#NEWLINE# def test_shape_compatibility( self ) : #NEWLINE# #INDENT# A = csc_matrix ( [ [ 1.0 , 0 ] , [ 0 , 2 ] ] ) #NEWLINE# bs = [ [ 1 , 6 ] , array ( [ 1 , 6 ] ) , [ [ 1 ] , [ 6 ] ] , array ( [ [ 1 ] , [ 6 ] ] ) , csc_matrix ( [ [ 1 ] , [ 6 ] ] ) , csr_matrix ( [ [ 1 ] , [ 6 ] ] ) , dok_matrix ( [ [ 1 ] , [ 6 ] ] ) , bsr_matrix ( [ [ 1 ] , [ 6 ] ] ) , array ( [ [ 1.0 , 2.0 , 3.0 ] , [ 6.0 , 8.0 , 10.0 ] ] ) , csc_matrix ( [ [ 1.0 , 2.0 , 3.0 ] , [ 6.0 , 8.0 , 10.0 ] ] ) , csr_matrix ( [ [ 1.0 , 2.0 , 3.0 ] , [ 6.0 , 8.0 , 10.0 ] ] ) , dok_matrix ( [ [ 1.0 , 2.0 , 3.0 ] , [ 6.0 , 8.0 , 10.0 ] ] ) , bsr_matrix ( [ [ 1.0 , 2.0 , 3.0 ] , [ 6.0 , 8.0 , 10.0 ] ] ) ] #NEWLINE# for b in bs : #NEWLINE# #INDENT# x = np . linalg . solve ( A . toarray ( ) , toarray ( b ) ) #NEWLINE# for spmattype in [ csc_matrix , csr_matrix , dok_matrix , lil_matrix ] : #NEWLINE# #INDENT# x1 = spsolve ( spmattype ( A ) , b , use_umfpack = True ) #NEWLINE# x2 = spsolve ( spmattype ( A ) , b , use_umfpack = False ) #NEWLINE# if ( ( x . ndim == 2 ) and ( x . shape [ 1 ] == 1 ) ) : #NEWLINE# #INDENT# x = x . ravel ( ) #NEWLINE# #UNINDENT# assert_array_almost_equal ( toarray ( x1 ) , x , err_msg = repr ( ( b , spmattype , 1 ) ) ) #NEWLINE# assert_array_almost_equal ( toarray ( x2 ) , x , err_msg = repr ( ( b , spmattype , 2 ) ) ) #NEWLINE# if ( isspmatrix ( b ) and ( x . ndim > 1 ) ) : #NEWLINE# #INDENT# assert_ ( isspmatrix ( x1 ) , repr ( ( b , spmattype , 1 ) ) ) #NEWLINE# assert_ ( isspmatrix ( x2 ) , repr ( ( b , spmattype , 2 ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert_ ( isinstance ( x1 , np . ndarray ) , repr ( ( b , spmattype , 1 ) ) ) #NEWLINE# assert_ ( isinstance ( x2 , np . ndarray ) , repr ( ( b , spmattype , 2 ) ) ) #NEWLINE# #UNINDENT# if ( x . ndim == 1 ) : #NEWLINE# #INDENT# assert_equal ( x1 . shape , ( A . shape [ 1 ] , ) ) #NEWLINE# assert_equal ( x2 . shape , ( A . shape [ 1 ] , ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert_equal ( x1 . shape , x . shape ) #NEWLINE# assert_equal ( x2 . shape , x . shape ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# A = csc_matrix ( ( 3 , 3 ) ) #NEWLINE# b = csc_matrix ( ( 1 , 3 ) ) #NEWLINE# assert_raises ( ValueError , spsolve , A , b )