#NEWLINE# def solve( a , b , sym_pos = False , lower = False , overwrite_a = False , overwrite_b = False , debug = False , check_finite = True ) : #NEWLINE# #INDENT# '\n    Solve the equation ``a x = b`` for ``x``.\n\n    Parameters\n    ----------\n    a : (M, M) array_like\n        A square matrix.\n    b : (M,) or (M, N) array_like\n        Right-hand side matrix in ``a x = b``.\n    sym_pos : bool, optional\n        Assume `a` is symmetric and positive definite.\n    lower : bool, optional\n        Use only data contained in the lower triangle of `a`, if `sym_pos` is\n        true.  Default is to use upper triangle.\n    overwrite_a : bool, optional\n        Allow overwriting data in `a` (may enhance performance).\n        Default is False.\n    overwrite_b : bool, optional\n        Allow overwriting data in `b` (may enhance performance).\n        Default is False.\n    check_finite : bool, optional\n        Whether to check that the input matrices contain only finite numbers.\n        Disabling may give a performance gain, but may result in problems\n        (crashes, non-termination) if the inputs do contain infinities or NaNs.\n\n    Returns\n    -------\n    x : (M,) or (M, N) ndarray\n        Solution to the system ``a x = b``.  Shape of the return matches the\n        shape of `b`.\n\n    Raises\n    ------\n    LinAlgError\n        If `a` is singular.\n    ValueError\n        If `a` is not square\n\n    Examples\n    --------\n    Given `a` and `b`, solve for `x`:\n\n    >>> a = np.array([[3, 2, 0], [1, -1, 0], [0, 5, 1]])\n    >>> b = np.array([2, 4, -1])\n    >>> from scipy import linalg\n    >>> x = linalg.solve(a, b)\n    >>> x\n    array([ 2., -2.,  9.])\n    >>> np.dot(a, x) == b\n    array([ True,  True,  True], dtype=bool)\n\n    ' #NEWLINE# a1 = _asarray_validated ( a , check_finite = check_finite ) #NEWLINE# b1 = _asarray_validated ( b , check_finite = check_finite ) #NEWLINE# if ( ( len ( a1 . shape ) != 2 ) or ( a1 . shape [ 0 ] != a1 . shape [ 1 ] ) ) : #NEWLINE# #INDENT# raise ValueError ( 'expected square matrix' ) #NEWLINE# #UNINDENT# if ( a1 . shape [ 0 ] != b1 . shape [ 0 ] ) : #NEWLINE# #INDENT# raise ValueError ( 'incompatible dimensions' ) #NEWLINE# #UNINDENT# overwrite_a = ( overwrite_a or _datacopied ( a1 , a ) ) #NEWLINE# overwrite_b = ( overwrite_b or _datacopied ( b1 , b ) ) #NEWLINE# if debug : #NEWLINE# #INDENT# print ( 'solve:overwrite_a=' , overwrite_a ) #NEWLINE# print ( 'solve:overwrite_b=' , overwrite_b ) #NEWLINE# #UNINDENT# if sym_pos : #NEWLINE# #INDENT# ( posv , ) = get_lapack_funcs ( ( 'posv' , ) , ( a1 , b1 ) ) #NEWLINE# ( c , x , info ) = posv ( a1 , b1 , lower = lower , overwrite_a = overwrite_a , overwrite_b = overwrite_b ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( gesv , ) = get_lapack_funcs ( ( 'gesv' , ) , ( a1 , b1 ) ) #NEWLINE# ( lu , piv , x , info ) = gesv ( a1 , b1 , overwrite_a = overwrite_a , overwrite_b = overwrite_b ) #NEWLINE# #UNINDENT# if ( info == 0 ) : #NEWLINE# #INDENT# return x #NEWLINE# #UNINDENT# if ( info > 0 ) : #NEWLINE# #INDENT# raise LinAlgError ( 'singular matrix' ) #NEWLINE# #UNINDENT# raise ValueError ( ( 'illegal value in %d-th argument of internal gesv|posv' % ( - info ) ) )