Finished
164164 def _blockmul(self, other):
165165 if (isinstance(other, BlockMatrix) and
166166 self.colblocksizes == other.rowblocksizes):
167 return BlockMatrix(self.blocks*other.blocks)
167 # Perform block multiplication manually to preserve ZeroMatrix types
168 from sympy.matrices import Matrix
169
170 # Get the block shapes
171 m, n = self.blockshape
172 p, q = other.blockshape
173
174 # Create result matrix
175 result_blocks = []
176 for i in range(m):
177 row = []
178 for j in range(q):
179 # Compute block (i,j) as sum of products
180 block_sum = None
181 for k in range(n):
182 # Multiply the blocks
183 block_product = self.blocks[i, k] * other.blocks[k, j]
184
185 # Convert scalar zeros back to ZeroMatrix if needed
186 if block_product == 0 and not isinstance(block_product, MatrixExpr):
187 # Determine the shape of the resulting matrix
188 rows = self.blocks[i, k].rows
189 cols = other.blocks[k, j].cols
190 block_product = ZeroMatrix(rows, cols)
191
192 if block_sum is None:
193 block_sum = block_product
194 else:
195 block_sum = block_sum + block_product
196 row.append(block_sum)
197 result_blocks.append(row)
198
199 return BlockMatrix(result_blocks)
168200
169201 return self * other
170202
Test NameStatus
test_zero_matrix_add
Fail
test_issue_17624
Pass
test_bc_matmul
Pass
test_bc_matadd
Pass
test_bc_transpose
Pass
test_bc_dist_diag
Pass
test_block_plus_ident
Pass
test_BlockMatrix
Pass
test_block_collapse_explicit_matrices
Pass
test_BlockMatrix_trace
Pass
test_BlockMatrix_Determinant
Pass
test_squareBlockMatrix
Pass
test_BlockDiagMatrix
Pass
test_blockcut
Pass
test_reblock_2x2
Pass
test_deblock
Pass
test_sort_key
Pass
test_matadd_sympify
Pass
test_matadd_of_matrices
Pass
test_doit_args
Pass
test_generic_identity
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.