Re: How to copy data from a C array to a numpy array efficiently?

79 views
Skip to first unread message

Bradley Froehle

unread,
Oct 7, 2012, 2:03:18 PM10/7/12
to cython...@googlegroups.com
Can you not just pass in your realData array to CDFlib, to avoid the copy in the first place?  Something like:

cimport numpy as np
import numpy as np

        cdef np.ndarray realData = np.zeros(np_shape, dtype='d')
        status = CDFlib(
                       SELECT_, zVAR_RECCOUNT_, numRecs,
                       NULL_)
        status = CDFlib(
                       GET_, zVAR_HYPERDATA_, <double*> realData.data,
                       NULL_)



Chris Barker

unread,
Oct 8, 2012, 3:08:01 PM10/8/12
to cython...@googlegroups.com


        status = CDFlib(
                       GET_, zVAR_HYPERDATA_, <double*> realData.data,
                       NULL_)

For the record, using .data may or may not be supported in future numpy releases. 

You can use realData[0] instead. And it saves you a typecast.

Also, if your lib does not support passing in a pointer, you can use memcpy() similarly.

Chris.


Jianbao Tao

unread,
Oct 8, 2012, 3:31:40 PM10/8/12
to cython...@googlegroups.com
Roger that. Thanks, Chris.
Reply all
Reply to author
Forward
0 new messages