1

I am studying in machine learning now and I want to build up a recommender system. First, I would like to make a top-N recommendation using two existing methods and they are both written in C++ code. As the file are huge and complex, I want to call them with Python, instead of adding code on that. Which tool is suitable for my case? Thank you in advance!

5
  • 2
    You can use something like SWIG. Commented Dec 11, 2015 at 16:56
  • 1
    I've heard good things about Boost.Python. Commented Dec 11, 2015 at 16:57
  • 3
    Just create a wrapper by extending Python. Commented Dec 11, 2015 at 17:02
  • 1
    If you have the sources, wrap them with Cython. It's way easier than using the standard Python C API Commented Dec 11, 2015 at 17:11
  • 2
    Possible duplicate of Calling C/C++ from python? Commented Dec 11, 2015 at 18:57

2 Answers 2

1

You can use standard python api , Cython or Boost.python. It is much easier to work with boost.python. You have to add very little code to your c++ library and compile it as a module library which then you can call from python.

with boost you can easily add your classes and their methods. Additionally you can introduce vector of an object which makes it easier to pass data to python and back to your library.

I recommend boost.python but you can look for yourself. There are a lot of tutorials on both cython and boost.python if you google it.

Sign up to request clarification or add additional context in comments.

Comments

0

Definitely use Cython. Useful tools to make the process easier: runcython (simplifies Cython use) and Google's protobuf library (simple / fast messaging serialization library). Here's a really simple example to help people get started: https://github.com/nicodjimenez/python2cpp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.