update generator used for sparse matrix vector product (#450)

This commit is contained in:
Tyler Chen
2023-04-19 19:47:32 -07:00
committed by GitHub
parent d100a89b4c
commit ae610886c2
2 changed files with 4 additions and 8 deletions
+2 -2
View File
@@ -84,8 +84,8 @@ class MatrixCalculusMethods:
[ 2.26812870852145 2.44114713886289 1.42699786729125]
[0.841130841230196 1.42699786729125 1.6000162976327]
>>> expm([[1+j, 0], [1+j,1]])
[(1.46869393991589 + 2.28735528717884j) 0.0]
[ (1.03776739863568 + 3.536943175722j) (2.71828182845905 + 0.0j)]
[(1.46869393991589 + 2.28735528717884j) 0.0]
[ (1.03776739863568 + 3.536943175722j) 2.71828182845905]
Matrices with large entries are allowed::
+2 -6
View File
@@ -573,14 +573,10 @@ class _matrix:
if self.__cols != other.__rows:
raise ValueError('dimensions not compatible for multiplication')
new = self.ctx.matrix(self.__rows, other.__cols)
self_zero = self.ctx.zero
self_get = self.__data.get
other_zero = other.ctx.zero
other_get = other.__data.get
for i in range(self.__rows):
for j in range(other.__cols):
new[i, j] = self.ctx.fdot((self_get((i,k), self_zero), other_get((k,j), other_zero))
for k in range(other.__rows))
new[i, j] = self.ctx.fdot((self.__data[i,k], other.__data[k,j])
for k in range(other.__rows) if (i,k) in self.__data and (k,j) in other.__data)
return new
else:
# try scalar multiplication