I'm stumped. I can't figure out how to extract from e.g.

view = A[:, 3]

that the view starts at element 3 of A. I was planning to make a
may_share_memory implementation based on the idea of swapping in a buffer
of 0s, and using the shapes, strides, itemsize etc. to increment just the
parts of the 0s buffer touched by the two ndarrays. If there  are any 2s in
the incremented buffer, it's because the two views overlapped. It's not the
best algorithm for comparing tiny views of huge arrays, I was wondering if
in my case it would have been quicker than the built-in method (I don't
know how it works). I actually have another data structure around to pull
out that shape and stride info, but it's a shame to use it, because then I
can't use the algorithm to compare ndarrays in general (or at least ones
that have been created by typical construction methods and slicing).


On Fri, Sep 6, 2013 at 12:48 PM, James Bergstra
<bergs...@iro.umontreal.ca>wrote:

> Thanks for the tips! FWIW my guess is that since '.data' is dynamically
> generated property rather than an attribute, it is being freed and
> re-allocated in the loop, and once for each of my id() expressions.
>
>
> On Fri, Sep 6, 2013 at 12:32 PM, Charles R Harris <
> charlesr.har...@gmail.com> wrote:
>
>>
>>
>>
>> On Fri, Sep 6, 2013 at 10:19 AM, James Bergstra <
>> bergs...@iro.umontreal.ca> wrote:
>>
>>> Hi, could someone help me understand why this assertion fails?
>>>
>>> def test_is(self):
>>>     a = np.empty(1)
>>>     b = np.empty(1)
>>>     if a.data is not b.data:
>>>         assert id(a.data) != id(b.data) # <-- fail
>>>
>>> I'm trying to write an alternate may_share_memory function.
>>>
>>>
>> id seems not as advertised:
>>
>> In [22]: for i in range(10): print id(a.data)
>> 66094640
>> 66095792
>> 66095792
>> 66095792
>> 66095792
>> 66095792
>> 66094640
>> 66094640
>> 66094640
>> 66094640
>>
>> Not sure why.
>>
>> Chuck
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>
>
> --
> http://www-etud.iro.umontreal.ca/~bergstrj
>



-- 
http://www-etud.iro.umontreal.ca/~bergstrj
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to