Re: [Numpy-discussion] documentation suggestion

2009-04-13 Thread Pauli Virtanen
Sun, 12 Apr 2009 17:32:31 -0400, Neal Becker wrote:
[clip]
 Done, but can someone check that what I wrote is accurate?  I wrote that
 changes to the ndarray will change the underlying buffer object.  But,
 the buffer protocol allows for read-only buffers.  Not sure what ndarray
 would do if you tried to write in that case.

For read-only buffers, the new array will not be writeable:

 x=abcde
 z=np.ndarray((5,), buffer=x, dtype='1S')
 z[0] = 'x'
Traceback (most recent call last):
  File stdin, line 1, in module
RuntimeError: array is not writeable

However, you can override this, and misusing it potentially leads to 
nasty things:

 x=abcde
 y=abcde
 z=np.ndarray((5,), buffer=x, dtype='1S')
 z.flags.writeable = True
 z[0] = 'x'
 x
'xbcde'
 y
'xbcde'
 hash(x)
-1332677140
 hash(abcde)
-1332677140

Hashing breaks, and the assumed immutability of strings causes nonlocal 
effects!

***

However, for some reason, I don't see your contribution in the change 
list:

http://docs.scipy.org/numpy/changes/

Can you check if the change you made went through? What page did you edit?

-- 
Pauli Virtanen

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] documentation suggestion

2009-04-12 Thread Neal Becker
Stéfan van der Walt wrote:

 Hi Neal
 
 2009/4/11 Neal Becker ndbeck...@gmail.com:
 I found this misleading.  It isn't just used to _fill_ the array - it is
 the
 
 Please create an account on docs.scipy.org, then I'll give you
 priviledges to edit documentation.
 
 Thanks!
 Stéfan

Done, but can someone check that what I wrote is accurate?  I wrote that 
changes to the ndarray will change the underlying buffer object.  But, the 
buffer protocol allows for read-only buffers.  Not sure what ndarray would 
do if you tried to write in that case.


___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] documentation suggestion

2009-04-11 Thread Neal Becker
numpy.ndarray says:

buffer : object exposing buffer interface, optional
Used to fill the array with data.

I found this misleading.  It isn't just used to _fill_ the array - it is the 
actual storage for the array.  If set to an object exporting the buffer 
interface, any updates to the ndarray will change the value of this object.

As an example:

from numpy import *
import eos

import mmap
import os
fd = os.open ('test.dat', os.O_RDWR|os.O_CREAT)
size = 128
os.ftruncate (fd, size)
m = mmap.mmap (fd, size, prot=mmap.PROT_READ|mmap.PROT_WRITE, 
flags=mmap.MAP_SHARED)

u = ndarray (shape=(size,), dtype=uint8, buffer=m)
u[:] = 24

mmap exports buffer interface (Also not mentioned in the documentation for 
mmap!).  Updating the value of u (last line above) will change the file on 
disk.


___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] documentation suggestion

2009-04-11 Thread Stéfan van der Walt
Hi Neal

2009/4/11 Neal Becker ndbeck...@gmail.com:
 I found this misleading.  It isn't just used to _fill_ the array - it is the

Please create an account on docs.scipy.org, then I'll give you
priviledges to edit documentation.

Thanks!
Stéfan
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion