dimanche 4 juin 2017

How to pass data from C++ to Python and back

I have a program I've written in C++ and I need to use some statistical tools that (since they are not available in C++) are written in Python.

What I have to do is pretty simple: I have two C++ vector objects representing two samples drawn from two random variables. What I want to do is translate these two vectors in one-dimensional Python arrays and pass them to the functions anderson_ksamp and ks_2samp (implementing respectively the Anderson-Darling K Sample Test and the Kolmogorov-Smirnov 2 Sample Test) from the scipy module, collect their output, pass it on to C++ and check if the two samples are drawn from the same distribution. That's it.

I've tried to do this, as a test, directly in Python and it took me something like 6 lines of code. But I really don't understand how to do the same thing from C++. It's been almost a week that I'm reading Python documentation and Stackoverflow questions non-stop without being able to figure out how to pass the two vectors from C++ to Python and back and how to call the two specific Python functions from C++.

Right now I'm working on a Mac using Xcode. I've installed Python 3.6 using Homebrew and successfully run a simple test program (the first example shown here: Embedding Python in C++ - Very High Level Example), so I know that all the compiler and linker flags are set correctly and Xcode sees and uses the right Python version.

Hoping to have been clear enough I thank you in advance for any help.

Aucun commentaire:

Enregistrer un commentaire