On 9/27/07, Bill Page <[EMAIL PROTECTED]> wrote: > There is another very relevant thread started by Robert Bradshaw on > this list concerning the safety of in-place modifications: > > http://groups.google.com/group/sage-devel/browse_thread/thread/806cd958eb28ac3b/46655d7572d11ee6?#46655d7572d11ee6 > > http://www.sagemath.org:9002/sage_trac/ticket/624
It's worth mentioning that extensions that provide low-level views of memory, even if they are fully refcounted, break the assumptions about the refcount being a safe way of detecting how many accesses to the current object exist. Here's a simple example illustrating the point: >>> import numpy as N >>> import sys >>> a = N.arange(10) >>> sys.getrefcount(a) 2 >>> b = a[::2] >>> sys.getrefcount(a) 3 >>> c = b[::2] >>> sys.getrefcount(a) 3 >>> c[:] = 999 >>> a array([999, 1, 2, 3, 999, 5, 6, 7, 999, 9]) >>> The last line modified a, even though the creation of the 'c' view over a's memory area did NOT increment a's refcount (since it did it via b, hence only b's refcount went up). This example is a bit contrived, but I just want to illustrate that extensions such as numpy (which is the basis of much of the numerical python code in existence) can make refcount-based arguments tricky. Cheers, f --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---