Search code examples
pythonperformancescipysparse-matrix

Bypass dok_matrix.get type checking


16% of the running time of my program is spent inside the isintlike() function from scipy/sparse/sputils. All of the calls to isintlike() come from calls to dok_matrix.get() (which make up 20% of the running time). I know that the indices I'm calling get() with are ints, so i don't actually need type checking.

I tried to bypass it by using x[coords] instead of x.get(coords), but this actually slowed down my program. I'm guessing it's calling get() behind the scenes with added overhead.

I'm not planning on reducing the number of calls to dok_matrix.get(), so this is the bottleneck for now. Is there any way to bypass this type checking?


Solution

  • You can call the dict base class method directly, bypassing the type checking:

    dict.get(dok_matrix, coords)