Re: [C++-sig] Accessing 2D array from python in C++

2012-08-22 Thread alfa
Hi John,

Thanks a lot for your implementation. In multi_array_to_numpy.h,  can you give 
more hints on which method/function that I can possibly use if I can include it 
in my implementation as a header file. 

Thanks in advance.





 From: John Reid 
To: cplusplus-sig@python.org 
Sent: Thursday, August 16, 2012 5:02 PM
Subject: Re: [C++-sig] Accessing 2D array from python in C++
 
If you don't mind digging around in my code, you could download the
source code for the STEME python package from pypi and look in the
c++/myrrh directory. There is code to access multi_arrays from python in
there.

http://pypi.python.org/pypi/STEME/

In particular the file
c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the
implementation.

HTH,
John.



On 16/08/12 09:29, alfa wrote:
> Hi,
> 
> Could you give more hints on this or any code snippet that I can
> implement this. I'm a bit naive in applying this. Please consider my 2D
> array of Vp_cpp(Vp equivalent in Python) is as below:
> 
>     typedef boost::multi_array array_type;
>     typedef array_type::index index;
>     array_type Vp_cpp(boost::extents[X_cpp][X_cpp]);
> 
> 
> I'm still puzzled how to "manually wrap the features" in the last "..." in:
>     boost::python::class_< boost::multi_array<...> >(...)
> 
> Thanks in advance.
> 
> 
> *From:* Jim Bosch 
> *To:* alfa 
> *Cc:* Development of Python/C++ integration 
> *Sent:* Wednesday, August 15, 2012 5:34 PM
> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
> 
> On Aug 15, 2012 1:57 AM, "alfa"  > wrote:
>>
>> I apologize for double posting this because it was spammed before.
>>
>> Hi Jim,
>>
>> Do you mean, "you could wrap multi_array itself using class_", I
> should do as below:
>>
>> boost::python::class_ >
>>("PyVec").def(boost::python::vector_indexing_suite
>> >());
>>
> No, I don't think that will work; I meant something like this:
> boost::python::class_< boost::multi_array<...> >(...)
>     ...;
> Where the last "..." is where you have to manually wrap the features of
> multi_array you want to use.  I'm afraid there's nothing as easy as
> vector_indexing_suite.
> Jim
> 
> 
> 
> 
> ___
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> 

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Accessing 2D array from python in C++

2012-08-22 Thread John Reid
On 22/08/12 11:13, alfa wrote:
> Hi John,
> 
> Thanks a lot for your implementation. In multi_array_to_numpy.h,  can
> you give more hints on which method/function that I can possibly use if
> I can include it in my implementation as a header file.
> 
> Thanks in advance.
> 
src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp
implement a boost.python module that exposes the multi-array classes.
You have choose which data types you expose multiarrays for.

HTH,
John.


> 
> 
> *From:* John Reid 
> *To:* cplusplus-sig@python.org
> *Sent:* Thursday, August 16, 2012 5:02 PM
> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
> 
> If you don't mind digging around in my code, you could download the
> source code for the STEME python package from pypi and look in the
> c++/myrrh directory. There is code to access multi_arrays from python in
> there.
> 
> http://pypi.python.org/pypi/STEME/
> 
> In particular the file
> c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the
> implementation.
> 
> HTH,
> John.
> 
> 
> 
> On 16/08/12 09:29, alfa wrote:
>> Hi,
>>
>> Could you give more hints on this or any code snippet that I can
>> implement this. I'm a bit naive in applying this. Please consider my 2D
>> array of Vp_cpp(Vp equivalent in Python) is as below:
>>
>>typedef boost::multi_array array_type;
>>typedef array_type::index index;
>>array_type Vp_cpp(boost::extents[X_cpp][X_cpp]);
>>
>>
>> I'm still puzzled how to "manually wrap the features" in the last
> "..." in:
>>boost::python::class_< boost::multi_array<...> >(...)
>>
>> Thanks in advance.
>>
>> 
>> *From:* Jim Bosch mailto:tallji...@gmail.com>>
>> *To:* alfa mailto:alfarobi0...@yahoo.com>>
>> *Cc:* Development of Python/C++ integration  >
>> *Sent:* Wednesday, August 15, 2012 5:34 PM
>> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
>>
>> On Aug 15, 2012 1:57 AM, "alfa"  
>> >> wrote:
>>>
>>> I apologize for double posting this because it was spammed before.
>>>
>>> Hi Jim,
>>>
>>> Do you mean, "you could wrap multi_array itself using class_", I
>> should do as below:
>>>
>>> boost::python::class_ >
>>>("PyVec").def(boost::python::vector_indexing_suite
>>> >());
>>>
>> No, I don't think that will work; I meant something like this:
>> boost::python::class_< boost::multi_array<...> >(...)
>>...;
>> Where the last "..." is where you have to manually wrap the features of
>> multi_array you want to use.  I'm afraid there's nothing as easy as
>> vector_indexing_suite.
>> Jim
>>
>>
>>
>>
>> ___
>> Cplusplus-sig mailing list
>> Cplusplus-sig@python.org 
>> http://mail.python.org/mailman/listinfo/cplusplus-sig
>>
> 
> ___
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org 
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> 
> 
> 
> 
> ___
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> 

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Accessing 2D array from python in C++

2012-08-22 Thread alfa
Hi John,

I'm sorry, I'm a bit confused because previously you said that the relevant 
implementation resides in "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but 
now, you point to "src/python/man_module.cpp and 
src/python/multi_array_to_numpy.cpp". Hope you understand my problem of having 
2D array in python that needs to be exposed/converted to C++. It would be great 
If I know any method/function that I can invoke from any of your 
implementations.

Thanks in advance.





 From: John Reid 
To: cplusplus-sig@python.org 
Sent: Wednesday, August 22, 2012 12:28 PM
Subject: Re: [C++-sig] Accessing 2D array from python in C++
 
On 22/08/12 11:13, alfa wrote:
> Hi John,
> 
> Thanks a lot for your implementation. In multi_array_to_numpy.h,  can
> you give more hints on which method/function that I can possibly use if
> I can include it in my implementation as a header file.
> 
> Thanks in advance.
> 
src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp
implement a boost.python module that exposes the multi-array classes.
You have choose which data types you expose multiarrays for.

HTH,
John.


> 
> 
> *From:* John Reid 
> *To:* cplusplus-sig@python.org
> *Sent:* Thursday, August 16, 2012 5:02 PM
> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
> 
> If you don't mind digging around in my code, you could download the
> source code for the STEME python package from pypi and look in the
> c++/myrrh directory. There is code to access multi_arrays from python in
> there.
> 
> http://pypi.python.org/pypi/STEME/
> 
> In particular the file
> c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the
> implementation.
> 
> HTH,
> John.
> 
> 
> 
> On 16/08/12 09:29, alfa wrote:
>> Hi,
>>
>> Could you give more hints on this or any code snippet that I can
>> implement this. I'm a bit naive in applying this. Please consider my 2D
>> array of Vp_cpp(Vp equivalent in Python) is as below:
>>
>>    typedef boost::multi_array array_type;
>>    typedef array_type::index index;
>>    array_type Vp_cpp(boost::extents[X_cpp][X_cpp]);
>>
>>
>> I'm still puzzled how to "manually wrap the features" in the last
> "..." in:
>>    boost::python::class_< boost::multi_array<...> >(...)
>>
>> Thanks in advance.
>>
>> 
>> *From:* Jim Bosch mailto:tallji...@gmail.com>>
>> *To:* alfa mailto:alfarobi0...@yahoo.com>>
>> *Cc:* Development of Python/C++ integration  >
>> *Sent:* Wednesday, August 15, 2012 5:34 PM
>> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
>>
>> On Aug 15, 2012 1:57 AM, "alfa"  
>> >> wrote:
>>>
>>> I apologize for double posting this because it was spammed before.
>>>
>>> Hi Jim,
>>>
>>> Do you mean, "you could wrap multi_array itself using class_", I
>> should do as below:
>>>
>>> boost::python::class_ >
>>>("PyVec").def(boost::python::vector_indexing_suite
>>> >());
>>>
>> No, I don't think that will work; I meant something like this:
>> boost::python::class_< boost::multi_array<...> >(...)
>>    ...;
>> Where the last "..." is where you have to manually wrap the features of
>> multi_array you want to use.  I'm afraid there's nothing as easy as
>> vector_indexing_suite.
>> Jim
>>
>>
>>
>>
>> ___
>> Cplusplus-sig mailing list
>> Cplusplus-sig@python.org 
>> http://mail.python.org/mailman/listinfo/cplusplus-sig
>>
> 
> ___
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org 
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> 
> 
> 
> 
> ___
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> 

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Accessing 2D array from python in C++

2012-08-22 Thread John Reid


On 22/08/12 11:45, alfa wrote:
> Hi John,
> 
> I'm sorry, I'm a bit confused because previously you said that the
> relevant implementation resides in
> "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to
> "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp".
> Hope you understand my problem of having 2D array in python that needs
> to be exposed/converted to C++. It would be great If I know any
> method/function that I can invoke from any of your implementations.
> 
> Thanks in advance.

Hi Alfa,

You can look at all of the code I've mentioned to work out how it works.
If it does not make sense perhaps it might be worth working through the
boost.python tutorial to get up to speed on how boost.python works.

You can call the expose_converters< npy_double >() function to expose
multiarrays of doubles to python as numpy arrays.

Please ask if you have any specific questions.

Regards,
John.


> 
> 
> 
> *From:* John Reid 
> *To:* cplusplus-sig@python.org
> *Sent:* Wednesday, August 22, 2012 12:28 PM
> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
> 
> On 22/08/12 11:13, alfa wrote:
>> Hi John,
>>
>> Thanks a lot for your implementation. In multi_array_to_numpy.h,  can
>> you give more hints on which method/function that I can possibly use if
>> I can include it in my implementation as a header file.
>>
>> Thanks in advance.
>>
> src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp
> implement a boost.python module that exposes the multi-array classes.
> You have choose which data types you expose multiarrays for.
> 
> HTH,
> John.
> 
> 
>>
>> 
>> *From:* John Reid  >
>> *To:* cplusplus-sig@python.org 
>> *Sent:* Thursday, August 16, 2012 5:02 PM
>> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
>>
>> If you don't mind digging around in my code, you could download the
>> source code for the STEME python package from pypi and look in the
>> c++/myrrh directory. There is code to access multi_arrays from python in
>> there.
>>
>> http://pypi.python.org/pypi/STEME/
>>
>> In particular the file
>> c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the
>> implementation.
>>
>> HTH,
>> John.
>>
>>
>>
>> On 16/08/12 09:29, alfa wrote:
>>> Hi,
>>>
>>> Could you give more hints on this or any code snippet that I can
>>> implement this. I'm a bit naive in applying this. Please consider my 2D
>>> array of Vp_cpp(Vp equivalent in Python) is as below:
>>>
>>>typedef boost::multi_array array_type;
>>>typedef array_type::index index;
>>>array_type Vp_cpp(boost::extents[X_cpp][X_cpp]);
>>>
>>>
>>> I'm still puzzled how to "manually wrap the features" in the last
>> "..." in:
>>>boost::python::class_< boost::multi_array<...> >(...)
>>>
>>> Thanks in advance.
>>>
>>> 
>>> *From:* Jim Bosch mailto:tallji...@gmail.com>
> >>
>>> *To:* alfa mailto:alfarobi0...@yahoo.com>
> >>
>>> *Cc:* Development of Python/C++ integration  
>> >>
>>> *Sent:* Wednesday, August 15, 2012 5:34 PM
>>> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
>>>
>>> On Aug 15, 2012 1:57 AM, "alfa"  
>> >
>>> 
> >> should do as below:

 boost::python::class_ >
("PyVec").def(boost::python::vector_indexing_suite
 >());

>>> No, I don't think that will work; I meant something like this:
>>> boost::python::class_< boost::multi_array<...> >(...)
>>>...;
>>> Where the last "..." is where you have to manually wrap the features of
>>> multi_array you want to use.  I'm afraid there's nothing as easy as
>>> vector_indexing_suite.
>>> Jim
>>>
>>>
>>>
>>>
>>> ___
>>> Cplusplus-sig mailing list
>>> Cplusplus-sig@python.org 
> >
>>> http://mail.python.org/mailman/listinfo/cplusplus-sig
>>>
>>
>> ___
>> Cplusplus-sig mailing list
>> Cplusplus-sig@python.org 
> >
>>

Re: [C++-sig] Accessing 2D array from python in C++

2012-08-22 Thread John Reid


On 22/08/12 11:58, John Reid wrote:
> 
> 
> On 22/08/12 11:45, alfa wrote:
>> Hi John,
>>
>> I'm sorry, I'm a bit confused because previously you said that the
>> relevant implementation resides in
>> "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to
>> "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp".
>> Hope you understand my problem of having 2D array in python that needs
>> to be exposed/converted to C++. It would be great If I know any
>> method/function that I can invoke from any of your implementations.
>>
>> Thanks in advance.
> 
> Hi Alfa,
> 
> You can look at all of the code I've mentioned to work out how it works.
> If it does not make sense perhaps it might be worth working through the
> boost.python tutorial to get up to speed on how boost.python works.
> 
> You can call the expose_converters< npy_double >() function to expose
> multiarrays of doubles to python as numpy arrays.

Also look in python_test/test_man.py for code that tests the
implementation from the python side if it helps.

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Accessing 2D array from python in C++

2012-08-22 Thread alfa
Hi John,

""




 From: John Reid 
To: cplusplus-sig@python.org 
Sent: Wednesday, August 22, 2012 12:58 PM
Subject: Re: [C++-sig] Accessing 2D array from python in C++
 Hi John,

"You can call the expose_converters< npy_double >() function to expose
multiarrays of doubles to python as numpy arrays."

I'm afraid you understood that I have C++ array to be exposed as  numpy arrays 
in Python. My problem is actually the other way around, in which I have a 2D 
python array/matrix that I want to convert to/access in C++.

Thanks in advance.



On 22/08/12 11:45, alfa wrote:
> Hi John,
> 
> I'm sorry, I'm a bit confused because previously you said that the
> relevant implementation resides in
> "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to
> "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp".
> Hope you understand my problem of having 2D array in python that needs
> to be exposed/converted to C++. It would be great If I know any
> method/function that I can invoke from any of your implementations.
> 
> Thanks in advance.

Hi Alfa,

You can look at all of the code I've mentioned to work out how it works.
If it does not make sense perhaps it might be worth working through the
boost.python tutorial to get up to speed on how boost.python works.

You can call the expose_converters< npy_double >() function to expose
multiarrays of doubles to python as numpy arrays.

Please ask if you have any specific questions.

Regards,
John.


> 
> 
> 
> *From:* John Reid 
> *To:* cplusplus-sig@python.org
> *Sent:* Wednesday, August 22, 2012 12:28 PM
> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
> 
> On 22/08/12 11:13, alfa wrote:
>> Hi John,
>>
>> Thanks a lot for your implementation. In multi_array_to_numpy.h,  can
>> you give more hints on which method/function that I can possibly use if
>> I can include it in my implementation as a header file.
>>
>> Thanks in advance.
>>
> src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp
> implement a boost.python module that exposes the multi-array classes.
> You have choose which data types you expose multiarrays for.
> 
> HTH,
> John.
> 
> 
>>
>> 
>> *From:* John Reid  >
>> *To:* cplusplus-sig@python.org 
>> *Sent:* Thursday, August 16, 2012 5:02 PM
>> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
>>
>> If you don't mind digging around in my code, you could download the
>> source code for the STEME python package from pypi and look in the
>> c++/myrrh directory. There is code to access multi_arrays from python in
>> there.
>>
>> http://pypi.python.org/pypi/STEME/
>>
>> In particular the file
>> c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the
>> implementation.
>>
>> HTH,
>> John.
>>
>>
>>
>> On 16/08/12 09:29, alfa wrote:
>>> Hi,
>>>
>>> Could you give more hints on this or any code snippet that I can
>>> implement this. I'm a bit naive in applying this. Please consider my 2D
>>> array of Vp_cpp(Vp equivalent in Python) is as below:
>>>
>>>    typedef boost::multi_array array_type;
>>>    typedef array_type::index index;
>>>    array_type Vp_cpp(boost::extents[X_cpp][X_cpp]);
>>>
>>>
>>> I'm still puzzled how to "manually wrap the features" in the last
>> "..." in:
>>>    boost::python::class_< boost::multi_array<...> >(...)
>>>
>>> Thanks in advance.
>>>
>>> 
>>> *From:* Jim Bosch mailto:tallji...@gmail.com>
> >>
>>> *To:* alfa mailto:alfarobi0...@yahoo.com>
> >>
>>> *Cc:* Development of Python/C++ integration  
>> >>
>>> *Sent:* Wednesday, August 15, 2012 5:34 PM
>>> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
>>>
>>> On Aug 15, 2012 1:57 AM, "alfa"  
>> >
>>> 
> >> should do as below:

 boost::python::class_ >
("PyVec").def(boost::python::vector_indexing_suite
 >());

>>> No, I don't think that will work; I meant something like this:
>>> boost::python::class_< boost::multi_array<...> >(...)
>>>    ...;
>>> Where the last "..." is where you have to manually wrap the features of
>>> multi_array you want to use.  I'm afraid 

Re: [C++-sig] Accessing 2D array from python in C++

2012-08-22 Thread alfa
Hi John,

"You can call the expose_converters< npy_double >() function to expose 
multiarrays of doubles to python as numpy arrays."

I'm afraid you understood that I have a C++ array that is to be exposed in 
Python. Actually, my problem is the other way around in which I have a Python 
array that needs to be converted to/ exposed in C++.

Thanks in advance.





 From: John Reid 
To: cplusplus-sig@python.org 
Sent: Wednesday, August 22, 2012 1:11 PM
Subject: Re: [C++-sig] Accessing 2D array from python in C++
 


On 22/08/12 11:58, John Reid wrote:
> 
> 
> On 22/08/12 11:45, alfa wrote:
>> Hi John,
>>
>> I'm sorry, I'm a bit confused because previously you said that the
>> relevant implementation resides in
>> "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to
>> "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp".
>> Hope you understand my problem of having 2D array in python that needs
>> to be exposed/converted to C++. It would be great If I know any
>> method/function that I can invoke from any of your implementations.
>>
>> Thanks in advance.
> 
> Hi Alfa,
> 
> You can look at all of the code I've mentioned to work out how it works.
> If it does not make sense perhaps it might be worth working through the
> boost.python tutorial to get up to speed on how boost.python works.
> 
> You can call the expose_converters< npy_double >() function to expose
> multiarrays of doubles to python as numpy arrays.

Also look in python_test/test_man.py for code that tests the
implementation from the python side if it helps.

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Accessing 2D array from python in C++

2012-08-22 Thread John Reid


On 22/08/12 12:28, alfa wrote:
> Hi John,
> 
> "You can call the expose_converters< npy_double >() function to expose
> multiarrays of doubles to python as numpy arrays."
> 
> I'm afraid you understood that I have a C++ array that is to be exposed
> in Python. Actually, my problem is the other way around in which I have
> a Python array that needs to be converted to/ exposed in C++.

Exposing works both ways.

> 
> Thanks in advance.
> 
> 
> 
> *From:* John Reid 
> *To:* cplusplus-sig@python.org
> *Sent:* Wednesday, August 22, 2012 1:11 PM
> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
> 
> 
> 
> On 22/08/12 11:58, John Reid wrote:
>>
>>
>> On 22/08/12 11:45, alfa wrote:
>>> Hi John,
>>>
>>> I'm sorry, I'm a bit confused because previously you said that the
>>> relevant implementation resides in
>>> "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to
>>> "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp".
>>> Hope you understand my problem of having 2D array in python that needs
>>> to be exposed/converted to C++. It would be great If I know any
>>> method/function that I can invoke from any of your implementations.
>>>
>>> Thanks in advance.
>>
>> Hi Alfa,
>>
>> You can look at all of the code I've mentioned to wor k out how it works.
>> If it does not make sense perhaps it might be worth working through the
>> boost.python tutorial to get up to speed on how boost.python works.
>>
>> You can call the expose_converters< npy_double >() function to expose
>> multiarrays of doubles to python as numpy arrays.
> 
> Also look in python_test/test_man.py for code that tests the
> implementation from the python side if it helps.
> 
> ___
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org 
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> 
> 
> 
> 
> ___
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> 

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig