Are there advantages to use the Python/C interface instead of Cython?

前端 未结 3 1565
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 01:16

I want to extend python and numpy by writing some modules in C or C++, using BLAS and LAPACK. I also want to be able to distribute the code as standalone C/C++ libraries. I

3条回答
  •  我在风中等你
    2020-12-24 01:32

    First, there is one point in your question I don't get:

    [...] also want to be able to distribute the code as standalone C/C++ libraries. [...] Some functions will need to call a Python function from the C/C++ code.

    How is this supposed to work?

    Next, as to your actual question, there are certainly advantages of using the Python/C API directly:

    • Most likely, you are more familar with writing C code than writing Cython code.

    • Writing your code in C gives you maximum control. To get the same performance from Cython code as from equivalent C code, you'll have to be very careful. You'll not only need to make sure to declare the types of all variables, you'll also have to set some flags adequately -- just one example is bounds checking. You will need intimate knowledge how Cython is working to get the best performance.

    • Cython code depends on Python. It does not seem to be a good idea to write code that should also be distributed as standalone C library in Cython

提交回复
热议问题