hellokitty12345
hellokitty12345

Reputation: 33

Is it wise to use Numba and Cython togther?

I'm developing a program that relies upon iterating through many millions of data points as quickly as possible.

I am intending to convert this program into a standalone exe for easy use and distribution.

I have been looking into numba and cython as a means to speed up my program as much as possible but they both seem to be good at different things.

Numba is more limited but is extremely good at iterating through numpy arrays and is easy to implement without much thinking.

It also seems to be faster than Cython on average, especially when the datasets are huge. At least from what I've read.

Cython is a bit more difficult to implement than numba but is general purpose and nearly or just as fast in most circumstances.

But I've never heard of anyone using them together.

I'm thinking of using Numba when it's convenient and useful and Cython elsewhere.

Is this a bad idea? Am I missing something?

Upvotes: 2

Views: 1550

Answers (1)

DavidW
DavidW

Reputation: 30910

I'm thinking of using Numba when it's convenient and useful and Cython elsewhere.

What I think you'll find is:

  1. If you need to call Cython functions from Numba that @ead has written a very thorough answer that details the limitations. Basically, it can't see inside Cython def functions too well, but there are ways to pass cdef and cpdef functions to it.

  2. You can't define your Numba functions in Cython code. This is because Numba looks at the bytecode of the function and Cython-compiled functions don't have bytecode.

With those two caveats I think they can coexist so there's no real issue with picking and choosing based on the task.

Upvotes: 6

Related Questions