numpyparallel-processingmatrix-multiplicationsvdnumba-pro

Is it not possible to call the in-built function e.g. svd in a custom python function that is parallized using @njit?


The following error is obtained while trying to run my for loop involving a svd function

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'svd': cannot determine Numba type of <class 'function'>

The code is as given below.

from scipy.linalg import svd
import numpy as np
from numba import jit

PatchSize = 5
@jit(nopython=True)
def svd_solver(image):
  Hight = image.shape[0]
  Width = image.shape[1]
  for i in range(PatchSize):
    for j in range(PatchSize):
       Count    =  Count+1
       Patch  =  ImgInput[i:Hight-PatchSize+i+1,j:Width-PatchSize+j+1]
       SG_S, SG_V, SG_D  =  svd(Patch)
  return SG_V

Solution

  • At the time of writing, Scipy is not in the list of the officially supported modules in Numba (see the documentation here and there).

    However, numpy.linalg.svd is supported according to the documentation (not that it may differ from scipy.linalg.svd). This support is partial as "only the 2 first arguments" are supported. This should be fine in your case.