Reputation: 2341
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?
Upvotes: 2
Views: 2944
Reputation: 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.
Upvotes: 0
Reputation: 892
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.
Upvotes: 0
Reputation: 323
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.
Upvotes: 3