I have the following snippet of code where I've used numba in order to speed up my code:
import numpy as np
from numba import jit
Sigma = np.array([
[1, 1, 0.5, 0.25],
[1, 2.5, 1, 0.5],
[0.5, 1, 0.5, 0.25],
[0.25, 0.5, 0.25, 0.25]
])
Z = np.array([0.111, 0.00658])
@jit(nopython=True)
def mean(Sigma, Z):
return np.dot(np.dot(Sigma[0:2, 2:4], linalg.inv(Sigma[2:4, 2:4])), Z)
print(mean(Sigma, Z))
However, numba is complaining
NumbaPerformanceWarning: np.dot() is faster on contiguous arrays, called on (array(float64, 2d, A), array(float64, 2d, F))
return np.dot(np.dot(Sigma[0:2, 2:4], linalg.inv(Sigma[2:4, 2:4])), Z)
If I'm not mistaken (after reading this), the contiguous structure of the numpy arrays is broken due to the slicing of sub-matrices from Sigma (i.e., "Sigma[0:2, 2:4]"). Is this correct? If so is there any way to resolve this warning? I believe resolving this warning would help speed up my code which is my main goal. Thanks.