[Numpy-discussion] Wrapping C array
Carlos Pita
carlosjosepita at yahoo.com.ar
Wed May 18 09:14:10 EDT 2005
The documentation for PyArray_FromDimsAndData
that I quoted in my previous post seems to suggest
that a copy is done. But browsing the web
numarray cvs I find out that its implementation
first creates a PyBuffer from the passed data:
buf = PyBuffer_FromReadWriteMemory(data, nelements * descr->elsize);
a = NA_NewAllFromBuffer( nd, dimensions, descr->type_num, buf,
0, descr->elsize, NA_ByteOrder(), 1, 1);
Then, from the NA_NewAllFromBuffer doc (in numarray
manual):
It is possible to create a Python buffer object from
an array of C data and then construct a numarray using
this function which refers to the C data without
making a copy.
So you both are right. I guess creating a
PyBuffer as above and then calling
NA_NewAllFromBuffer is the best way
to do what I was asking for in numarray
(that is, without recurring to the
numeric simulation API).
Am I right?
Regards,
Carlos
> On Wed, 2005-05-18 at 04:01, Alexandre wrote:
> > On Tue, May 17, 2005 at 09:36:22PM -0300, Carlos Pita wrote:
> > > Hi!
> > > I need to wrap a pre-existent C array into
> > > a numarray. It shouldn't be a copy of the
> > > original array because this is an audio buffer
> > > with a fixed address and also input/output
> > > copying from/to the buffer would be overkilling,
> > > so the numarray *must* be lightly wrapping the
> > > buffer and not a memcpy of it. But NA_NewArray
> > > duplicates the passed buffer so I'm not sure
> > > how to achieve the goal stated above or if
> > > it's possible at all.
> > > Can you help me?
> >
> > I'm not sure for Numarray, but for Numeric, you can use
> > PyArray_FromDimsAndData(). There should be a similar function in
> > numarray.
>
> That function does indeed exist for Numeric and has non-copying
> semantics.
>
> Regards,
> Todd
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by Oracle Space Sweepstakes
> Want to be the first software developer in space?
> Enter now for the Oracle Space Sweepstakes!
> http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list