embedded PyArray_FromDimsAndData Segmentation Fault 

embedded PyArray_FromDimsAndData Segmentation Fault
Re: embedded PyArray_FromDimsAndData Segmentation Fault
Re: embedded PyArray_FromDimsAndData Segmentation Fault
Re: embedded PyArray_FromDimsAndDataSegment

>I didn't know a person could write a standalone program using NumPy
>this way (can you?) Well, this is possible when you embed python and use the "simple" objects such as ints, strings, .... Why should it be impossible to do it for numpy then? My plan is to send multidimensional arrays from C to python and to apply some python specific functions to them. _______________________________________________ Numpydiscussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpydiscussion winmail.dat (3K) Download Attachment 
On Wed, May 14, 2008 at 6:40 PM, Thomas Hrabe <[hidden email]> wrote:
>>I didn't know a person could write a standalone program using NumPy >>this way (can you?) > > Well, this is possible when you embed python and use the "simple" objects such as ints, strings, .... > Why should it be impossible to do it for numpy then? numpy exposes its API as a pointer to an array which contains function pointers. import_array() imports the extension module, accesses the PyCObject that contains this pointer, and sets a global pointer appropriately. There are #defines macros to emulate the functions by dereferencing the appropriate element of the array and calling it with the given macro arguments. The reason you get the error about returning nothing when the return type of main() is declared int is because this macro is only intended to work inside of an initmodule() function of an extension module, whose return type is void. import_array() includes error handling logic and will return if there is an error. You get the segfault without import_array() because all of the functions you try to call are trying to dereference an array which has not been initialized. > My plan is to send multidimensional arrays from C to python and to apply some python specific functions to them. Well, first you need to call Py_Initialize() to start the VM. Otherwise, you can't import numpy to begin with. I guess you could write a "void load_numpy(void)" function which just exists to call import_array(). Just be sure to check the exception state appropriately after it returns. But for the most part, it's much better to drive your C code using Python than the other around.  Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth."  Umberto Eco _______________________________________________ Numpydiscussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpydiscussion 
>But for the most part, it's much better to drive your C code using >Python than the other around. True, the other way arround works fine. Will investigate further tomorrow, because its a must have feature... Thanks _______________________________________________ Numpydiscussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpydiscussion winmail.dat (3K) Download Attachment 
In reply to this post by Robert Kern2
After all, I figured how to create an numpy in C with the help below. _______________________________________________ Numpydiscussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpydiscussion 
On Tue, May 20, 2008 at 2:01 PM, Thomas Hrabe <[hidden email]> wrote:
> After all, I figured how to create an numpy in C with the help below. > > If called in C, import_array() but actually _import_array() successfully > creates all the instances needed for the array. > However, once I call this function from another environment such as Matlab, > PyObject *numpy = PyImport_ImportModule("numpy.core.multiarray"); > in __import_array() returns NULL, because numpy.core.multiarray is not > found? Something like that. Call PyErr_Print() do display the full traceback so you can find out what the actual problem is. > Do you think it might depend on the path settings? You've called Py_Initialize() before you do anything else with Py* functions, right?  Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth."  Umberto Eco _______________________________________________ Numpydiscussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpydiscussion 
Thats what PyErr_Print() prints.
Python is initialised, for sure Traceback (most recent call last): File "/usr/global/python32/lib/python2.4/sitepackages/numpy/__init__.py", lin e 34, in ? import testing File "/usr/global/python32/lib/python2.4/sitepackages/numpy/testing/__init__. py", line 3, in ? from numpytest import * File "/usr/global/python32/lib/python2.4/sitepackages/numpy/testing/numpytest .py", line 8, in ? import unittest File "/usr/global/python32/lib/python2.4/unittest.py", line 51, in ? import time ImportError: /usr/global/python32/lib/python2.4/libdynload/time.so: undefined s ymbol: PyExc_IOErro why does it work in C and not in C started within Matlab? Original Message From: [hidden email] on behalf of Robert Kern Sent: Tue 5/20/2008 12:23 PM To: Discussion of Numerical Python Subject: Re: [Numpydiscussion] embeddedPyArray_FromDimsAndDataSegmentationFault On Tue, May 20, 2008 at 2:01 PM, Thomas Hrabe <[hidden email]> wrote: > After all, I figured how to create an numpy in C with the help below. > > If called in C, import_array() but actually _import_array() successfully > creates all the instances needed for the array. > However, once I call this function from another environment such as Matlab, > PyObject *numpy = PyImport_ImportModule("numpy.core.multiarray"); > in __import_array() returns NULL, because numpy.core.multiarray is not > found? Something like that. Call PyErr_Print() do display the full traceback so you can find out what the actual problem is. > Do you think it might depend on the path settings? You've called Py_Initialize() before you do anything else with Py* functions, right?  Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth."  Umberto Eco _______________________________________________ Numpydiscussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpydiscussion _______________________________________________ Numpydiscussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpydiscussion winmail.dat (5K) Download Attachment 
On Tue, May 20, 2008 at 3:36 PM, Thomas Hrabe <[hidden email]> wrote:
> Thats what PyErr_Print() prints. > Python is initialised, for sure > > Traceback (most recent call last): > File "/usr/global/python32/lib/python2.4/sitepackages/numpy/__init__.py", lin > e 34, in ? > import testing > File "/usr/global/python32/lib/python2.4/sitepackages/numpy/testing/__init__. > py", line 3, in ? > from numpytest import * > File "/usr/global/python32/lib/python2.4/sitepackages/numpy/testing/numpytest > .py", line 8, in ? > import unittest > File "/usr/global/python32/lib/python2.4/unittest.py", line 51, in ? > import time > ImportError: /usr/global/python32/lib/python2.4/libdynload/time.so: undefined s > ymbol: PyExc_IOErro > > why does it work in C and not in C started within Matlab? It depends on how you linked everything. Presumably, you linked in libpython24 for the program but not the MEX.  Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth."  Umberto Eco _______________________________________________ Numpydiscussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpydiscussion 
In reply to this post by Thomas Hrabe2
ti, 20080520 kello 13:36 0700, Thomas Hrabe kirjoitti:
> Thats what PyErr_Print() prints. > Python is initialised, for sure > > Traceback (most recent call last): > File "/usr/global/python32/lib/python2.4/sitepackages/numpy/__init__.py", lin > e 34, in ? > import testing > File "/usr/global/python32/lib/python2.4/sitepackages/numpy/testing/__init__. > py", line 3, in ? > from numpytest import * > File "/usr/global/python32/lib/python2.4/sitepackages/numpy/testing/numpytest > py", line 8, in ? > import unittest > File "/usr/global/python32/lib/python2.4/unittest.py", line 51, in ? > import time > ImportError: /usr/global/python32/lib/python2.4/libdynload/time.so: undefined s > ymbol: PyExc_IOErro > > why does it work in C and not in C started within Matlab? It's probably that it has something to do with the way Matlab loads its extension libraries: http://www.iki.fi/pav/software/pythoncall/index.html#compilationimportant  Pauli Virtanen _______________________________________________ Numpydiscussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpydiscussion 
Hi Pauli _______________________________________________ Numpydiscussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpydiscussion 
Free forum by Nabble  Edit this page 