I want to send a numpy array to a Armadillo (C++) and output a numpy array from the C++ program. I didn't find any tutorials online for this. Can someone give me pointers on how to do this ?
-
I'm not including code because, it is not relevant to the question and I didn't find any tutorials to try.user7241499– user72414992019-01-04 15:56:16 +00:00Commented Jan 4, 2019 at 15:56
-
read up on ctypes, im guessing that's what you're after.Paritosh Singh– Paritosh Singh2019-01-04 15:57:52 +00:00Commented Jan 4, 2019 at 15:57
-
1It is very relevant... What wrapper tool are you using for instance?Matthieu Brucher– Matthieu Brucher2019-01-04 15:58:06 +00:00Commented Jan 4, 2019 at 15:58
-
No I have code written python (numpy) and code that does stuff using armadillo in C++. I want to call the C++ function in python. But I don't know how to link them.user7241499– user72414992019-01-04 15:59:10 +00:00Commented Jan 4, 2019 at 15:59
-
1What wrapper tool are you using?Matthieu Brucher– Matthieu Brucher2019-01-04 16:00:18 +00:00Commented Jan 4, 2019 at 16:00
2 Answers
You can rely on cython and the numpy c interface for the data conversion. There are different projects that implement this including armanpy, a library for conversion between numpy and armadillo, or mlpack, a machine learning library that uses armadillo as its data and linear algebra backend. The easiest method that I found was to use the cyarma python library, which comes with simple examples of how to access the c++ armadillo functionality from within cython.
If you want to use purely C++ (without the cython) you could implement a conversion using the boost libraries.
Comments
first convert numpy array to c++ array and enter to armadillo and from outpu