On Sep 27, 2007, at 7:36 AM, Fernando Perez wrote:

> 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.

You have a good point, though fortunately we're looking for refcounts  
so low that (essentially) nothing else can be holding onto it but the  
current stack frame. If b is pointing to a, it doesn't matter how  
many other things are (directly or indirectly). If nothing is  
pointing to it directly, it's difficult (but not impossible) for  
things to safely point to it indirectly. Also, we would only play  
this trick with SAGE elements, which we have more control over.

Also, in this case, since things are referenced, if one changes so  
should the other. I gave this a lot of though, but I hope others will  
too since I can't be sure I didn't miss something.

- Robert



--~--~---------~--~----~------------~-------~--~----~
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/
-~----------~----~----~----~------~----~------~--~---

Reply via email to