a
    RG5d                     @   sB   d dl mZ dddZdefddZdddZddd	d
dZdS )   )_iszeroFc                    s$    j |dd\}} fdd|D S )a  Returns a list of vectors (Matrix objects) that span columnspace of ``M``

    Examples
    ========

    >>> from sympy import Matrix
    >>> M = Matrix(3, 3, [1, 3, 0, -2, -6, 0, 3, 9, 6])
    >>> M
    Matrix([
    [ 1,  3, 0],
    [-2, -6, 0],
    [ 3,  9, 6]])
    >>> M.columnspace()
    [Matrix([
    [ 1],
    [-2],
    [ 3]]), Matrix([
    [0],
    [0],
    [6]])]

    See Also
    ========

    nullspace
    rowspace
    Tsimplifywith_pivotsc                    s   g | ]}  |qS  )col.0iMr   T/var/www/html/django/DPS/env/lib/python3.9/site-packages/sympy/matrices/subspaces.py
<listcomp>#       z _columnspace.<locals>.<listcomp>)echelon_form)r   r   reducedpivotsr   r   r   _columnspace   s    r   c           
         s    j ||d\}fddt jD }g }|D ]P} jg j } j||< tD ] \}}	||	  |||f 8  < qV|| q2 fdd|D S )a  Returns list of vectors (Matrix objects) that span nullspace of ``M``

    Examples
    ========

    >>> from sympy import Matrix
    >>> M = Matrix(3, 3, [1, 3, 0, -2, -6, 0, 3, 9, 6])
    >>> M
    Matrix([
    [ 1,  3, 0],
    [-2, -6, 0],
    [ 3,  9, 6]])
    >>> M.nullspace()
    [Matrix([
    [-3],
    [ 1],
    [ 0]])]

    See Also
    ========

    columnspace
    rowspace
    )
iszerofuncr   c                    s   g | ]}| vr|qS r   r   r   )r   r   r   r   B   r   z_nullspace.<locals>.<listcomp>c                    s   g | ]}   jd |qS )r   )_newcols)r	   br   r   r   r   P   r   )rrefranger   zeroone	enumerateappend)
r   r   r   r   Z	free_varsbasisZfree_varvecpiv_rowpiv_colr   )r   r   r   
_nullspace&   s    
r"   c                    s,   | j |dd\ } fddtt|D S )aD  Returns a list of vectors that span the row space of ``M``.

    Examples
    ========

    >>> from sympy import Matrix
    >>> M = Matrix(3, 3, [1, 3, 0, -2, -6, 0, 3, 9, 6])
    >>> M
    Matrix([
    [ 1,  3, 0],
    [-2, -6, 0],
    [ 3,  9, 6]])
    >>> M.rowspace()
    [Matrix([[1, 3, 0]]), Matrix([[0, 0, 6]])]
    Tr   c                    s   g | ]}  |qS r   )rowr   r   r   r   r   f   r   z_rowspace.<locals>.<listcomp>)r   r   len)r   r   r   r   r$   r   	_rowspaceS   s    r&   )	normalize	rankcheckc                G   s   ddl m} |sg S |d jdk}dd |D }| j| }|||d\}}|rd|jt|k rdtdg }	t|jD ]>}
|r| |dd|
f j}n| |dd|
f }|		| qr|	S )	a  Apply the Gram-Schmidt orthogonalization procedure
    to vectors supplied in ``vecs``.

    Parameters
    ==========

    vecs
        vectors to be made orthogonal

    normalize : bool
        If ``True``, return an orthonormal basis.

    rankcheck : bool
        If ``True``, the computation does not stop when encountering
        linearly dependent vectors.

        If ``False``, it will raise ``ValueError`` when any zero
        or linearly dependent vectors are found.

    Returns
    =======

    list
        List of orthogonal (or orthonormal) basis vectors.

    Examples
    ========

    >>> from sympy import I, Matrix
    >>> v = [Matrix([1, I]), Matrix([1, -I])]
    >>> Matrix.orthogonalize(*v)
    [Matrix([
    [1],
    [I]]), Matrix([
    [ 1],
    [-I]])]

    See Also
    ========

    MatrixBase.QRdecomposition

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process
    r   )_QRdecomposition_optional    c                 S   s   g | ]}|  qS r   )r   )r	   xr   r   r   r      r   z"_orthogonalize.<locals>.<listcomp>)r'   z0GramSchmidt: vector set not linearly independentN)
decompositionsr)   rowshstackr   r%   
ValueErrorr   Tr   )clsr'   r(   vecsr)   Zall_row_vecsr   QRretr
   r   r   r   r   _orthogonalizei   s     0
r6   N)F)F)	utilitiesr   r   r"   r&   r6   r   r   r   r   <module>   s   
"-
