[SciPy-user] array resize() method error in scipy_core

Travis Oliphant oliphant.travis at ieee.org
Fri Dec 9 23:41:42 CST 2005


Chris Fonnesbeck wrote:

>On 12/10/05, Travis Oliphant <oliphant.travis at ieee.org> wrote:
>  
>
>>The resize function is very conservative about letting you resize the
>>memory of an array in-place because of the possibility of sharing the
>>data through the buffer interface.  If you resized the memory while
>>another object was holding the memory you could easily get a segfault
>>later.
>>
>>Unfortunately, there is no way to tell whether another object is
>>referencing the memory of the array except through the reference count
>>(which also increases on simple name binding, too.)
>>
>>So, perhaps while profiling an additional reference is being held to the
>>objects and therefore, the resize function won't let you resize the
>>memory.   I'm not sure how to be more generous about when resizing is
>>possible.
>>
>>    
>>
>
>Hi Travis,
>
>I assume you mean the resize *method*, right? Should I go back to
>using the function (i.e. resize(my_array) 
>
Yes the resize() works for anything (it also fills differently --- the 
.resize method
doesn't fill the new memory at all, the resize function fills the old 
way of copying
old data repeatedly.

.resize() is faster, but it does have that no-other references restriction
(perhaps you could use one while profiling and another in production...)



-Travis





More information about the SciPy-user mailing list