bohdan

Finished
7979 def __new__(cls, *args, **kwargs):
8080 from sympy.matrices.immutable import ImmutableDenseMatrix
8181 from sympy.utilities.iterables import is_sequence
82 from sympy import S
8283 isMat = lambda i: getattr(i, 'is_Matrix', False)
84 # Allow scalar zeros to be treated as valid blocks
85 isMatOrZero = lambda i: getattr(i, 'is_Matrix', False) or i == S.Zero
8386 if len(args) != 1 or \
8487 not is_sequence(args[0]) or \
85 len(set([isMat(r) for r in args[0]])) != 1:
88 len(set([isMatOrZero(r) for r in args[0]])) != 1:
8689 raise ValueError(filldedent('''
8790 expecting a sequence of 1 or more rows
8891 containing Matrices.'''))
148151
149152 @property
150153 def rowblocksizes(self):
151 return [self.blocks[i, 0].rows for i in range(self.blockshape[0])]
154 from sympy import S
155 sizes = []
156 for i in range(self.blockshape[0]):
157 block = self.blocks[i, 0]
158 if hasattr(block, 'rows'):
159 sizes.append(block.rows)
160 elif block == S.Zero:
161 # For scalar zero, find the row size from other blocks in the same row
162 row_size = None
163 for j in range(self.blockshape[1]):
164 other_block = self.blocks[i, j]
165 if hasattr(other_block, 'rows'):
166 row_size = other_block.rows
167 break
168 if row_size is None:
169 # If all blocks in this row are scalar zeros, use the overall shape
170 # This is a fallback - ideally this shouldn't happen in valid block matrices
171 total_rows = sum(self.blocks[k, 0].rows for k in range(self.blockshape[0]) if hasattr(self.blocks[k, 0], 'rows'))
172 if total_rows > 0:
173 row_size = total_rows // self.blockshape[0]
174 else:
175 row_size = 1 # Default fallback
176 sizes.append(row_size)
177 else:
178 # For other non-matrix objects, try to get shape or use default
179 if hasattr(block, 'shape'):
180 sizes.append(block.shape[0])
181 else:
182 sizes.append(1) # Default fallback
183 return sizes
152184
153185 @property
154186 def colblocksizes(self):
155 return [self.blocks[0, i].cols for i in range(self.blockshape[1])]
187 from sympy import S
188 sizes = []
189 for i in range(self.blockshape[1]):
190 block = self.blocks[0, i]
191 if hasattr(block, 'cols'):
192 sizes.append(block.cols)
193 elif block == S.Zero:
194 # For scalar zero, find the column size from other blocks in the same column
195 col_size = None
196 for j in range(self.blockshape[0]):
197 other_block = self.blocks[j, i]
198 if hasattr(other_block, 'cols'):
199 col_size = other_block.cols
200 break
201 if col_size is None:
202 # If all blocks in this column are scalar zeros, use the overall shape
203 # This is a fallback - ideally this shouldn't happen in valid block matrices
204 total_cols = sum(self.blocks[0, k].cols for k in range(self.blockshape[1]) if hasattr(self.blocks[0, k], 'cols'))
205 if total_cols > 0:
206 col_size = total_cols // self.blockshape[1]
207 else:
208 col_size = 1 # Default fallback
209 sizes.append(col_size)
210 else:
211 # For other non-matrix objects, try to get shape or use default
212 if hasattr(block, 'shape'):
213 sizes.append(block.shape[1])
214 else:
215 sizes.append(1) # Default fallback
216 return sizes
156217
157218 def structurally_equal(self, other):
158219 return (isinstance(other, BlockMatrix)
Test NameStatus
test_issue_17624
Fail
test_zero_matrix_add
Fail
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.