Re: [Numpy-discussion] numpy array sharing between processes? (and ctypes)

2007-05-15 Thread Albert Strasheim
Agreed.

Could someone with wiki admin access please delete the Ctypes page and 
rename type Ctypes2 page to Ctypes? As far as I know, Ctypes2 is really 
what you want to look at (at least it was, last time I worked on it).

Thanks.

Cheers,

Albert

On Mon, 14 May 2007, Stefan van der Walt wrote:

 On Mon, May 14, 2007 at 11:44:11AM -0700, Ray S wrote:
  While investigating ctypes and numpy for sharing, I saw that the 
  example on
  http://www.scipy.org/Cookbook/Ctypes#head-7def99d882618b52956c6334e08e085e297cb0c6
  does not quite work. However, with numpy.version.version=='1.0b1', 
  ActivePython 2.4.3 Build 12:
 
 That page should probably be replaced by
 
 http://www.scipy.org/Cookbook/Ctypes2
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy array sharing between processes? (and ctypes)

2007-05-14 Thread Ray S
While investigating ctypes and numpy for sharing, I saw that the 
example on
http://www.scipy.org/Cookbook/Ctypes#head-7def99d882618b52956c6334e08e085e297cb0c6
does not quite work. However, with numpy.version.version=='1.0b1', 
ActivePython 2.4.3 Build 12:


import numpy as N
from ctypes import *
x = N.zeros((3, 3), dtype=N.float64)
xdataptr = N.intp(x.__array_interface__['data'])[0]
y = (c_double * x.size).from_address(xdataptr)
y[0] = 123.
y[4] = 456.
y[8] = 789
print N.diag(x)

Works for me...

I can then do:
  import  numpy.core.multiarray as MA
  xBuf = MA.getbuffer(x)
  z = MA.frombuffer(xBuf).reshape((3,3))
  z
array([[ 123.,0.,0.],
[   0.,  456.,0.],
[   0.,0.,  789.]])
  z[0,1] = 99
  z
array([[ 123.,   99.,0.],
[   0.,  456.,0.],
[   0.,0.,  789.]])
  x
array([[ 123.,   99.,0.],
[   0.,  456.,0.],
[   0.,0.,  789.]])
  y[1]
99.0

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


Re: [Numpy-discussion] numpy array sharing between processes? (and ctypes)

2007-05-14 Thread Travis Oliphant
Ray S wrote:
 print N.diag(x)

 Works for me...

 I can then do:
   import  numpy.core.multiarray as MA
   xBuf = MA.getbuffer(x)
   z = MA.frombuffer(xBuf).reshape((3,3))
   

I see this kind of importing used more often than it should be. 

It is dangerous to import directly from numpy.core and numpy.lib and 
even more dangerous to import directly from files in those 
sub-packages.  The organization of the files may change suddenly in the 
future.  The only guarantee is that the numpy name-space will not change 
suddenly.

These namespaces are all incorporated in numpy. 

Thus,

numpy.getbuffer
numpy.frombuffer

are the recommended ways to use this functionality.

-Travis

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


Re: [Numpy-discussion] numpy array sharing between processes? (and ctypes)

2007-05-14 Thread Stefan van der Walt
On Mon, May 14, 2007 at 11:44:11AM -0700, Ray S wrote:
 While investigating ctypes and numpy for sharing, I saw that the 
 example on
 http://www.scipy.org/Cookbook/Ctypes#head-7def99d882618b52956c6334e08e085e297cb0c6
 does not quite work. However, with numpy.version.version=='1.0b1', 
 ActivePython 2.4.3 Build 12:

That page should probably be replaced by

http://www.scipy.org/Cookbook/Ctypes2

Cheers
Stéfan
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion