tempj = np.empty(shape0, dtype=int)
R = self.__class__(self.shape)
for j in range(shape0):
Rj = spsolve(Q, P[:,j])
w = np.where(Rj != 0.0)[0]
tempj.fill(j)
R = R + self.__class__((Rj[w],(w,tempj[:len(w)])),
shape=self.shape, dtype=self.dtype)
After Change
P = U + V // p_m(A) : numerator
Q = -U + V // q_m(A) : denominator
R = solve(Q, P)
// squaring step to undo scaling
for i in range(n_squarings):
R = R.dot(R)