def _block_diag(A, n):
 if sparse.issparse(A):
  raise NotImplemented('sparse reversal not implemented yet')
 (ma, na) = A.shape
 bdn = (na // int(n))
 if ((na % n) > 0):
  raise ValueError('Width of matrix must be a multiple of n')
 tmp = np.arange((ma * bdn), dtype=np.int).reshape(bdn, ma)
 tmp = np.tile(tmp, (1, n))
 ii = tmp.ravel()
 jj = np.arange(na, dtype=np.int)[None, :]
 jj = (jj * np.ones(ma, dtype=np.int)[:, None])
 jj = jj.T.ravel()
 bd = sparse.coo_matrix((A.T.ravel(), np.c_[(ii, jj)].T)).tocsc()
 return bd

def _block_diag ( A , n ) : if sparse . issparse ( A ) : raise NotImplemented ( 'sparse reversal not implemented yet' ) ( ma , na ) = A . shape bdn = ( na // int ( n ) ) if ( ( na % n ) > 0 ) : raise ValueError ( 'Width of matrix must be a multiple of n' ) tmp = np . arange ( ( ma * bdn ) , dtype = np . int ) . reshape ( bdn , ma ) tmp = np . tile ( tmp , ( 1 , n ) ) ii = tmp . ravel ( ) jj = np . arange ( na , dtype = np . int ) [ None , : ] jj = ( jj * np . ones ( ma , dtype = np . int ) [ : , None ] ) jj = jj . T . ravel ( ) bd = sparse . coo_matrix ( ( A . T . ravel ( ) , np . c_ [ ( ii , jj ) ] . T ) ) . tocsc ( ) return bd
construct a block diagonal from a packed structure .