| 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 | # Compute the block multiplication result | |
| 168 | result_blocks = self.blocks*other.blocks | |
| 169 | ||
| 170 | # Post-process to ensure zero results remain as ZeroMatrix objects | |
| 171 | # with proper dimensions instead of scalar Zero objects | |
| 172 | from sympy.core.numbers import Zero | |
| 173 | from sympy.matrices.immutable import ImmutableDenseMatrix | |
| 174 | ||
| 175 | # Create a new matrix with the same structure | |
| 176 | new_blocks_data = [] | |
| 177 | for i in range(result_blocks.rows): | |
| 178 | row_data = [] | |
| 179 | for j in range(result_blocks.cols): | |
| 180 | block = result_blocks[i, j] | |
| 181 | # If the block is a scalar Zero, replace it with a ZeroMatrix | |
| 182 | # with appropriate dimensions | |
| 183 | if isinstance(block, Zero): | |
| 184 | # Get the dimensions from the block structure | |
| 185 | # Row dimension from self's i-th row block size | |
| 186 | # Col dimension from other's j-th col block size | |
| 187 | row_dim = self.rowblocksizes[i] | |
| 188 | col_dim = other.colblocksizes[j] | |
| 189 | row_data.append(ZeroMatrix(row_dim, col_dim)) | |
| 190 | else: | |
| 191 | row_data.append(block) | |
| 192 | new_blocks_data.append(row_data) | |
| 193 | ||
| 194 | # Create the new blocks matrix | |
| 195 | new_blocks = ImmutableDenseMatrix(new_blocks_data) | |
| 196 | return BlockMatrix(new_blocks) | |
| 168 | 197 | |
| 169 | 198 | return self * other |
| 170 | 199 |
| 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.