<div dir="ltr">On Fri, Sep 6, 2013 at 9:19 AM, James Bergstra <span dir="ltr"><<a href="mailto:bergstrj@iro.umontreal.ca" target="_blank">bergstrj@iro.umontreal.ca</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>def test_is(self):<br>
</div>
<div>    a = np.empty(1)</div><div>    b = np.empty(1)</div><div>    if a.data is not b.data:</div>

<div>        assert id(a.data) != id(b.data) # <-- fail</div><div><br></div></div></div></blockquote><div><br></div><div style>I'm not familiar with the internals, but:</div><div style><br></div><div style><div>In [27]: a = np.empty(1)</div>

<div><br></div><div>In [28]: a.data</div><div>Out[28]: <read-write buffer for 0x122df30, size 8, offset 0 at 0x3501860></div><div><br></div><div style>so .data is a buffer object, wrapped around a particular pointer.</div>

<div><br></div><div>In [29]: id(a.data)</div><div>Out[29]: 55581376</div><div><br></div><div>In [30]: id(a.data)</div><div>Out[30]: 55581728</div><div><br></div><div style>but it looks like the buffer object itself is created on the fly -- so you are getting a different pyton object, even though it wraps the same data pointer. So you need to compare the value of the pointer compared, not the identity of the buffer object.</div>

<div style><br></div><div style>Not sure how to get that value though, other that parsing __repr__</div><div style><br></div><div style><div><div>In [44]: a.data.__repr__().split()[-1][:-1]</div><div>Out[44]: '0x3512100'</div>

</div><div><br></div><div style>ugly hack -- there must be a better way!</div><div style><br></div><div style>But:</div><div style><br></div><div style><div>In [38]: a = np.zeros((100,))</div><div><br></div><div>In [39]: b = a[50:]</div>

<div><br></div><div>In [40]: a.data</div><div>Out[40]: <read-write buffer for 0x1443990, size 800, offset 0 at 0x3501da0></div><div><br></div><div>In [41]: b.data</div><div>Out[41]: <read-write buffer for 0x1617130, size 400, offset 0 at 0x3501c20></div>

<div><br></div><div style>a and b share memory, but don't have the same data pointer as b's is offset.</div><div style><br></div><div style>HTH,</div><div style>   -Chris</div><div style><br></div><div style><br>
</div>
<div style><br></div><div style><br></div></div></div><div style><br></div><div style><br></div></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div dir="ltr"><div dir="ltr"><div></div><div>I'm trying to write an alternate may_share_memory function.</div><div><br></div><div>Thanks,</div><div> - James</div></div><br></div>

<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>

Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a>
</div></div>