Overloading Python math functions using Cython
cython, python
Solution
In an example from Cython's documentation, they use a cimport from a C library to achieve this:
from libc.math cimport sin
Problem
Here is my basic problem: I have a Python file with an import of ``` from math import sin,cos,sqrt ``` I need this file to still be 100% CPython compatible to allow my developers to write 100% CPython code and employ the great tools developed for Python. Now enter Cython. In my Python file, the trig functions get called millions of times (fundamental to the code, can't change this). Is there any way that through some Python-fu in the main python file, or Cython magic otherwise I can instead use the C/C++ math functions using some variation on the Cython code ``` cdef extern from "math.h": double sin(double) ``` That would give me near-C performance, which would be awesome. Stefan's talk says specifically this can't be done, but the talk is two years old, and there are many creative people out there