[C++-sig] Trouble converting data from numpy.array to c++
Hi, I've got this problem I cannot solve. I've a c++ application from which I create an array sending to python this string: anArray = numpy.array((1, 2, 3)) After extracting the symbol "anArray" from the directory in a boost::python::object, I'm trying to extract the values in C++: int val = bp::extract(anArray[0]); It doesn't work and raise the error: "TypeError: No registered converter was able to produce a C++ rvalue of type int from this Python object of type numpy.int32" What is going on ? I'm using python 2.6, last version of Numpy 1.4.1 with boost 1.38 on Linux. Looking on the list, it seems that someone had this very problem but he didn't get any answer. http://article.gmane.org/gmane.comp.python.c++/11279/match=typeerror+no+registered+converter+able+produce+c%2b%2b+rvalue+type+int+python+object+numpy+int32 Hopefully I'll have more chance ! Any idea greatly appreciated, Jean-Charles ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Trouble converting data from numpy.array to c++
Hi Jean-Charles, AFAIK there are no standard converters for the numpy scalar types to C++ types. In pyrap it is solved by having explicit converters for numpy scalar types to C++ types (see pyrap.googlecode.com). Cheers, Ger >>> QUILLET Jean-Charles 05/11/10 11:38 AM >>> Hi, I've got this problem I cannot solve. I've a c++ applicationfrom which I create an array sending to python this string: anArray = numpy.array((1, 2, 3)) After extracting the symbol "anArray" from thedirectory in a boost::python::object, I'm trying to extract the values in C++: int val = bp::extract(anArray[0]); It doesn't work and raise the error: "TypeError: No registered converter was able toproduce a C++ rvalue of type int from this Python object of type numpy.int32" What is going on ? I'm using python 2.6, last version ofNumpy 1.4.1 with boost 1.38 on Linux. Looking on the list, it seems thatsomeone had this very problem but he didn't get any answer. http://article.gmane.org/gmane.comp.python.c++/11279/match=typeerror+no+registered+converter+able+produce+c%2b%2b+rvalue+type+int+python+object+numpy+int32 Hopefully I'll have more chance ! Any idea greatly appreciated, Jean-Charles ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Trouble converting data from numpy.array to c++
Thanks Ger, I'll check out this, it seems very interesting. But I'm confused because what I'm describing is working without any problem on windows using Visual Studio 2005 python 2.5 and boost 1.34 But for some reason I cant use these versions on Linux because of an incompatibility between Qt and Python 25 http://bugs.python.org/issue1086854 This is library hell ! Despite this, I'll check out the converters, but it seems a bit overkill for me. Whould you know an easy way to retrieve my values from the array ? Thanks in advance, Jean-Charles De : Ger van Diepen [mailto:die...@astron.nl] Envoyé : mardi 11 mai 2010 12:25 À : QUILLET Jean-Charles; cplusplus-sig@python.org Objet : [Spam Probable] Re: [C++-sig] Trouble converting data from numpy.array to c++ Hi Jean-Charles, AFAIK there are no standard converters for the numpy scalar types to C++ types. In pyrap it is solved by having explicit converters for numpy scalar types to C++ types (see pyrap.googlecode.com). Cheers, Ger >>> QUILLET Jean-Charles 05/11/10 11:38 AM >>> Hi, I've got this problem I cannot solve. I've a c++ application from which I create an array sending to python this string: anArray = numpy.array((1, 2, 3)) After extracting the symbol "anArray" from the directory in a boost::python::object, I'm trying to extract the values in C++: int val = bp::extract(anArray[0]); It doesn't work and raise the error: "TypeError: No registered converter was able to produce a C++ rvalue of type int from this Python object of type numpy.int32" What is going on ? I'm using python 2.6, last version of Numpy 1.4.1 with boost 1.38 on Linux. Looking on the list, it seems that someone had this very problem but he didn't get any answer. http://article.gmane.org/gmane.comp.python.c++/11279/match=typeerror+no+registered+converter+able+produce+c%2b%2b+rvalue+type+int+python+object+numpy+int32 Hopefully I'll have more chance ! Any idea greatly appreciated, Jean-Charles ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Trouble converting data from numpy.array to c++
Hi Jean-Charles, On Tue, 11 May 2010 11:32:08 +0200, QUILLET Jean-Charles wrote: > I've got this problem I cannot solve. I've a c++ application from which I > create an array sending to python this string: > > anArray = numpy.array((1, 2, 3)) > > After extracting the symbol "anArray" from the directory in a > boost::python::object, I'm trying to extract the values in C++: > > int val = bp::extract(anArray[0]); > > It doesn't work and raise the error: This is probably not what you wanted to hear, but my PyUblas package solves your problem. :) http://mathema.tician.de/software/pyublas HTH, Andreas ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] When not to use static boost python library
Hi, I am new to boost python. I have some experience making python extension using pure C. Now I have a question: when should I not use static boost python library? I tried to search the archive a bit. But haven't found a good answer. I read the boost python library documentation, where the section 6.2 mentioned when should should static binary. But I still not very clear about it. The lines in the documentation is: ''' It might be appropriate to use the static Boost.Python library in any of the following cases: * You are extending python and the types exposed in your dynamically-loaded extension module don't need to be used by any other Boost.Python extension modules, and you don't care if the core library code is duplicated among them. * You are embedding python in your application and either: * You are targeting a Unix variant OS other than MacOS or AIX, where the dynamically-loaded extension modules can “see” the Boost.Python library symbols that are part of the executable. * Or, you have statically linked some Boost.Python extension modules into your application and you don't care if any dynamically-loaded Boost.Python extension modules are able to use the types exposed by your statically-linked extension modules (and vice-versa). ''' First of all, I am not embedding python interpreter in my app. I want to write an extention that can by loaded dynamicaly. So I fall into the first case, and I don't care my core library code is duplicated (i think here it means the boost python code is duplicated). But I do care the types and functions in my produced extension can be used. I have built my extension using static boost python lib and test it by writing some python code access the typs and functions exposed. It all works fine. So I guess what the problem is should be that: another python extension, written in boost python, cannot access the types and functions exposed in my current extension. I am not clear why is it so, becaused it is exposed to the python interpreter already. If there are two python extensions, both written in pure C, can't they access each other's type and functions? Thanks in advance for any help. Kun ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig