| 164 | 164 | def _blockmul(self, other): |
| 165 | 165 | if (isinstance(other, BlockMatrix) and |
| 166 | 166 | self.colblocksizes == other.rowblocksizes): |
| 167 | return BlockMatrix(self.blocks*other.blocks) | |
| 167 | from sympy.matrices.immutable import ImmutableDenseMatrix | |
| 168 | # Perform block multiplication | |
| 169 | result_blocks = self.blocks * other.blocks | |
| 170 | ||
| 171 | # Convert Zero objects back to ZeroMatrix with appropriate dimensions | |
| 172 | def convert_to_matrix(block, row_idx, col_idx): | |
| 173 | from sympy import S | |
| 174 | if block is S.Zero: | |
| 175 | # Get dimensions from the corresponding blocks | |
| 176 | # For multiplication, the result block at (i,j) has dimensions: | |
| 177 | # rows: self.blocks[i, 0].rows (same as row i of self) | |
| 178 | # cols: other.blocks[0, j].cols (same as column j of other) | |
| 179 | rows = self.blocks[row_idx, 0].rows | |
| 180 | cols = other.blocks[0, col_idx].cols | |
| 181 | return ZeroMatrix(rows, cols) | |
| 182 | return block | |
| 183 | ||
| 184 | # Apply conversion to all blocks | |
| 185 | converted_blocks = ImmutableDenseMatrix([ | |
| 186 | [convert_to_matrix(result_blocks[i, j], i, j) | |
| 187 | for j in range(result_blocks.cols)] | |
| 188 | for i in range(result_blocks.rows) | |
| 189 | ]) | |
| 190 | ||
| 191 | return BlockMatrix(converted_blocks) | |
| 168 | 192 | |
| 169 | 193 | return self * other |
| 170 | 194 |
| Test Name | Status |
|---|---|
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.