| 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 | result_blocks = self.blocks*other.blocks | |
| 168 | # Convert Zero objects back to ZeroMatrix with appropriate dimensions | |
| 169 | from sympy.core.numbers import Zero | |
| 170 | from sympy.matrices.immutable import ImmutableDenseMatrix | |
| 171 | ||
| 172 | def convert_zero_to_zeromatrix(blocks, rowblocksizes, colblocksizes): | |
| 173 | """Convert Zero objects in blocks to ZeroMatrix with proper dimensions""" | |
| 174 | new_data = [] | |
| 175 | for i in range(blocks.shape[0]): | |
| 176 | row = [] | |
| 177 | for j in range(blocks.shape[1]): | |
| 178 | block = blocks[i, j] | |
| 179 | if isinstance(block, Zero): | |
| 180 | # Create ZeroMatrix with appropriate dimensions | |
| 181 | row_block_size = rowblocksizes[i] | |
| 182 | col_block_size = colblocksizes[j] | |
| 183 | block = ZeroMatrix(row_block_size, col_block_size) | |
| 184 | row.append(block) | |
| 185 | new_data.append(row) | |
| 186 | return ImmutableDenseMatrix(new_data) | |
| 187 | ||
| 188 | # Get the block sizes for the result | |
| 189 | result_rowblocksizes = self.rowblocksizes | |
| 190 | result_colblocksizes = other.colblocksizes | |
| 191 | ||
| 192 | # Convert Zero objects to ZeroMatrix | |
| 193 | result_blocks = convert_zero_to_zeromatrix(result_blocks, result_rowblocksizes, result_colblocksizes) | |
| 194 | ||
| 195 | return BlockMatrix(result_blocks) | |
| 168 | 196 | |
| 169 | 197 | return self * other |
| 170 | 198 |
| 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.