Re: [Numpy-discussion] Funny business with 'is' operator?

2013-09-09 Thread Robert Kern
On Fri, Sep 6, 2013 at 6:50 PM, James Bergstra bergs...@iro.umontreal.ca wrote: Thanks, this is exactly what I was looking for. I'll look into what this Diophantine equation is. Let's say we have two arrays with shape tuples `shape0` and `shape1`, stride tuples `stride0` and `stride1` and

Re: [Numpy-discussion] Funny business with 'is' operator?:

2013-09-06 Thread Nathaniel Smith
The .data attribute is generated on the fly when accessed. So it returns an anonymous temporary that's deallocated as soon as it's no longer needed. a.data is b.data needs both objects, so both get allocated and then compared. In the second one though, each object gets allocated one at a time and

Re: [Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread Chris Barker - NOAA Federal
On Fri, Sep 6, 2013 at 9:19 AM, James Bergstra bergs...@iro.umontreal.cawrote: 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 not familiar with the internals, but: In [27]: a = np.empty(1) In

Re: [Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread Charles R Harris
On Fri, Sep 6, 2013 at 10:19 AM, James Bergstra bergs...@iro.umontreal.cawrote: 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

Re: [Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread Robert Kern
On Fri, Sep 6, 2013 at 5:58 PM, James Bergstra bergs...@iro.umontreal.ca wrote: 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

Re: [Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread James Bergstra
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:

[Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread James Bergstra
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. Thanks, - James

Re: [Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread James Bergstra
Thanks, this is exactly what I was looking for. I'll look into what this Diophantine equation is. Also, relatedly, a few months ago Julian Taylor at least wrote what was there in C, which made it faster, if not better. - James On Fri, Sep 6, 2013 at 1:27 PM, Robert Kern robert.k...@gmail.com

Re: [Numpy-discussion] Funny business with 'is' operator?

2013-09-06 Thread James Bergstra
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