[Numpy-discussion] Funny business with 'is' operator?
James Bergstra
bergstrj at iro.umontreal.ca
Fri Sep 6 12:48:55 EDT 2013
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.harris at gmail.com
> wrote:
>
>
>
> On Fri, Sep 6, 2013 at 10:19 AM, James Bergstra <bergstrj at 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 at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
--
http://www-etud.iro.umontreal.ca/~bergstrj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130906/c961d166/attachment.html>
More information about the NumPy-Discussion
mailing list