
    _-Ph'                     $    d Z ddlZd Zd Zd ZdS )zJUtility Functions for reading and writing individual rows in BSR matrices.    Nc                    | j         d         }t          ||z            }| j        |         }| j        |dz            }||z  }| j        |||ddf                                         }| j        |||ddf         |d         |d         f         }t          j        dt          |          ft
          j                  }	d}
t          ||          D ]]}|| j
        |         z  }| j        ||ddf                                         d         }|j        d         }||z   |	d|
|
|z   f<   |
|z  }
^|                    dd          |	dddf         fS )a  Return row i in BSR matrix A.

    Only nonzero entries are returned

    Parameters
    ----------
    A : bsr_matrix
        Input matrix
    i : int
        Row number

    Returns
    -------
    z : array
        Actual nonzero values for row i colindx Array of column indices for the
        nonzeros of row i

    Examples
    --------
    >>> from numpy import array
    >>> from scipy.sparse import bsr_matrix
    >>> from pyamg.util.bsr_utils import bsr_getrow
    >>> indptr  = array([0,2,3,6])
    >>> indices = array([0,2,2,0,1,2])
    >>> data    = array([1,2,3,4,5,6]).repeat(4).reshape(6,2,2)
    >>> B = bsr_matrix( (data,indices,indptr), shape=(6,6) )
    >>> Brow = bsr_getrow(B,2)
    >>> print(Brow[1])
    [4 5]

    r      N)dtype)	blocksizeintindptrdatanonzeronpzeroslenint32rangeindicesshapereshape)Air   	BlockIndxrowstartrowendlocalRowIndxindyszcolindxcounterj	coloffset	increments                 T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pyamg/util/bsr_utils.py
bsr_getrowr"      sl   @ AIAiK  Ix	"HXik"Fy=L F8F?L!!!34<<>>E	xaaa/0q581CDAh3q66{"(333GG8V$$  ail*	q,)*2244Q7KN	2;e2C7GI-../999RWQT]**    c                    | j         d         }t          ||z            }| j        |         }| j        |dz            }||z  }| j        |||ddf                                         }|| j        |||ddf         |d         |d         f<   dS )a[  Set a scalar at each nonzero location in row i of BSR matrix A.

    Parameters
    ----------
    A : bsr_matrix
        Input matrix
    i : int
        Row number
    x : float
        Scalar to overwrite nonzeros of row i in A

    Returns
    -------
    A : bsr_matrix
        All nonzeros in row i of A have been overwritten with x.
        If x is a vector, the first length(x) nonzeros in row i
        of A have been overwritten with entries from x

    Examples
    --------
    >>> from numpy import array
    >>> from scipy.sparse import bsr_matrix
    >>> from pyamg.util.bsr_utils import bsr_row_setscalar
    >>> indptr  = array([0,2,3,6])
    >>> indices = array([0,2,2,0,1,2])
    >>> data    = array([1,2,3,4,5,6]).repeat(4).reshape(6,2,2)
    >>> B = bsr_matrix( (data,indices,indptr), shape=(6,6) )
    >>> bsr_row_setscalar(B,5,22)

    r   r   N)r   r   r	   r
   r   	r   r   xr   r   r   r   r   r   s	            r!   bsr_row_setscalarr'   >   s    > AIAiK  Ix	"HXik"Fy=L F8F?L!!!34<<>>ECDAF8F?L!!!+,U1XuQx-?@@@r#   c                    | j         d         }t          ||z            }| j        |         }| j        |dz            }||z  }|                                                    t          |j                  f          }| j        |||ddf                                         }|| j        |||ddf         |d         |d         f<   dS )a  Set the nonzeros in row i of BSR matrix A with the vector x.

    length(x) and nnz(A[i,:]) must be equivalent

    Parameters
    ----------
    A : bsr_matrix
        Matrix assumed to be in BSR format
    i : int
        Row number
    x : array
        Array of values to overwrite nonzeros in row i of A

    Returns
    -------
    A : bsr_matrix
        The nonzeros in row i of A have been
        overwritten with entries from x.  x must be same
        length as nonzeros of row i.  This is guaranteed
        when this routine is used with vectors derived form
        bsr_getrow

    Examples
    --------
    >>> from numpy import array
    >>> from scipy.sparse import bsr_matrix
    >>> from pyamg.util.bsr_utils import bsr_row_setvector
    >>> indptr  = array([0,2,3,6])
    >>> indices = array([0,2,2,0,1,2])
    >>> data    = array([1,2,3,4,5,6]).repeat(4).reshape(6,2,2)
    >>> B = bsr_matrix( (data,indices,indptr), shape=(6,6) )
    >>> bsr_row_setvector(B,5,array([11,22,33,44,55,66]))

    r   r   N)	r   r   r	   	__array__r   maxr   r
   r   r%   s	            r!   bsr_row_setvectorr+   l   s    F AIAiK  Ix	"HXik"Fy=L 	
s17||o..A F8F?L!!!34<<>>ECDAF8F?L!!!+,U1XuQx-?@@@r#   )__doc__numpyr   r"   r'   r+    r#   r!   <module>r/      sZ    P P    4+ 4+ 4+n+E +E +E\4E 4E 4E 4E 4Er#   