No speed gains from Cython

后端 未结 7 839
不思量自难忘°
不思量自难忘° 2021-01-30 14:05

I am trying to define a function that contains an inner loop for simulating an integral.

The problem is speed. Evaluating the function once can take up to 30 seconds on

7条回答
  •  青春惊慌失措
    2021-01-30 14:51

    Cython can produce an html file to help with this:

    cython -a MODULE.py
    

    This shows each line of source code colored white through various shades of yellow. The darker the yellow color, the more dynamic Python behaviour is still being performed on that line. For each line that contains some yellow, you need to add more static typing declarations.

    When I'm doing this, I like to split parts of my source code that I'm having trouble with onto many separate lines, one for each expression or operator, to get the most granular view.

    Without this, it's easy to overlook some static type declarations of variables, function calls or operators. (e.g. the indexing operator x[y] is still a fully-dynamic Python operation unless you declare otherwise)

提交回复
热议问题