#NEWLINE# def sympy_to_scipy_sparse( m , **options ) : #NEWLINE# #INDENT# 'Convert a sympy Matrix/complex number to a numpy matrix or scalar.' #NEWLINE# if ( ( not np ) or ( not sparse ) ) : #NEWLINE# #INDENT# raise ImportError #NEWLINE# #UNINDENT# dtype = options . get ( 'dtype' , 'complex' ) #NEWLINE# if isinstance ( m , Matrix ) : #NEWLINE# #INDENT# return sparse . csr_matrix ( np . matrix ( m . tolist ( ) , dtype = dtype ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( m , Expr ) : #NEWLINE# #INDENT# if ( m . is_Number or m . is_NumberSymbol or ( m == I ) ) : #NEWLINE# #INDENT# return complex ( m ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# raise TypeError ( ( 'Expected Matrix or complex scalar, got: %r' % m ) )