2

Just wondering one simple thing:

Does the majority of numpy code have bindings to C++? (Which would make it run almost as fast as native C++ code)

Or is it all in python?

1
  • 2
    A large portion of the numpy code is written in C. Some of it is written in Fortran. A lot of it is written in Python. Well-written numpy code is comparable in speed to C code. Commented Sep 26, 2014 at 2:21

3 Answers 3

3

An easy way to bind NumPy (Python) code to C++ and use the NumPy arrays in place is xtensor: https://github.com/QuantStack/xtensor-python

In case you ever need that extra bit of speed.

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

Comments

1

This is an old thread, but the answers to this question are actually quite ridiculous and don't answer the simple question OP is posing.

To answer specifically: most of NumPy is implemented in C/C++ and was originally bound to Python with SWIG or through other manual procedures implemented by its creators. I am not up to date on its modernization but I would not be surprised if another framework for binding it to scripting languages is used today. NumPy is part of the larger SciPy project and a great read on this is this resource. All objects in NumPy are objects implemented in C/C++ - so there is some marshaling/type conversion that happens between your wrapper program (Python) and the underlying implementation in C/C++.

This is a complex topic that requires knowledge of C/C++ in order to fully grasp how the translation process happens between the two languages, but the importance here is that the methods and functions available to you in NumPy are not operating "under the hood" in the same way that operations using the Python standard library would be performed.

Comments

0

The documention of the numpy array API gives a lot of examples of how you can handle numpy arrays in C (and C++, it's the same API) or handling data existing in a C/C++ program through numpy.

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.