Closed jiqicn closed 2 years ago
The expensive parts of the code (by order):
Both the first and second parts are quite straight forward (vectorized operations), and no idea how to make them faster.
For the third part that is the for-loop, tried to vectorize things as much as possible, but still no significant improvement on performance (typically about 1 second faster).
See code:
TODO:
The Cython code can be found in the gitlabmaster branch: https://github.com/ODISSEI-School-Choice/school-choice/tree/gitlabmaster/cython_school_ranking.
The idea is to type all the variables and accept numpy arrays involved in heavy computation as memoryviews. Also, the argsort function is rewritten in Cython as well.
There is a notebook to show the profiling result of both the Python and the Cython versions. Basically, I would say they are equally fast, which means converting Python code to Cython doesn't bring significant improvement on performance. And since it doesn't add any benefit on readability of the code, the Cython solution is given up.
Possible bottlenecks: