| 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.core.numbers import Zero | |
| 168 | ||
| 169 | # Multiply the blocks | |
| 170 | multiplied_blocks = self.blocks * other.blocks | |
| 171 | ||
| 172 | # Convert Zero objects back to ZeroMatrix with correct dimensions | |
| 173 | def convert_zero_to_zeromatrix(block_matrix): | |
| 174 | from sympy.matrices.immutable import ImmutableDenseMatrix | |
| 175 | ||
| 176 | # Create a new matrix with Zero objects converted to ZeroMatrix | |
| 177 | new_data = [] | |
| 178 | for i in range(block_matrix.shape[0]): | |
| 179 | row_data = [] | |
| 180 | for j in range(block_matrix.shape[1]): | |
| 181 | elem = block_matrix[i, j] | |
| 182 | if isinstance(elem, Zero): | |
| 183 | # Determine the correct dimensions for this ZeroMatrix | |
| 184 | # Row dimension comes from self.rowblocksizes[i] | |
| 185 | # Column dimension comes from other.colblocksizes[j] | |
| 186 | rows = self.rowblocksizes[i] | |
| 187 | cols = other.colblocksizes[j] | |
| 188 | row_data.append(ZeroMatrix(rows, cols)) | |
| 189 | else: | |
| 190 | row_data.append(elem) | |
| 191 | new_data.append(row_data) | |
| 192 | ||
| 193 | return ImmutableDenseMatrix(new_data) | |
| 194 | ||
| 195 | converted_blocks = convert_zero_to_zeromatrix(multiplied_blocks) | |
| 196 | return BlockMatrix(converted_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.