I am looking to create a custom scalar type that has magnitude and a bunch of sign bits. I have defined operations such as arithmetic and comparison. I want to use this scalar type with numpy extensively. (Eg., Normal operations would involve multiplying matrices of size 1000 X 1000 multiple times). So I need this to be as efficient as possible. I have an implementation in C++ using Eigen as matrix library but I need a python port to make it easily accessible in python.
I see three ways as of now :
- Create a python class
- Create an extension type as explained here
- Using Boost.python and expose my C++ class
The operations of my type are only bit level (addition, for) but they would be done millions of times.
I would like to know what method would create the most efficient scalar type.
- writing a class in python Vs using boost, would there be any observable difference in speed
- writing an extension type in C Vs class in python, would the difference be noticable.
I could carry out experiment but I am looking for some experience. If this doesn't get answered, I will answer myself.
Edit:
As suggested by @Parfait, it looks like the best way would be using Cython cdef
. Here is a quick benchmark involving numpy and Cython.