@@ -93,7 +93,7 @@ def empty(nblocks, dtype=np.float64):
9393 """
9494
9595 # Empty partition has block dims of zero until they are assigned
96- partition = [(0 ,0 )] * nblocks
96+ partition = [(0 , 0 )] * nblocks
9797
9898 return BlkDiagMatrix (partition , dtype = dtype )
9999
@@ -784,10 +784,10 @@ def from_list(blk_diag, dtype=np.float64):
784784 @staticmethod
785785 def from_mat (mat , blk_partition , dtype = np .float64 ):
786786 """
787- Convert full block diagonal matrix into list representation .
787+ Convert full block diagonal matrix into BlkDiagMatrix .
788788
789789 :param mat; The full block diagonal matrix including the zero elements
790- ofnon -diagonal blocks.
790+ of non -diagonal blocks.
791791 :param blk_partition: The matrix block partition in the form of a
792792 K-element list storing all shapes of K diagonal matrix blocks,
793793 where `blk_partition[i]` corresponds to the shape (number rows
@@ -796,15 +796,21 @@ def from_mat(mat, blk_partition, dtype=np.float64):
796796 :return: The BlkDiagMatrix instance.
797797 """
798798
799- # TODO: maybe can improve this implementation
800-
801799 A = BlkDiagMatrix (blk_partition , dtype = dtype )
802800
803801 rows = blk_partition [:, 0 ]
804802 cols = blk_partition [:, 1 ]
805803 cellarray = Cell2D (rows , cols , dtype = mat .dtype )
806- blk_diag = cellarray .mat_to_blk_diag (mat , rows , cols )
807- A .data = BlkDiagMatrix .from_list (blk_diag )
804+
805+ offset = 0
806+ blk_ind = 0
807+ for i in range (0 , cellarray .nrow ):
808+ for j in range (0 , cellarray .ncol ):
809+ offset += 1
810+ if i == j :
811+ blk_ind += 1
812+ A [blk_ind ] = cellarray .cell_list [offset ]
813+
808814 return A
809815
810816 def solve (self , Y ):
0 commit comments