o
    oh                     @   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                       g | ]}  |qS  )col.0iMr   l/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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 ](} jg j } j||< tD ]\}}	||	  |||f 8  < q+|| q 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   s    z_nullspace.<locals>.<listcomp>c                    s   g | ]
}   jd |qS )r   )_newcols)r
   br   r   r   r   P   s    )rrefranger   zeroone	enumerateappend)
r   r   r   r   	free_varsbasis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                    r   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\}}|r2|jt|k r2tdg }	t|jD ]}
|rI| |dd|
f j}n
| |dd|
f }|		| q9|	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      s    z"_orthogonalize.<locals>.<listcomp>)r*   z0GramSchmidt: vector set not linearly independentN)
decompositionsr,   rowshstackr   r(   
ValueErrorr   Tr   )clsr*   r+   vecsr,   all_row_vecsr   QRretr   r   r   r   r   _orthogonalizei   s    0
r:   N)F)	utilitiesr   r   r%   r)   r:   r   r   r   r   <module>   s
    
"
-