[Numpy-discussion] Getting data from NDarrays to Blitz++ and back again

Philip Sterne pjs67@cam.ac...
Tue Apr 6 04:23:17 CDT 2010

If anyone was interested I found that the easiest solution involved 
patching up the strides after calling PyArray_SimpleNewFromData().  I 
still haven't gotten any sort of memory interaction so any objects 
created by Blitz are deleted by Blitz, while Python objects are deleted 
by Python.  (Irrespective of any pointers held by the other side.)

I find for my purposes that this is sufficient since I just want to be 
able to peer into the workings of a c++ program.


Philip Sterne wrote:
> Hi all,
> I hope this is the correct place to post my question.  I'd like python 
> to interface with c++ code that makes heavy use of Blitz++ arrays. After 
> a day's hacking I appear to have a simple working solution which I am 
> attaching.  (It uses Boost.Python and CMake.)
> However I believe this solution won't work if the blitz array is not 
> laid out contiguously in memory.  I also haven't really thought about 
> reference counting issues (although the example seems to work).  I 
> imagine that those sorts of issues will lead me to call the more 
> complicated:
> PyArray_New(...)
> or:
> PyArray_NewFromDescr(...)
> instead of the PyArray_SimpleNewFromData(...) that I currently use. 
> However I couldn't figure out some of the extra arguments from the API 
> documentation.
> Can someone point out all the things that will break when this code 
> actually gets used in the real world (and maybe even how to avoid them)?
> Thanks for your time!
>     -Philip.
> ------------------------------------------------------------------------
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simple.cpp
Type: text/x-c++src
Size: 1894 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100406/ea226c67/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simpletest.py
Type: text/x-python
Size: 160 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100406/ea226c67/attachment.py 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CMakeLists.txt
Url: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100406/ea226c67/attachment.txt 

More information about the NumPy-Discussion mailing list