armor

Finished
148148
149149 @property
150150 def rowblocksizes(self):
151 return [self.blocks[i, 0].rows for i in range(self.blockshape[0])]
151 result = []
152 for i in range(self.blockshape[0]):
153 block = self.blocks[i, 0]
154 if hasattr(block, 'rows'):
155 result.append(block.rows)
156 else:
157 # Handle Zero objects by finding dimensions from other blocks in the same row
158 for j in range(self.blockshape[1]):
159 other_block = self.blocks[i, j]
160 if hasattr(other_block, 'rows'):
161 result.append(other_block.rows)
162 break
163 else:
164 # If all blocks in this row are Zero objects,
165 # we need to handle this differently
166 raise ValueError("Cannot determine row dimensions from zero blocks")
167 return result
152168
153169 @property
154170 def colblocksizes(self):
155 return [self.blocks[0, i].cols for i in range(self.blockshape[1])]
171 result = []
172 for i in range(self.blockshape[1]):
173 block = self.blocks[0, i]
174 if hasattr(block, 'cols'):
175 result.append(block.cols)
176 else:
177 # Handle Zero objects by finding dimensions from other blocks in the same column
178 for j in range(self.blockshape[0]):
179 other_block = self.blocks[j, i]
180 if hasattr(other_block, 'cols'):
181 result.append(other_block.cols)
182 break
183 else:
184 # If all blocks in this column are Zero objects,
185 # we need to handle this differently
186 raise ValueError("Cannot determine column dimensions from zero blocks")
187 return result
156188
157189 def structurally_equal(self, other):
158190 return (isinstance(other, BlockMatrix)
164196 def _blockmul(self, other):
165197 if (isinstance(other, BlockMatrix) and
166198 self.colblocksizes == other.rowblocksizes):
167 return BlockMatrix(self.blocks*other.blocks)
199 result_blocks = self.blocks*other.blocks
200 # Convert Zero objects back to ZeroMatrix with proper dimensions
201 from sympy.core.numbers import Zero
202 converted_blocks = []
203 for i in range(result_blocks.shape[0]):
204 row = []
205 for j in range(result_blocks.shape[1]):
206 block = result_blocks[i, j]
207 if isinstance(block, Zero):
208 # Determine dimensions from the original blocks
209 # For block (i,j), the dimensions should be:
210 # rows: self.rowblocksizes[i], cols: other.colblocksizes[j]
211 rows = self.rowblocksizes[i]
212 cols = other.colblocksizes[j]
213 row.append(ZeroMatrix(rows, cols))
214 else:
215 row.append(block)
216 converted_blocks.append(row)
217 return BlockMatrix(converted_blocks)
168218
169219 return self * other
170220
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.