+
    LV-j
é  ã                   óh  € R t Rt. R2Ot^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt	^ RI
HtHtHt ^ RIHt ^RIHtHtHtHt ^RIHt ^RIHtHt ^RIHtHt ^R	IHtHt ^R
I H!t!H"t" ^RI#H$t$H%t% ^RI&H't'H(t( R^ /R lt)R t*R3R lt+R4R lt,R^ RRRRR]/R lt-^ RR]3R lt.R5R lt/R6R^ R]0RR/R llt1R7R lt2R^ ]0R3R lt3R6R lt4R6R lt5R t6R  t7R8R! lt8R8R" lt9R8R# lt:RRRR/R$ lt;R9R% lt<R8R& lt=]! R'4      R(R)RR*RRR+RR,R/R- l4       t>R:R. lt?]! R'^R/7      R;R0 l4       t@]! R'^R/7      R<R1 l4       tAR# )=z2Functions to construct sparse matrices and arrays
zrestructuredtext enN)Úcheck_random_stateÚrng_integersÚ_transition_to_rng)Ú_NoValue)ÚupcastÚget_index_dtypeÚisscalarlikeÚ	isintlike)Ú
csr_hstack)Ú
bsr_matrixÚ	bsr_array)Ú
coo_matrixÚ	coo_array)Ú
csc_matrixÚ	csc_array)Ú
csr_matrixÚ	csr_array)Ú
dia_matrixÚ	dia_array)ÚissparseÚsparrayÚaxisc              ód  € \        V4      '       g   \        RV R24      hV^ 8¼  d   TMWP                  ,           ^,           pV^ 8  g   W P                  8”  d   \        RV RV P                   R24      hV P                  RR7      p\        P
                  ! VP                  ^ ,          4      pVP                  RV V3,           VP                  VR ,           Vn        VP                  RV R	,           VP                  VR ,           Vn        V P                  R8X  d   V P                  Vn
        V# )
a™  
Add trivial axes to an array. Shape gets a ``1`` inserted at position `axis`.

Parameters
----------
A : sparse array

axis : int
    Position in the expanded axes where the new axis (or axes) is placed.
    For a dimension ``N`` array, a valid axis is an integer on the
    closed-interval ``[-N-1, N]``. Negative values work from the end of
    the shape. ``0`` prepends an axis, as does ``-N-1``. ``-1`` appends
    an axis, as does ``N``. The new axis has shape ``1`` and indices are
    created with the value ``0``.

Returns
-------
out : sparse array
    A expanded copy output in COO format with the same dtype as `A`.

Raises
------
ValueError
    If provided a non-integer or out of range ``[-N-1, N]`` axis,
    where ``N`` is ``A.ndim``.

Examples
--------
>>> from scipy.sparse import csr_array, expand_dims
>>> A = csr_array([[1, 2], [2, 0]])
>>> A.shape
(2, 2)
>>> expand_dims(A, axis=1).shape
(2, 1, 2)

zInvalid axis z. Must be an integer.z for N=z. Must be in [-N-1, N].T©ÚcopyNÚcoo©é   )r	   Ú
ValueErrorÚndimÚtocooÚnpÚ
zeros_likeÚcoordsÚshapeÚ_shapeÚformatÚhas_canonical_format)ÚAr   ÚidxÚnewAÚ	new_coords   "$   Úh/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/scipy/sparse/_construct.pyÚexpand_dimsr-       sþ   € ôJ �T�?Š?Ü˜=¨¨Ð.CÐDÓEÐEØ˜!”)‰$ ¯©¥°Õ!2€CØ
ˆQ„w�#Ÿ™”,Ü˜=¨¨¨g°a·f±f°XÐ=TÐUÓVÐVà�7‰7˜ˆ7Ó€DÜ—’˜dŸk™k¨!�nÓ-€Ià—+‘+˜d˜sÐ# y lÕ2°T·[±[ÀÀÐ5FÕF€D„KØ—*‘*˜T˜cÐ" TÕ)¨D¯J©J°s°tÐ,<Õ<€D„KØ‡x�x�5ÔØ$%×$:Ñ$:ˆÔ!Ø€Kó    c                óR  € \         P                  ! V P                  4      p W2V.,          W1V.&   \        T4      p\        YRR7      #   \         dT   p\	        T4      pTP                  R4      P                  R^4      ^ ,          p\        RT RT P                   24      hRp?ii ; i)a'  Interchange two axes of an array.

Parameters
----------
A : sparse array
axis1 : int
    First axis.
axis2 : int
    Second axis.

Returns
-------
a_swapped : sparse array in COO format
    A copy of the input array with the two identified axes swapped.

Raises
------
ValueError
    If provided a non-integer or out of range ``[-N, N-1]`` axis,
    where ``N`` is ``A.ndim``.

Examples
--------
>>> from scipy.sparse import coo_array, swapaxes
>>> A = coo_array([[[1, 2, 3], [2, 0, 0]]])
>>> A.shape
(1, 2, 3)
>>> swapaxes(A, 1, 2).shape
(1, 3, 2)

zindex z axis zInvalid axis: z ndim=NT)Úaxesr   )
r!   Úaranger   Ú
IndexErrorÚstrÚremoveprefixÚsplitr   ÚtupleÚpermute_dims)r(   Úaxis1Úaxis2r0   ÚerrÚmsgs   &&&   r,   Úswapaxesr<   U   s    € ô@ �9Š9�Q—V‘VÓ€Dð?Ø#¨E NÕ3ˆ�Uˆ^Ñô �‹;€DÜ˜¨4Ô0Ð0øô ô ?ä�#‹hˆØ×Ñ˜xÓ(×.Ñ.¨x¸Ó;¸AÕ>ˆä˜>¨#¨¨f°Q·V±V°HÐ=Ó>Ð>ûð?ús   ¢A ÁB&ÁAB!Â!B&c                óP  a € S P                   pVf    \        \        V4      RRR1,          4      pM+\        V4      V8w  d   \	        RV RS P                    24      h\        V\        \        34      '       gc   \        P                  ! \        P                  ! \        V4      4      \        P                  4      '       g   \        R\        V4       24      hV3p. pV F[  p\        V4      '       g   \        RV R24      hV^ 8  d	   WS,          pV^ 8  g   WS8¼  d   \	        R4      hVP                  V4       K]  	  \        V4      \        \        V4      4      8w  d   \	        R4      hTpV\        \        V4      4      8X  d   V'       g   S # S P!                  4       # S P#                  VR	7      o \        ;QJ d    . V 3R
 lV 4       F  NK  	  5M! V 3R
 lV 4       4      S n        \        ;QJ d    . V 3R lV 4       F  NK  	  5M! V 3R lV 4       4      S n        RS n        S # )a  Permute the axes of the sparse array `A` to the order `axes`.

Parameters
----------
A : sparse array
axes : tuple or list of ints, optional
    If specified, it must be a tuple or list which contains a permutation
    of ``[0, 1, ..., N-1]`` where ``N`` is ``A.ndim``. The ith
    axis of the returned array will correspond to the axis numbered ``axes[i]``
    of the input. If not specified, defaults to ``range(A.ndim)[::-1]``,
    which reverses the order of the axes.
copy : bool, optional (default: False)
    Whether to return the permutation as a copy. If False, an in-place
    permutation is provided if possible depending on format.

Returns
-------
out : sparse array in COO format
    A copy of `A` with permuted axes.

Raises
------
ValueError
    If provided a non-integer or out of range ``[-N, N-1]`` axis,
    where ``N`` is ``A.ndim``.

Examples
--------
>>> from scipy.sparse import coo_array, permute_dims
>>> A = coo_array([[[1, 2, 3], [2, 0, 0]]])
>>> A.shape
(1, 2, 3)
>>> permute_dims(A, axes=(1, 2, 0)).shape
(2, 3, 1)

NzIncorrect number of axes: z instead of z+axis must be an integer/tuple of ints, not z axis must be an integer. (given Ú)zaxis out of range for ndimzduplicate value in axisr   c              3   óJ   <"  € T F  pSP                   V,          x € K  	  R # 5i©N©r$   ©Ú.0r)   r(   s   & €r,   Ú	<genexpr>Úpermute_dims.<locals>.<genexpr>É   s   øé € Ð2©T c�Q—W‘W˜S—\’\«Tùó   ƒ #c              3   óJ   <"  € T F  pSP                   V,          x € K  	  R # 5ir@   )r#   rB   s   & €r,   rD   rE   Ê   s   øé € Ð3©d s�Q—X‘X˜c—]’]«dùrF   Féÿÿÿÿ)r   r6   ÚrangeÚlenr   Ú
isinstanceÚlistr!   Ú
issubdtypeÚdtypeÚtypeÚintegerÚ	TypeErrorr	   ÚappendÚsetr   r    r%   r#   r'   )r(   r0   r   r   Ú
canon_axesÚaxs   f&&   r,   r7   r7   ƒ   s²  ø€ ðJ �6‰6€DØ‚|Ü”U˜4“[¡ 2 Õ&Ó'‰Ü	ˆT‹�dÔ	ÜÐ5°d°V¸<ÈÏÉÀxÐPÓQÐQô �dœU¤D˜M×*Ò*ô �}Š}œRŸXšX¤d¨4£jÓ1´2·:±:×>Ò>ÜÐIÌ$ÈtË*ÈÐVÓWÐWØˆwˆà€JÛˆÜ˜�}Š}ÜÐ>¸r¸dÀ!ÐDÓEÐEØ�Œ6Ø�JˆBØ�Œ6�R”ZÜÐ9Ó:Ð:Ø×Ñ˜"Öñ ô ˆ:ƒœ#œc *›oÓ.Ô.ÜÐ2Ó3Ð3à€DØŒt”E˜$“KÓ Ô ßˆqÐ* !§&¡&£(Ð*à	�‰�TˆÓ€AßŒuÔ2©TÓ2�u‰uÔ2©TÓ2Ó2€A„HßŒuÔ3©dÓ3�u‰uÔ3©dÓ3Ó3€A„HØ"€AÔØ€Hr.   c                ó†   € Vf   Vf   \        V ^ ,          4      ;r#MVf   Vw  r#\        W3W#3R7      P                  V4      # )a  
Return a sparse matrix from diagonals.

.. warning::

    This function returns a sparse matrix -- not a sparse array.
    You are encouraged to use `dia_array` to take advantage
    of the sparse array functionality. (See Notes below.)

Parameters
----------
data : array_like
    Matrix diagonals stored row-wise
diags : sequence of int or an int
    Diagonals to set:

    * k = 0  the main diagonal
    * k > 0  the kth upper diagonal
    * k < 0  the kth lower diagonal
m, n : int, tuple, optional
    Shape of the result. If `n` is None and `m` is a given tuple,
    the shape is this tuple. If omitted, the matrix is square and
    its shape is ``len(data[0])``.
format : str, optional
    Format of the result. By default (format=None) an appropriate sparse
    matrix format is returned. This choice is subject to change.

Returns
-------
new_matrix : sparse matrix
    `dia_matrix` format with values in ``data`` on diagonals from ``diags``.

Notes
-----
This function can be replaced by an equivalent call to `dia_matrix`
as::

    dia_matrix((data, diags), shape=(m, n)).asformat(format)

See Also
--------
diags_array : more convenient form of this function
diags : matrix version of diags_array
dia_matrix : the sparse DIAgonal format.

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import spdiags
>>> data = np.array([[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]])
>>> diags = np.array([0, -1, 2])
>>> spdiags(data, diags, 4, 4).toarray()
array([[1, 0, 3, 0],
       [1, 2, 0, 4],
       [0, 2, 3, 0],
       [0, 0, 3, 4]])

rA   )rJ   r   Úasformat)ÚdataÚdiagsÚmÚnr&   s   &&&&&r,   Úspdiagsr\   Ï   sH   € ðv 	‚y�Q’YÜ�D˜•G“ÐˆˆAØ	
ŠØ‰ˆÜ�t�m¨A¨6Ô2×;Ñ;¸FÓCÐCr.   Úoffsetsr$   r&   rN   c              ón  € \        V4      '       dL   \        V 4      ^ 8X  g   \        V ^ ,          4      '       d   \        P                  ! V 4      .p M.\	        R4      h\        \        \        P                  V 4      4      p \        P                  ! V4      p\        V 4      \        V4      8w  d   \	        R4      hVf6   \        V ^ ,          4      \        \        V^ ,          4      4      ,           pWU3pVf   \        P                  ! V !  pMºV\        J d±   \        P                  ! \        P                  ! V !  4      p\        P                  ! V !  p\        P                  R8  d   R^/pRpM(R\        P                   P#                  \$        4      3/pRpWF8w  d+   \&        P(                  ! RV RV R	2V,           \*        3/ VB  Vw  rY\-        V U
u. uF,  p
\/        WZ,           Wš,
          4      \-        ^ V
4      ,           NK.  	  up
4      p\-        ^ V4      p\        P0                  ! \        V4      V3VR
7      p\/        WY4      p\3        V 4       Ff  w  rïW,          p
\-        ^ V
4      p\/        WZ,           Wš,
          V4      pV^ 8  d   \	        RV
 RV R24      h VRRV13,          WÎVVV,           13&   Kh  	  \5        WÁ3WY3R7      P7                  V4      # u up
i   \         dL   p\        T4      T8w  d6   \        T4      ^8w  d&   \	        RT R\        T4       RT
 RT RT	 R24      Thh Rp?ii ; i)az  
Construct a sparse array from diagonals.

Parameters
----------
diagonals : sequence of array_like
    Sequence of arrays containing the array diagonals,
    corresponding to `offsets`.
offsets : sequence of int or an int, optional
    Diagonals to set (repeated offsets are not allowed):
      - k = 0  the main diagonal (default)
      - k > 0  the kth upper diagonal
      - k < 0  the kth lower diagonal
shape : tuple of int, optional
    Shape of the result. If omitted, a square array large enough
    to contain the diagonals is returned.
format : {"dia", "csr", "csc", "lil", ...}, optional
    Matrix format of the result. By default (format=None) an
    appropriate sparse array format is returned. This choice is
    subject to change.
dtype : dtype, optional
    Data type of the array.  If `dtype` is None, the output
    data type is determined by the data type of the input diagonals.

    Up until SciPy 1.19, the default behavior will be to return an array
    with an inexact (floating point) data type.  In particular, integer
    input will be converted to double precision floating point.  This
    behavior is deprecated, and in SciPy 1.19, the default behavior
    will be changed to return an array with the same data type as the
    input diagonals.  To adopt this behavior before version 1.19, use
    `dtype=None`.

Returns
-------
new_array : dia_array
    `dia_array` holding the values in `diagonals` offset from the main diagonal
    as indicated in `offsets`.

Notes
-----
Repeated diagonal offsets are disallowed.

The result from ``diags_array`` is the sparse equivalent of::

    np.diag(diagonals[0], offsets[0])
    + ...
    + np.diag(diagonals[k], offsets[k])

``diags_array`` differs from `dia_array` in the way it handles off-diagonals.
Specifically, `dia_array` assumes the data input includes padding
(ignored values) at the start/end of the rows for positive/negative
offset, while ``diags_array`` assumes the input data has no padding.
Each value in the input `diagonals` is used.

.. versionadded:: 1.11

See Also
--------
dia_array : constructor for the sparse DIAgonal format.

Examples
--------
>>> from scipy.sparse import diags_array
>>> diagonals = [[1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0], [1.0, 2.0]]
>>> diags_array(diagonals, offsets=[0, -1, 2]).toarray()
array([[1., 0., 1., 0.],
       [1., 2., 0., 2.],
       [0., 2., 3., 0.],
       [0., 0., 3., 4.]])

Broadcasting of scalars is supported (but shape needs to be
specified):

>>> diags_array([1.0, -2.0, 1.0], offsets=[-1, 0, 1], shape=(4, 4)).toarray()
array([[-2.,  1.,  0.,  0.],
       [ 1., -2.,  1.,  0.],
       [ 0.,  1., -2.,  1.],
       [ 0.,  0.,  1., -2.]])


If only one diagonal is wanted (as in `numpy.diag`), the following
works as well:

>>> diags_array([1.0, 2.0, 3.0], offsets=1).toarray()
array([[ 0.,  1.,  0.,  0.],
       [ 0.,  0.,  2.,  0.],
       [ 0.,  0.,  0.,  3.],
       [ 0.,  0.,  0.,  0.]])

z*Different number of diagonals and offsets.NÚ
stacklevelzü
Note: In Python 3.11, this warning can be generated by a call of scipy.sparse.diags(), but the code indicated in the warning message will refer to an internal call of scipy.sparse.diags_array(). If that happens, check your code for the use of diags().Úskip_file_prefixesÚ zInput has data type z", but the output has been cast to zÌ.  In the future, the output data type will match the input. To avoid this warning, set the `dtype` parameter to `None` to have the output dtype match the input, or set it to the desired output data type.©rN   zOffset z (index z) out of bounds.zDiagonal length (index ú: z at offset z") does not agree with array size (z, z).rA   )é   é   )r   rJ   r!   Ú
atleast_1dr   rL   ÚmapÚabsÚintÚresult_typer   rN   Úcommon_typeÚsysÚversion_infoÚosÚpathÚdirnameÚ__file__ÚwarningsÚwarnÚFutureWarningÚmaxÚminÚzerosÚ	enumerater   rW   )Ú	diagonalsr]   r$   r&   rN   rZ   Úfuture_dtypeÚwarn_kwargsÚ	extra_msgr[   ÚoffsetÚMÚdata_arrÚKÚjÚdiagonalÚkÚlengthÚes   "$$$$              r,   Údiags_arrayr†     s  € ôx �G×Òäˆy‹>˜QÔ¤,¨y¸­|×"<Ò"<ÜŸš yÓ1Ð2‰IäÐIÓJÐJäœœRŸ]™]¨IÓ6Ó7ˆ	ä�mŠm˜GÓ$€Gô ˆ9ƒ~œ˜W›Ô%ÜÐEÓFÐFð ‚}Ü�	˜!•Ó¤¤C¨°­
£OÓ 4Õ4ˆØ�ˆð ‚}Ü—’ 	Ñ*‰Ø	”(Ó	ô —’œŸš¨Ñ3Ó4ˆÜ—~’~ yÑ1ˆÜ×Ñ˜gÔ%Ø'¨Ð+ˆKð8‰Ið 0´"·'±'·/±/Ä(Ó2KÐ1MÐNˆKØˆIØÔ!Ü�MŠMØ& | nð 5Ø�Wð ,ð,ð
 õô ñ	ð ò	ð �D€AäÙ"ó$Ù"�ô �•˜Q�ZÓ(¬3¨q°&«>×9Ð9Ù"ñ$ó 	%€AäˆAˆq‹	€AÜ�xŠxœ˜W› qÐ)°Ô7€HäˆA‹	€Aä  Ö+‰ˆØ•ˆÜ��6‹NˆÜ�Q•Z ¥¨QÓ/ˆØ�AŒ:Ü˜w v h¨h°q°c¸ÐIÓJÐJð	Ø&.¨s°7°F°7¨{Õ&;ˆH˜˜!˜F�(˜
�]Ó#ñ ,ô  �hÐ(°°Ô7×@Ñ@ÀÓHÐHùò/$øô ô 	Ü�8‹} Ô&¬3¨x«=¸AÔ+=Ü Ø-¨a¨S°´3°x³=°/ð BØ%˜hÐ&HÈÈÈ2ÈaÈSÐPRðTóð ðð ûð	ús   Ç2KÊKËL4Ë)AL/Ì/L4c                óP   € \        WW$R7      p\        V4      P                  V4      # )a'  
Construct a sparse matrix from diagonals.

.. warning::

    This function returns a sparse matrix -- not a sparse array.
    You are encouraged to use `diags_array` to take advantage
    of the sparse array functionality.

Parameters
----------
diagonals : sequence of array_like
    Sequence of arrays containing the matrix diagonals,
    corresponding to `offsets`.
offsets : sequence of int or an int, optional
    Diagonals to set (repeated offsets are not allowed):
      - k = 0  the main diagonal (default)
      - k > 0  the kth upper diagonal
      - k < 0  the kth lower diagonal
shape : tuple of int, optional
    Shape of the result. If omitted, a square matrix large enough
    to contain the diagonals is returned.
format : {"dia", "csr", "csc", "lil", ...}, optional
    Matrix format of the result. By default (format=None) an
    appropriate sparse matrix format is returned. This choice is
    subject to change.
dtype : dtype, optional
    Data type of the matrix.  If `dtype` is None, the output
    data type is determined by the data type of the input diagonals.

    Up until SciPy 1.19, the default behavior will be to return a matrix
    with an inexact (floating point) data type.  In particular, integer
    input will be converted to double precision floating point.  This
    behavior is deprecated, and in SciPy 1.19, the default behavior
    will be changed to return a matrix with the same data type as the
    input diagonals.  To adopt this behavior before version 1.19, use
    `dtype=None`.

Returns
-------
new_matrix : dia_matrix
    `dia_matrix` holding the values in `diagonals` offset from the main diagonal
    as indicated in `offsets`.

Notes
-----
Repeated diagonal offsets are disallowed.

The result from ``diags`` is the sparse equivalent of::

    np.diag(diagonals[0], offsets[0])
    + ...
    + np.diag(diagonals[k], offsets[k])

``diags`` differs from `dia_matrix` in the way it handles off-diagonals.
Specifically, `dia_matrix` assumes the data input includes padding
(ignored values) at the start/end of the rows for positive/negative
offset, while ``diags`` assumes the input data has no padding.
Each value in the input `diagonals` is used.

.. versionadded:: 0.11

See Also
--------
spdiags : construct matrix from diagonals
diags_array : construct sparse array instead of sparse matrix

Examples
--------
>>> from scipy.sparse import diags
>>> diagonals = [[1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0], [1.0, 2.0]]
>>> diags(diagonals, [0, -1, 2]).toarray()
array([[1., 0., 1., 0.],
       [1., 2., 0., 2.],
       [0., 2., 3., 0.],
       [0., 0., 3., 4.]])

Broadcasting of scalars is supported (but shape needs to be
specified):

>>> diags([1.0, -2.0, 1.0], [-1, 0, 1], shape=(4, 4)).toarray()
array([[-2.,  1.,  0.,  0.],
       [ 1., -2.,  1.,  0.],
       [ 0.,  1., -2.,  1.],
       [ 0.,  0.,  1., -2.]])


If only one diagonal is wanted (as in `numpy.diag`), the following
works as well:

>>> diags([1.0, 2.0, 3.0], 1).toarray()
array([[ 0.,  1.,  0.,  0.],
       [ 0.,  0.,  2.,  0.],
       [ 0.,  0.,  0.,  3.],
       [ 0.,  0.,  0.,  0.]])

©r]   r$   rN   )r†   r   rW   )ry   r]   r$   r&   rN   r(   s   &&&&& r,   rY   rY   ½  s&   € ôD 	�I°eÔI€AÜ�a‹=×!Ñ! &Ó)Ð)r.   c                ó   € \        W WR7      # )a¿  Identity matrix in sparse format

Returns an identity matrix with shape ``(n, n)`` using a given
sparse format and dtype. This differs from `eye_array` in
that it has a square shape with ones only on the main diagonal.
It is thus the multiplicative identity. `eye_array` allows
rectangular shapes and the diagonal can be offset from the main one.

.. warning::

    This function returns a sparse matrix -- not a sparse array.
    You are encouraged to use `eye_array` to take advantage
    of the sparse array functionality.

Parameters
----------
n : int
    Shape of the identity matrix.
dtype : dtype, optional
    Data type of the matrix
format : str, optional
    Sparse format of the result, e.g., format="csr", etc.

Returns
-------
new_matrix : sparse matrix
    A square sparse matrix with ones on the main diagonal and zeros elsewhere.

See Also
--------
eye_array : Sparse array of chosen shape with ones on a specified diagonal.
eye : Sparse matrix of chosen shape with ones on a specified diagonal.

Examples
--------
>>> import scipy as sp
>>> sp.sparse.identity(3).toarray()
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])
>>> sp.sparse.identity(3, dtype='int8', format='dia')
<DIAgonal sparse matrix of dtype 'int8'
    with 3 stored elements (1 diagonals) and shape (3, 3)>
>>> sp.sparse.eye_array(3, dtype='int8', format='dia')
<DIAgonal sparse array of dtype 'int8'
    with 3 stored elements (1 diagonals) and shape (3, 3)>

)rN   r&   )Úeye)r[   rN   r&   s   &&&r,   Úidentityr‹   #  s   € ôb ˆq˜5Ô0Ð0r.   rƒ   c               ó   € \        WW#V4      # )aó  Sparse array of chosen shape with ones on the kth diagonal and zeros elsewhere.

Return a sparse array with ones on diagonal.
Specifically a sparse array (m x n) where the kth diagonal
is all ones and everything else is zeros.

Parameters
----------
m : int
    Number of rows requested.
n : int, optional
    Number of columns. Default: `m`.
k : int, optional
    Diagonal to place ones on. Default: 0 (main diagonal).
dtype : dtype, optional
    Data type of the array
format : str, optional (default: "dia")
    Sparse format of the result, e.g., format="csr", etc.

Returns
-------
new_array : sparse array
    Sparse array of chosen shape with ones on the kth diagonal and zeros elsewhere.

Examples
--------
>>> import numpy as np
>>> import scipy as sp
>>> sp.sparse.eye_array(3).toarray()
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])
>>> sp.sparse.eye_array(3, dtype=np.int8)
<DIAgonal sparse array of dtype 'int8'
    with 3 stored elements (1 diagonals) and shape (3, 3)>

©Ú_eye©rZ   r[   rƒ   rN   r&   s   &&$$$r,   Ú	eye_arrayr�   W  s   € ôN ��a Ó'Ð'r.   c           
      ó   € V'       d   \         p\        p\        p\        p	M\        p\
        p\        p\        p	Vf   T p\        V 4      \        V4      rW8X  dæ   V^ 8X  dß   VR9   ds   \        VR7      p
\        P                  ! V^,           V
R7      p\        P                  ! WR7      p\        P                  ! WR7      pRVRV/V,          pV! WÜV3W34      # VR8X  d_   \        VR7      p
\        P                  ! WR7      p\        P                  ! WR7      p\        P                  ! WR7      pV! WßV33W34      # \        P                  ! ^\        ^ \        W,           V4      4      3VR7      pV	! WÒ.W3VR7      P                  V4      # )NÚcsrÚcsc©Úmaxvalrb   r   rˆ   )r’   r“   )r   r   r   r†   r   r   r   rY   ri   r   r!   r1   Úonesru   rv   rW   )rZ   r[   rƒ   rN   r&   Ú
as_sparrayÚ
csr_sparseÚ
csc_sparseÚ
coo_sparseÚdiags_sparseÚ	idx_dtypeÚindptrÚindicesrX   ÚclsÚrowÚcols   &&&&&&           r,   rŽ   rŽ   �  sM  € ßÜˆ
Üˆ
Üˆ
Ü"‰äˆ
Üˆ
Üˆ
Üˆà‚yØˆÜˆq‹6”3�q“6€qà„v�!�q”&à�^Ô#Ü'¨qÔ1ˆIÜ—Y’Y˜q �s¨)Ô4ˆFÜ—i’i Ô3ˆGÜ—7’7˜1Ô*ˆDØ˜* e¨ZÐ8¸Õ@ˆCÙ˜ vÐ.°°Ó7Ð7à�uŒ_Ü'¨qÔ1ˆIÜ—)’)˜AÔ/ˆCÜ—)’)˜AÔ/ˆCÜ—7’7˜1Ô*ˆDÙ˜t¨3 ZÐ0°1°&Ó9Ð9ä�7Š7�A”s˜1œc !¥%¨›mÓ,Ð-°UÔ;€DÙ˜ c°!°¸uÔE×NÑNÈvÓVÐVr.   c                ó   € \        WW#VR4      # )aÁ  Sparse matrix of chosen shape with ones on the kth diagonal and zeros elsewhere.

Returns a sparse matrix (m x n) where the kth diagonal
is all ones and everything else is zeros.

.. warning::

    This function returns a sparse matrix -- not a sparse array.
    You are encouraged to use `eye_array` to take advantage
    of the sparse array functionality.

Parameters
----------
m : int
    Number of rows in the matrix.
n : int, optional
    Number of columns. Default: `m`.
k : int, optional
    Diagonal to place ones on. Default: 0 (main diagonal).
dtype : dtype, optional
    Data type of the matrix.
format : str, optional
    Sparse format of the result, e.g., format="csr", etc.

Returns
-------
new_matrix : sparse matrix
    Sparse matrix of chosen shape with ones on the kth diagonaland zeros elsewhere.

See Also
--------
eye_array : Sparse array of chosen shape with ones on a specified diagonal.

Examples
--------
>>> import numpy as np
>>> import scipy as sp
>>> sp.sparse.eye(3).toarray()
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])
>>> sp.sparse.eye(3, dtype=np.int8)
<DIAgonal sparse matrix of dtype 'int8'
    with 3 stored elements (1 diagonals) and shape (3, 3)>

Fr�   r�   s   &&&&&r,   rŠ   rŠ   ¦  s   € ô^ ��a ¨Ó.Ð.r.   c                óô
  € \        V \        4      '       g   \        V\        4      '       d   \        p\        p\        pM\
        p\        p\        pV! V4      pVe	   VR8X  Ed±   VP                  ^8X  EdŸ   ^VP                  ,          \        P                  ! VP                  4      8¼  Edh   \        V R4      '       d   V P                  ^8w  d	   V! V 4      p V P                  ^8X  Ed*   V! V RR7      p V P                  ^ ,          VP                  ^ ,          ,          V P                  ^,          VP                  ^,          ,          3pV P                  ^ 8X  g   VP                  ^ 8X  d   V! V4      P                  V4      # VP                  4       pV P                   P#                  VP$                  4      P'                  R
VP                  ^ ,          VP                  ^,          4      pWq,          pV! WpP(                  V P*                  3VR7      # MV! V 4      p V\        J dZ   V P                  ^ ,          VP                  ^ ,          ,          V P                  ^,          VP                  ^,          ,          3p^ pM¶V P                  VP                  ,
          pV^ 8¼  d   V P                  MRV) ,          V P                  ,           p	V^ 8:  d   VP                  MRV,          VP                  ,           p
\,        ;QJ d    . R \/        Wš4       4       F  NK  	  5M! R \/        Wš4       4       4      pV P                  ^ 8X  g   VP                  ^ 8X  d   V! V4      P                  V4      # V P                   P#                  VP                  4      p\1        V P2                  \5        V4      R7      pV P2                   Uu. uF3  p\6        P8                  ! WËR	7      P#                  VP                  4      NK5  	  ppV^ 8  d]   \6        P:                  ! V^ ,          4      pV.\=        V) ^,
          4       Uu. uF  qþP?                  4       NK  	  up,           V,           p\/        WÑP                  ) R VP                  4       F  w  ppVV,          pK  	  \/        WÑP                  ) R VP2                  4       UUu. uF7  w  ppVP'                  R
VP                  4      V,           PA                  4       NK9  	  uppWÑP                  ) R% VP'                  R
VP                  4      VP                   ,          PA                  4       pV! V\-        V4      3VR7      P                  V4      # u upi u upi u uppi )a¡  Sparse representation of the Kronecker product of `A` and `B`

Computes the Kronecker product, a composite sparse array
made of blocks consisting of the second input array multiplied
by each element of the first input array.

Parameters
----------
A : sparse or dense array
    first array of the product
B : sparse or dense array
    second array of the product
format : str, optional (default: 'bsr' or 'coo')
    format of the result (e.g. "csr")
    If None, choose 'bsr' for relatively dense 2D arrays and 'coo' for others

Returns
-------
sparse matrix or array
    kronecker product in a sparse format. Returns a sparse matrix unless either
    `A` or `B` is a sparse array in which case returns a sparse array.

Examples
--------
>>> import numpy as np
>>> import scipy as sp
>>> A = sp.sparse.csr_array(np.array([[0, 2], [5, 0]]))
>>> B = sp.sparse.csr_array(np.array([[1, 2], [3, 4]]))
>>> sp.sparse.kron(A, B).toarray()
array([[ 0,  0,  2,  4],
       [ 0,  0,  6,  8],
       [ 5, 10,  0,  0],
       [15, 20,  0,  0]])

>>> sp.sparse.kron(A, [[1, 2], [3, 4]]).toarray()
array([[ 0,  0,  2,  4],
       [ 0,  0,  6,  8],
       [ 5, 10,  0,  0],
       [15, 20,  0,  0]])

NÚbsrr   Tr   rA   c              3   ó6   "  € T F  w  rW,          x € K  	  R # 5ir@   © )rC   ÚaÚbs   &  r,   rD   Úkron.<locals>.<genexpr>/  s   é € ÐEÑ/D¡t q˜QŸUšUÓ/Dùs   ‚r”   rb   rH   r   )!rK   r   r   r   r   r   r   r   r   ÚnnzÚmathÚprodr$   ÚhasattrrW   ÚtoarrayrX   ÚrepeatÚsizeÚreshaperž   r�   r6   Úzipr   r#   ru   r!   Úasarrayr"   rI   r   Úravel)r(   ÚBr&   Ú
bsr_sparser˜   rš   Úoutput_shaperX   Ú	ndim_diffÚA_shapeÚB_shaperœ   Úcor#   Únew_coÚ_Ú	B_shape_iÚBcos   &&&               r,   ÚkronrÀ   Ø  sû  € ôV �!”W×Ò¤¨A¬w×!7Ò!7äˆ
Üˆ
Ü‰
äˆ
Üˆ
Üˆ
á�1‹€Að 
Š˜6 U�?Ø	�‰�!�˜˜!Ÿ%™%�¤4§9¢9¨Q¯W©WÓ#5Õ5ä�q˜&×!Ò! Q§V¡V¨q¤[á˜1“ˆAØ�6‰6�Q�;Ù˜1 4Ô(ˆAØŸG™G A�J q§w¡w¨q¥zÕ1°1·7±7¸1µ:¸a¿g¹gÀa½jÕ3HÐIˆLà�u‰u˜Œz˜QŸU™U aœZá! ,Ó/×8Ñ8¸Ó@Ð@à—	‘	“ˆAØ—6‘6—=‘= §¡Ó(×0Ñ0°°Q·W±W¸QµZÀÇÁÈÅÓLˆDØ•8ˆDá˜t§Y¡Y°·±Ð9ÀÔNÐNð ñ �q‹Mˆð ”ZÓØŸ™ �
 Q§W¡W¨Q¥ZÕ/°·±¸µ¸a¿g¹gÀa½jÕ1HÐIˆØ‰	à—F‘F˜QŸV™V•Oˆ	Ø&¨!œ^�!—'’'°¸)¸Õ1DÀqÇwÁwÕ1NˆØ&¨!œ^�!—'’'°¸	Õ1AÀAÇGÁGÕ1Kˆß”uÑE¬s°7Ô/DÓE—u‘uÑE¬s°7Ô/DÓEÓEˆà‡u�u�„z�Q—U‘U˜a”Zá˜,Ó'×0Ñ0°Ó8Ð8ð �6‰6�=‰=˜Ÿ™Ó€DÜ §¡´°\Ó1BÔC€IØFGÇhÂhÓOÁhÀŒb�jŠj˜Ô-×4Ñ4°Q·U±UÖ;Áh€FÐOØ�1„}Ü—’˜v a�yÓ)ˆØ�´E¸9¸*Àq½.Ô4IÓJÑ4I¨qŸ[™[ž]Ñ4IÑJÕJÈVÕSˆô ˜V§V¡V G HÐ-¨q¯w©wÖ7‰ˆˆIØ
ˆi�Šñ 8ô
 (+¨6·6±6°'°(Ð+;¸Q¿X¹XÔ'FôHÙ'F™G˜B ð Ÿ™ B¨¯©Ó.°Õ4×;Ñ;Ö=Ù'FòH€F�F‰Fˆ7ˆ8Ðð �L‰L˜˜QŸU™UÓ# a§f¡fÕ,×3Ñ3Ó5€Dá�tœU 6›]Ð+°<Ô@×IÑIÈ&ÓQÐQùò! Pùò KùóHs   Ï9U*Ð9U/Ò==U4c                ó2  € \        V \        4      '       g   \        V\        4      '       d   \        p\        pM\        p\
        pV! V 4      p V! V4      pV P                  ^8w  d   \        RV P                   R24      hVP                  ^8w  d   \        RVP                   R24      hV P                  ^ ,          V P                  ^,          8w  d   \        R4      hVP                  ^ ,          VP                  ^,          8w  d   \        R4      h\        V P                  VP                  4      pV! V P                  ^ ,          VR7      pV! VP                  ^ ,          VR7      p\        WpRR7      p\        WRR7      p	W‰,           P                  V4      # )	au  Kronecker sum of square sparse matrices `A` and `B`

Kronecker sum of two sparse matrices is a sum of two Kronecker
products ``kron(I_n,A) + kron(B,I_m)`` where `A` has shape ``(m, m)``
and `B` has shape ``(n, n)`` and ``I_m`` and ``I_n`` are identity matrices
of shape ``(m, m)`` and ``(n, n)``, respectively.

Parameters
----------
A : sparse matrix or array
    Square matrix
B : sparse array or array
    Square matrix
format : str
    format of the result (e.g. "csr")

Returns
-------
sparse matrix or array
    kronecker sum in a sparse format. Returns a sparse matrix unless either
    `A` or `B` is a sparse array in which case returns a sparse array.

Examples
--------
`kronsum` can be used to construct a finite difference discretization of the 2D
Laplacian from a 1D discretization.

>>> from scipy.sparse import diags_array, kronsum
>>> from matplotlib import pyplot as plt
>>> import numpy as np
>>> ex = np.ones(10)
>>> D_x = diags_array([ex, -ex[1:]], offsets=[0, -1])  # 1D first derivative
>>> D_xx = D_x.T @ D_x  # 1D second derivative
>>> L = kronsum(D_xx, D_xx)  # 2D Laplacian
>>> plt.spy(L.toarray())
>>> plt.show()

z#kronsum requires 2D inputs. `A` is zD.z#kronsum requires 2D inputs. `B` is zA is not squarezB is not squarerb   r   )r&   )rK   r   r   r�   r   r‹   r   r   r$   r   rN   rÀ   rW   )
r(   rµ   r&   rš   Úidentity_sparserN   ÚI_nÚI_mÚLÚRs
   &&&       r,   ÚkronsumrÇ   K  s;  € ôP �!”W×Ò¤¨A¬w×!7Ò!7äˆ
Ü#‰äˆ
Ü"ˆá�1‹€AÙ�1‹€Aà‡v�v�„{ÜÐ>¸q¿v¹v¸hÀbÐIÓJÐJØ‡v�v�„{ÜÐ>¸q¿v¹v¸hÀbÐIÓJÐJØ‡w�wˆq…z�Q—W‘W˜Q•ZÔÜÐ*Ó+Ð+Ø‡w�wˆq…z�Q—W‘W˜Q•ZÔÜÐ*Ó+Ð+ä�1—7‘7˜AŸG™GÓ$€Eá
˜!Ÿ'™' !�*¨EÔ
2€CÙ
˜!Ÿ'™' !�*¨EÔ
2€CÜˆS˜EÔ"€AÜˆQ˜EÔ"€Aà�E×Ñ˜FÓ#Ð#r.   c                ó‚  a€ S^ 8X  d   ^M^ p\         P                  ! V  Uu. uF  qDP                  NK  	  up4      pV ^ ,          P                  V,          p\	        V  Uu. uF  qDP
                  NK  	  up\        VP                  V4      R7      p\         P                  ! VP                  VR7      p\         P                  ! \        V3R lV  4       4      ^,           VR7      p	V! ^ 4      p
^ p^ pV  Fç  pVP                  V,          V8w  d   \        RV 24      hVP                  WŒWÄP                  P                  ,           % WÄP                  P                  ,          p\        W»VP                  S,          ,           4      pVP
                  RR W�&   W�;;,          V
,          uu&   W´P                  S,          ,          pW¤P
                  R,          ,          p
Ké  	  W©R&   V'       d(   S^ 8X  d   \        WXV	3W¶3R7      # \        WXV	3Wk3R7      # S^ 8X  d   \        WXV	3W¶3R7      # \!        WXV	3Wk3R7      # u upi u upi )z\
Stacking fast path for CSR/CSC matrices or arrays
(i) vstack for CSR, (ii) hstack for CSC.
)Úarraysr•   rb   c              3   óH   <"  € T F  qP                   S,          x € K  	  R # 5ir@   ©Ú_shape_as_2d©rC   r¨   r   s   & €r,   rD   Ú+_compressed_sparse_stack.<locals>.<genexpr>œ  s   øé € Ð?¹°1Ÿ.™.¨×.Ò.»ùó   ƒ"z!incompatible dimensions for axis NrA   rH   )r!   ÚconcatenaterX   rÌ   r   r�   ru   r°   ÚemptyÚsumr   rž   Úslicer   r   r   r   )Úblocksr   Úreturn_spmatrixÚ
other_axisr¨   rX   Úconstant_dimrœ   rž   r�   Úlast_indptrÚsum_dimÚsum_indicesÚidxss   &f&           r,   Ú_compressed_sparse_stackrÜ   ‘  sö  ø€ ð
 ˜a”i‘ Q€JÜ�>Š>©6Ó2©6 aŸ6œ6©6Ñ2Ó3€DØ˜!•9×)Ñ)¨*Õ5€LÜ¹&Ó'A¹&°Q¯¬¹&Ñ'AÜ'*¨4¯9©9°lÓ'CôE€Iä�hŠh�t—y‘y¨	Ô2€GÜ�XŠX”cÔ?¹Ó?Ó?À!ÕCÈ9ÔU€FÙ˜A“,€KØ€GØ€KÛˆØ�>‰>˜*Õ%¨Ô5ÜÐ@ÀÀÐMÓNÐNØ:;¿)¹)ˆ˜K¯	©	¯©Õ6Ð7Ø—y‘y—~‘~Õ%ˆÜ�W¨¯©°tÕ(<Õ<Ó=ˆØ—x‘x  �}ˆ‰Ø�˜Õ#‹Ø—>‘> $Õ'Õ'ˆØ—x‘x •|Õ#Šñ ð ˆ2�JçØ�1Œ9Ü˜t¨fÐ5Ø%,Ð$;ô=ð =ô ˜t¨fÐ5Ø%1Ð$;ô=ð =ð ˆq„yÜ˜$¨Ð0Ø!(Ð 7ô9ð 	9ô ˜$¨Ð0Ø!-Ð 7ô9ð 	9ùòC 3ùâ'As   ¡H7ÁH<c                ób  a€ \        V 4      pV^ 8X  d   \        R4      hV^8X  d
   V ^ ,          # S^ 8X  d   ^M^ pV  Uu0 uF  qDP                  V,          kK  	  pp\        V4      ^8”  d   \        RV RV 24      hVw  pV  Uu. uF  qDP                  NK  	  pp\        P
                  ! V  Uu. uF  qDP                  NK  	  up4      p\        V3R lV  4       4      p	\        R V  4       4      p
\        V\        V	^,
          V
4      R7      p\        P                  ! V  Uu. uF  qDP                  S,          NK  	  upVR7      pVP                  ^ 8”  d¦   \        P
                  ! W{R7      p\        P
                  ! V  Uu. uF  qDP                  NK  	  upVR7      p\        P                  ! V^,           VR7      p\        P                  ! V4      p\        P                  ! V4      p\        W&VWÞVVVV4	       MY\        P                   ! V^,           VR7      p\        P                  ! ^ VR7      p\        P                  ! ^ VP"                  R7      pS^ 8X  d   V ^ ,          P%                  VVV3W–3R7      # V ^ ,          P'                  VVV3Wi3R7      # u upi u upi u upi u upi u upi )	zg
Stacking fast path for CSR/CSC matrices along the minor axis
(i) hstack for CSR, (ii) vstack for CSC.
zMissing block matricesz"Mismatching dimensions along axis rc   c              3   óH   <"  € T F  qP                   S,          x € K  	  R # 5ir@   rË   rÍ   s   & €r,   rD   Ú*_stack_along_minor_axis.<locals>.<genexpr>Ú  s   øé € Ð7±¨1—.‘. ×&Ò&³ùrÏ   c              3   óL   "  € T F  p\        VP                  4      x € K  	  R # 5ir@   )rJ   rž   ©rC   r¨   s   & r,   rD   rß   Û  s   é € Ð-¡f Œc�!—)‘)�nˆn£fùs   ‚"$r”   rb   rA   )rJ   r   rÌ   r�   r!   rÐ   rX   rÒ   r   ru   Úarrayr°   rž   rÑ   Ú
empty_liker
   rw   rN   Ú_csc_containerÚ_csr_container)rÔ   r   Ún_blocksrÖ   r¨   Úother_axis_dimsr×   Úindptr_listÚdata_catrÙ   rª   rœ   Ústack_dim_catÚ
indptr_catÚindices_catr�   rž   rX   s   &f                r,   Ú_stack_along_minor_axisrí   ¼  sf  ø€ ô
 �6‹{€HØ�1„}ÜÐ1Ó2Ð2à�1„}Ø�a�yÐð ˜a”i‘ Q€JÙ;AÓB¹6°a—~‘~ j×1Ð1¹6€OÐBÜ
ˆ?Ó˜aÔÜÐ=¸j¸\ÈØ+Ð,ð.ó /ð 	/à#�M€Lñ &,Ó,¡V —8”8¡V€KÐ,Ü�~Š~©vÓ6©v¨!Ÿvœv©vÑ6Ó7€Hô Ô7±Ó7Ó7€GÜ
Ñ-¡fÓ-Ó
-€CÜ ´C¸À!½ÀSÓ4IÔJ€IÜ—H’H¹FÓC¹F°qŸn™n¨T×2Ð2¹FÑCÈ9ÔU€MØ‡}�}�qÔÜ—^’^ KÔAˆ
Ü—n’n¹Ó%@¹°A§i¤i¹Ñ%@È	ÔRˆÜ—’˜,¨Õ*°)Ô<ˆÜ—-’- Ó,ˆÜ�}Š}˜XÓ&ˆÜ�8¨=Ø¨HØ˜7 Dõ	*ô —’˜,¨Õ*°)Ô<ˆÜ—(’(˜1 IÔ.ˆÜ�xŠx˜ §¡Ô0ˆàˆq„yØ�a�y×'Ñ'¨¨w¸Ð(?Ø!(Ð 7ð (ó 9ð 	9ð �a�y×'Ñ'¨¨w¸Ð(?Ø!-Ð 7ð (ó 9ð 	9ùòM Cùò -ùÚ6ùò Dùò &As   ¾JÂJÂ.J"Ä"J'ÆJ,c                ó  € \         P                  ! V RR7      p \        ;QJ d&    R V P                   4       F  '       g   K   RM	  RM! R V P                   4       4      '       d   \	        V .W4      # \	        V .WRR7      # )a  
Stack sparse matrices horizontally (column wise)

Parameters
----------
blocks
    sequence of sparse matrices with compatible shapes
format : str
    sparse format of the result (e.g., "csr")
    by default an appropriate sparse matrix format is returned.
    This choice is subject to change.
dtype : dtype, optional
    The data-type of the output matrix. If not given, the dtype is
    determined from that of `blocks`.

Returns
-------
new_array : sparse matrix or array
    If any block in blocks is a sparse array, return a sparse array.
    Otherwise return a sparse matrix.

    If you want a sparse array built from blocks that are not sparse
    arrays, use ``block(hstack(blocks))`` or convert one block
    e.g. ``blocks[0] = csr_array(blocks[0])``.

See Also
--------
vstack : stack sparse matrices vertically (row wise)

Examples
--------
>>> from scipy.sparse import coo_matrix, hstack
>>> A = coo_matrix([[1, 2], [3, 4]])
>>> B = coo_matrix([[5], [6]])
>>> hstack([A,B]).toarray()
array([[1, 2, 5],
       [3, 4, 6]])

Úobjectrb   c              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5ir@   ©rK   r   rá   s   & r,   rD   Úhstack.<locals>.<genexpr>  ó   é € Ð
7©; aŒ:�aœ×!Ð!«;ùó   ‚TF©rÕ   ©r!   r³   ÚanyÚflatÚ_block©rÔ   r&   rN   s   &&&r,   Úhstackrû   ô  s^   € ôP �ZŠZ˜ hÔ/€Fß
ƒsÑ
7¨6¯;ª;Ó
7‡s‡s‚sÑ
7¨6¯;ª;Ó
7×7Ò7Ü�v�h Ó.Ð.ä�v�h ¸tÔDÐDr.   c                óV  € \         P                  ! V RR7      p \        ;QJ d&    R V P                   4       F  '       g   K   RM	  RM! R V P                   4       4      '       d   \	        V  Uu. uF  q3.NK  	  upW4      # \	        V  Uu. uF  q3.NK  	  upWRR7      # u upi u upi )a  
Stack sparse arrays vertically (row wise)

Parameters
----------
blocks
    sequence of sparse arrays with compatible shapes
format : str, optional
    sparse format of the result (e.g., "csr")
    by default an appropriate sparse array format is returned.
    This choice is subject to change.
dtype : dtype, optional
    The data-type of the output array. If not given, the dtype is
    determined from that of `blocks`.

Returns
-------
new_array : sparse matrix or array
    If any block in blocks is a sparse array, return a sparse array.
    Otherwise return a sparse matrix.

    If you want a sparse array built from blocks that are not sparse
    arrays, use ``block(vstack(blocks))`` or convert one block
    e.g. ``blocks[0] = csr_array(blocks[0])``.

See Also
--------
hstack : stack sparse matrices horizontally (column wise)

Examples
--------
>>> from scipy.sparse import coo_array, vstack
>>> A = coo_array([[1, 2], [3, 4]])
>>> B = coo_array([[5, 6]])
>>> vstack([A, B]).toarray()
array([[1, 2],
       [3, 4],
       [5, 6]])

rï   rb   c              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5ir@   rñ   rá   s   & r,   rD   Úvstack.<locals>.<genexpr>M  ró   rô   TFrõ   rö   )rÔ   r&   rN   r¨   s   &&& r,   Úvstackrÿ   #  s€   € ôR �ZŠZ˜ hÔ/€Fß
ƒsÑ
7¨6¯;ª;Ó
7‡s‡s‚sÑ
7¨6¯;ª;Ó
7×7Ò7Ü¡FÓ+¡F˜q“s¡FÑ+¨VÓ;Ð;ä¡FÓ+¡F˜q“s¡FÑ+¨VÈDÔQÐQùò ,ùâ+s   Á0B!ÂB&c                ó  € \         P                  ! V RR7      p \        ;QJ d&    R V P                   4       F  '       g   K   RM	  RM! R V P                   4       4      '       d   \	        WV4      # \	        WVRR7      # )a  
Build a sparse array or matrix from sparse sub-blocks

Note: `block_array` is preferred over ``bmat``. They are the same function
except that ``bmat`` returns a deprecated sparse matrix when none of the
inputs are sparse arrays.

.. warning::

    This function returns a sparse matrix when no inputs are sparse arrays.
    You are encouraged to use `block_array` to take advantage
    of the sparse array functionality.

Parameters
----------
blocks : array_like
    Grid of sparse matrices with compatible shapes.
    An entry of None implies an all-zero matrix.
format : {'bsr', 'coo', 'csc', 'csr', 'dia', 'dok', 'lil'}, optional
    The sparse format of the result (e.g. "csr"). By default an
    appropriate sparse matrix format is returned.
    This choice is subject to change.
dtype : dtype, optional
    The data-type of the output matrix. If not given, the dtype is
    determined from that of `blocks`.

Returns
-------
bmat : sparse matrix or array
    If any block in blocks is a sparse array, return a sparse array.
    Otherwise return a sparse matrix.

    If you want a sparse array built from blocks that are not sparse
    arrays, use ``block_array()``.

See Also
--------
block_array

Examples
--------
>>> from scipy.sparse import coo_array, bmat
>>> A = coo_array([[1, 2], [3, 4]])
>>> B = coo_array([[5], [6]])
>>> C = coo_array([[7]])
>>> bmat([[A, B], [None, C]]).toarray()
array([[1, 2, 5],
       [3, 4, 6],
       [0, 0, 7]])

>>> bmat([[A, None], [None, C]]).toarray()
array([[1, 2, 0],
       [3, 4, 0],
       [0, 0, 7]])

rï   rb   c              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5ir@   rñ   rá   s   & r,   rD   Úbmat.<locals>.<genexpr>�  ró   rô   TFrõ   rö   rú   s   &&&r,   Úbmatr  S  sZ   € ôr �ZŠZ˜ hÔ/€Fß
ƒsÑ
7¨6¯;ª;Ó
7‡s‡s‚sÑ
7¨6¯;ª;Ó
7×7Ò7Ü�f eÓ,Ð,ä�f e¸TÔBÐBr.   c               ó   € \        WV4      # )a#  
Build a sparse array from sparse sub-blocks

Parameters
----------
blocks : array_like
    Grid of sparse arrays with compatible shapes.
    An entry of None implies an all-zero array.
format : {'bsr', 'coo', 'csc', 'csr', 'dia', 'dok', 'lil'}, optional
    The sparse format of the result (e.g. "csr"). By default an
    appropriate sparse array format is returned.
    This choice is subject to change.
dtype : dtype, optional
    The data-type of the output array. If not given, the dtype is
    determined from that of `blocks`.

Returns
-------
block : sparse array

See Also
--------
block_diag : specify blocks along the main diagonals
diags : specify (possibly offset) diagonals

Examples
--------
>>> from scipy.sparse import coo_array, block_array
>>> A = coo_array([[1, 2], [3, 4]])
>>> B = coo_array([[5], [6]])
>>> C = coo_array([[7]])
>>> block_array([[A, B], [None, C]]).toarray()
array([[1, 2, 5],
       [3, 4, 6],
       [0, 0, 7]])

>>> block_array([[A, None], [None, C]]).toarray()
array([[1, 2, 0],
       [3, 4, 0],
       [0, 0, 7]])

)rù   rú   s   &$$r,   Úblock_arrayr  “  s   € ôV �& %Ó(Ð(r.   c                 ó  € \         P                  ! V R R7      p V P                  ^8w  d   \        R4      hV P                  w  rEVR9   dÈ   \
        ;QJ d&    R V P                   4       F  '       d   K   RM	  RM! R V P                   4       4      '       dz   V^8”  dF   \        V4       Uu. uF  p\        WR3,          ^4      .NK  	  p p\         P                  ! V R R7      p \        V R,          ^ V4      pVe   VP                  VRR7      pV# VR9   dÊ   \
        ;QJ d&    R	 V P                   4       F  '       d   K   RM	  RM! R	 V P                   4       4      '       d|   V^8”  dH   \        V4       Uu. uF  p\        V RV3,          ^ 4      NK  	  up.p \         P                  ! V R R7      p \        V R,          ^V4      pVe   VP                  VRR7      pV# \         P                  ! V P                  \        R7      p\         P                  ! V\         P                  R7      p	\         P                  ! V\         P                  R7      p
\        V4       EF.  p\        V4       EF  pWV3,          f   K  \        WV3,          4      pWpW¼3&   RW‹V3&   W›,          ^ 8X  d   VP                  ^ ,          W›&   MRW›,          VP                  ^ ,          8w  d5   R
V RV RV RVP                  ^ ,           RW›,           R2p\        V4      hW¬,          ^ 8X  d   VP                  ^,          W¬&   KÉ  W¬,          VP                  ^,          8w  g   Ké  RV RV RV RVP                  ^,           RW¬,           R2p\        V4      h	  EK1  	  \!        R W,           4       4      pVf4   W,           Uu. uF  qÿP"                  NK  	  ppV'       d
   \%        V!  MRp\         P&                  ! ^ \         P(                  ! V	4      4      p\         P&                  ! ^ \         P(                  ! V
4      4      pVR,          VR,          3p\         P*                  ! WâR7      p\-        W,           Uu. uF  qfP.                  ^ ,          NK  	  up\1        V4      R7      p\         P*                  ! VVR7      p\         P*                  ! VVR7      p^ p\         P2                  ! V4      w  pp\5        VV4       F±  w  r¼WV3,          p\7        WîVP8                  ,           4      pVP:                  VV&   \         P<                  ! VP>                  VV,          VV,          VR7       \         P<                  ! VP@                  VV,          VV,          VR7       VVP8                  ,          pK³  	  V'       d!   \C        VVV33VR7      PE                  V4      # \        VVV33VR7      PE                  V4      # u upi u upi u upi u upi )rï   rb   zblocks must be 2-DNc              3   óf   "  € T F'  p\        V4      ;'       d    VP                  R 8H  x € K)  	  R# 5i)r’   N©r   r&   rá   s   & r,   rD   Ú_block.<locals>.<genexpr>Ë  s(   é € ÐC±{°!ŒH�Q‹K×-Ð-˜AŸH™H¨Ñ-Ô-³{ùó   ‚1™1FTºNNNr   c              3   óf   "  € T F'  p\        V4      ;'       d    VP                  R 8H  x € K)  	  R# 5i)r“   Nr  rá   s   & r,   rD   r	  Ø  s(   é € ÐE¹°AŒh�q‹k×/Ð/˜aŸh™h¨%Ñ/Ô/»ùr
  zblocks[z0,:] has incompatible row dimensions. Got blocks[Ú,z].shape[0] == z, expected Ú.z	blocks[:,z1] has incompatible column dimensions. Got blocks[z].shape[1] == c              3   ó8   "  € T F  qP                   x € K  	  R # 5ir@   )rª   )rC   Úblocks   & r,   rD   r	    s   é € Ð8Ñ%7˜E�iŽiÓ%7ùs   ‚r”   )ÚoutrN   rA   )Nr’   )r  é    )Nr“   )r  r  rH   )#r!   r³   r   r   r$   Úallrø   rI   rí   rÜ   Úastyperw   ÚboolÚint64r   rÌ   rÒ   rN   r   rR   ÚcumsumrÑ   r   r#   ru   Únonzeror²   rÓ   rª   rX   Úaddr    r¡   r   rW   )rÔ   r&   rN   rÕ   r~   ÚNr¨   r(   Ú
block_maskÚbrow_lengthsÚbcol_lengthsÚir�   r;   rª   ÚblkÚ
all_dtypesÚrow_offsetsÚcol_offsetsr$   rX   rœ   r    r¡   ÚiiÚjjrµ   r)   s   &&&&                        r,   rù   rù   Á  sÖ  € Ü�ZŠZ˜ hÔ/€Fà‡{�{�aÔÜÐ-Ó.Ð.à
�,‰,�C€Að 	�-Ôß‹ÑC°v·{²{ÓC��ŠÑC°v·{²{ÓC×CÒCàˆqŒ5äJOÐPQÌ(ÓSÉ(ÀQÔ.¨v¸°d­|¸QÓ?Ó@É(ˆFÐSÜ—Z’Z ¨hÔ7ˆFô % V¨D¥\°1°oÓFˆØÒØ—‘˜ U�Ó+ˆAØˆØ
�MÔ
!ß
‹#ÑE¸¿ºÓE�#�#Š#ÑE¸¿ºÓE×
EÒ
EàˆqŒ5äINÈqÌÓRÉÀAÔ.¨v°a¸°d­|¸QÖ?ÉÑRÐSˆFÜ—Z’Z ¨hÔ7ˆFô % V¨D¥\°1°oÓFˆØÒØ—‘˜ U�Ó+ˆAØˆä—’˜&Ÿ,™,¬dÔ3€JÜ—8’8˜A¤R§X¡XÔ.€LÜ—8’8˜A¤R§X¡XÔ.€Lô �1�XˆÜ�q—ˆAØ˜�c�{Ô&Ü˜f q S�kÓ*�Ø�q�s‘Ø"&�
˜Q˜3‘à•? aÔ'Ø&'§n¡n°QÕ&7�L’OØ!•_¨¯©°qÕ(9Ô9Ø$ Q Cð ()Ø)*¨¨1¨Q¨C¨~¸a¿n¹nÈQÕ>OÐ=Pð Q'Ø'3¥Ð&7°qð:�Cô % S›/Ð)à•? aÔ'Ø&'§n¡n°QÕ&7�L“OØ!•_¨¯©°qÕ(9Ö9Ø& q cð *)à)*¨¨1¨Q¨C¨~¸a¿n¹nÈQÕ>OÐ=Pð Q'Ø'3¥Ð&7°qð:�Cô % S›/Ð)ô+ ñ ô0 Ñ8 VÖ%7Ó8Ó
8€CØ‚}Ø+1Ö+=Ó>Ñ+= C—i”iÑ+=ˆ
Ð>ß'1”˜
Ò#°tˆä—)’)˜AœrŸyšy¨Ó6Ó7€KÜ—)’)˜AœrŸyšy¨Ó6Ó7€Kà˜�_˜k¨"�oÐ.€Eä�8Š8�CÔ%€DÜ°fÖ6HÓ IÑ6H°§¡¨!§ Ñ6HÑ IÜ'*¨5£zô3€Iä
�(Š(�3˜iÔ
(€CÜ
�(Š(�3˜iÔ
(€Cà
€CÜ�ZŠZ˜
Ó#�F€BˆÜ�B˜–‰ˆØ�a�4�LˆÜ�C˜qŸu™u�Ó%ˆØ—F‘FˆˆS‰	Ü
�Šˆq�u‰u�k !•n¨#¨c­(¸)ÕDÜ
�Šˆq�u‰u�k !•n¨#¨c­(¸)ÕDØˆq�u‰u�Šñ ÷ Ü˜4 # s Ð,°EÔ:×CÑCÀFÓKÐKÜ�d˜S #˜JÐ'¨uÔ5×>Ñ>¸vÓFÐFùò_ Tùò SùòP ?ùò !Js   Â,W/Å:W4Î7W9Ñ.W>c                óT  € \         ;QJ d    R V  4       F  '       g   K   RM	  RM! R V  4       4      '       d   \        pM\        p. p. p. p. p^ p^ p	V  EFÕ  p
\        V
\        \
        P                  ,          4      '       d    \        \        P                  ! V
4      4      p
\        V
4      '       dÙ   V
P                  4       p
V'       gS   V
P                  ^ ,          P                  \        P                  8X  d#   VP                  V
P                  ^ ,          4       V
P                  w  r¼VP                  V
P                   V,           4       VP                  V
P"                  V	,           4       VP                  V
P$                  4       MŽV
P&                  w  r¼\        P(                  ! \        P*                  ! W¼,          4      V4      w  rÞVP                  WØ,           4       VP                  Wé,           4       VP                  V
P-                  4       4       W‹,          pWœ,          p	EKØ  	  \/        V\1        W‰4      R7      p\        P2                  ! WOR7      p\        P2                  ! W_R7      p\        P2                  ! V4      pW‰3pV! WdV33VVR7      P5                  V4      # )aÒ  
Build a block diagonal sparse matrix or array from provided matrices.

Parameters
----------
mats : sequence of matrices or arrays
    Input matrices or arrays.
format : str, optional
    The sparse format of the result (e.g., "csr"). If not given, the result
    is returned in "coo" format.
dtype : dtype specifier, optional
    The data-type of the output. If not given, the dtype is
    determined from that of `blocks`.

Returns
-------
res : sparse matrix or array
    If at least one input is a sparse array, the output is a sparse array.
    Otherwise the output is a sparse matrix.

Notes
-----

.. versionadded:: 0.11.0

See Also
--------
block_array
diags_array

Examples
--------
>>> from scipy.sparse import coo_array, block_diag
>>> A = coo_array([[1, 2], [3, 4]])
>>> B = coo_array([[5], [6]])
>>> C = coo_array([[7]])
>>> block_diag((A, B, C)).toarray()
array([[1, 2, 0, 0],
       [3, 4, 0, 0],
       [0, 0, 5, 0],
       [0, 0, 6, 0],
       [0, 0, 0, 7]])

c              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5ir@   rñ   )rC   r§   s   & r,   rD   Úblock_diag.<locals>.<genexpr>N  s   é € Ð
0©4 aŒ:�aœ×!Ð!«4ùrô   TFr”   rb   )r$   rN   )r÷   r   r   rK   rL   ÚnumbersÚNumberr!   Ú
atleast_2dr   r    r#   rN   r  rR   rÌ   r    r¡   rX   r$   Údivmodr1   r´   r   ru   rÐ   rW   )Úmatsr&   rN   Ú	containerr    r¡   rX   Ú
idx_arraysÚr_idxÚc_idxr§   ÚnrowsÚncolsÚa_rowÚa_colrœ   Ú	new_shapes   &&&              r,   Ú
block_diagr6  !  sÔ  € ÷Z ƒsÑ
0©4Ó
0‡s‡s‚sÑ
0©4Ó
0×0Ò0Ü‰	äˆ	à
€CØ
€CØ€DØ€JØ€EØ€EÜˆÜ�aœ$¤§¡Õ/×1Ò1Üœ"Ÿ-š-¨Ó*Ó+ˆAÜ�A�;Š;Ø—‘“	ˆAß !§(¡(¨1¥+×"3Ñ"3´r·x±xÔ"?Ø×!Ñ! !§(¡(¨1¥+Ô.ØŸ>™>‰LˆEØ�J‰J�q—u‘u˜u•}Ô%Ø�J‰J�q—u‘u˜u•}Ô%Ø�K‰K˜Ÿ™ÕàŸ7™7‰LˆEÜŸ9š9¤R§Y¢Y¨u­{Ó%;¸UÓC‰LˆEØ�J‰J�u•}Ô%Ø�J‰J�u•}Ô%Ø�K‰K˜Ÿ™›	Ô"Ø�ˆØ�‹ñ% ô&   
´3°uÓ3DÔE€IÜ
�.Š.˜Ô
.€CÜ
�.Š.˜Ô
.€CÜ�>Š>˜$Ó€DØ�€Iá�d #˜JÐ'¨yÀÔF×OÑOÐPVÓWÐWr.   Úrandom_stateÚdensityç{®Gáz„?r   ÚrngÚdata_samplerc               óê   a€ \        WW#WE4      w  rg\        \        V 4      R7      o\        ;QJ d    . V3R lV 4       F  NK  	  5M! V3R lV 4       4      p\	        Wg3V R7      P                  V4      # )a   Return a sparse array of uniformly random numbers in [0, 1)

Returns a sparse array with the given shape and density
where values are generated uniformly randomly in the range [0, 1).

Parameters
----------
shape : tuple of int
    shape of the array.
density : real, optional (default: 0.01)
    density of the generated matrix: density equal to one means a full
    matrix, density of 0 means a matrix with no non-zero items.
format : str, optional (default: 'coo')
    sparse matrix format.
dtype : dtype, optional (default: np.float64)
    type of the returned matrix values.
rng : `numpy.random.Generator`, optional
    Pseudorandom number generator state. When `rng` is None, a new
    `numpy.random.Generator` is created using entropy from the
    operating system. Types other than `numpy.random.Generator` are
    passed to `numpy.random.default_rng` to instantiate a ``Generator``.

    This random state will be used for sampling ``indices`` (the sparsity
    structure), and by default for the data values too (see `data_sampler`).
data_sampler : callable, optional (default depends on dtype)
    Sampler of random data values with keyword arg ``size``.
    This function should take a single keyword argument ``size`` specifying
    the length of its returned ndarray. It is used to generate the nonzero
    values in the matrix after the locations of those values are chosen.
    By default, uniform [0, 1) random values are used unless `dtype` is
    an integer (default uniform integers from that dtype) or
    complex (default uniform over the unit square in the complex plane).
    For these, the `rng` is used e.g. ``rng.uniform(size=size)``.

Returns
-------
res : sparse array

Examples
--------

Passing a ``np.random.Generator`` instance for better performance:

>>> import numpy as np
>>> import scipy as sp
>>> rng = np.random.default_rng()

Default sampling uniformly from [0, 1):

>>> S = sp.sparse.random_array((3, 4), density=0.25, rng=rng)

Providing a sampler for the values:

>>> rvs = sp.stats.poisson(25, loc=10).rvs
>>> S = sp.sparse.random_array((3, 4), density=0.25,
...                            rng=rng, data_sampler=rvs)
>>> S.toarray()
array([[ 36.,   0.,  33.,   0.],   # random
       [  0.,   0.,   0.,   0.],
       [  0.,   0.,  36.,   0.]])

Providing a sampler for uint values:

>>> def random_uint32_to_100(size=None):
...     return rng.integers(100, size=size, dtype=np.uint32)
>>> S = sp.sparse.random_array((3, 4), density=0.25, rng=rng,
...                            data_sampler=random_uint32_to_100)

Building a custom distribution.
This example builds a squared normal from np.random:

>>> def np_normal_squared(size=None, rng=rng):
...     return rng.standard_normal(size) ** 2
>>> S = sp.sparse.random_array((3, 4), density=0.25, rng=rng,
...                            data_sampler=np_normal_squared)

Or we can build it from sp.stats style rvs functions:

>>> def sp_stats_normal_squared(size=None, rng=rng):
...     std_normal = sp.stats.distributions.norm_gen().rvs
...     return std_normal(size=size, random_state=rng) ** 2
>>> S = sp.sparse.random_array((3, 4), density=0.25, rng=rng,
...                            data_sampler=sp_stats_normal_squared)

Or we can subclass sp.stats rv_continuous or rv_discrete:

>>> class NormalSquared(sp.stats.rv_continuous):
...     def _rvs(self,  size=None, random_state=rng):
...         return rng.standard_normal(size) ** 2
>>> X = NormalSquared()
>>> Y = X().rvs
>>> S = sp.sparse.random_array((3, 4), density=0.25,
...                            rng=rng, data_sampler=Y)
r”   c              3   óT   <"  € T F  p\         P                  ! VSR 7      x € K  	  R# 5i)rb   N©r!   r³   ©rC   r»   rœ   s   & €r,   rD   Úrandom_array.<locals>.<genexpr>Ú  s   øé € Ð>¹#°B”—
’
˜2 Y×/Ñ/»#ùs   ƒ%(rA   )Ú_randomr   ru   r6   r   rW   )	r$   r8  r&   rN   r:  r;  rX   Úindrœ   s	   &$$$$$  @r,   Úrandom_arrayrC  u  s^   ø€ ôB ˜¨°sÓI�I€Dô  ¤s¨5£zÔ2€Iß
Œ%Ô>¹#Ó>�%‰%Ô>¹#Ó>Ó
>€CÜ�d�[¨Ô.×7Ñ7¸Ó?Ð?r.   c                 óR  aaa€ V^ 8  g   V^8”  d   \        R4      h\        P                  ! V 4      p\        \	        W,          4      4      p\        S4      oVfr   \        P                  ! S\        P                  4      '       d	   VV3R lpM>\        P                  ! S\        P                  4      '       d   V3R lpMSP                  p\        \        V 4      R7      oV\        P                  ! \        P                  4      P                  8:  d_   SP                  WgRR7      p\        P                   ! W€RR7      p	\"        ;QJ d    . V3R	 lV	 4       F  NK  	  5M! V3R	 lV	 4       4      p	M™\%        V 4      p
\'        4       p\%        V4      V8  dA   V\%        V4      ,
          pVP)                  \+        \"        \-        SWV
3R
7      4      4       KP  \#        \        P.                  ! \1        V4      SR7      P2                  4      p	V! VR
7      P5                  SRR7      pWÙ3# )r  z(density expected to be 0 <= density <= 1c                 óœ   <€ \        S\        P                  ! S4      P                  \        P                  ! S4      P                  V SR 7      # )rb   )r   r!   Úiinforv   ru   )r°   rN   r:  s   &€€r,   r;  Ú_random.<locals>.data_samplerì  s:   ø€ Ü# CÜ$&§H¢H¨U£O×$7Ñ$7Ü$&§H¢H¨U£O×$7Ñ$7Ø$(Ø*/ô	1ð 1r.   c                 ód   <€ SP                  V R 7      SP                  V R 7      R,          ,           # )©r°   y              ð?)Úuniform)r°   r:  s   &€r,   r;  rG  ó  s.   ø€ ØŸ™¨˜Ó.ØŸ™¨˜Ó.°Õ3õ4ð 5r.   r”   F)r°   ÚreplaceÚF)r$   Úorderc              3   óR   <"  € T F  p\         P                  ! VS4      x € K  	  R # 5ir@   r>  r?  s   & €r,   rD   Ú_random.<locals>.<genexpr>þ  s   øé € Ð<¹°"”B—J’J˜r 9×-Ð-»ùs   ƒ$'rI  rb   r   )r   r«   r¬   ri   Úroundr   r!   rM   rP   ÚcomplexfloatingrJ  r   ru   rF  r  ÚchoiceÚunravel_indexr6   rJ   rS   Úupdaterg   r   râ   rL   ÚTr  )r$   r8  r&   rN   r:  r;  Útot_prodr°   Úraveled_indrB  r   ÚseenÚdsizeÚvalsrœ   s   &&&ff&        @r,   rA  rA  Þ  s‰  ú€ à�„{�g ”kÜÐCÓDÐDä�yŠy˜Ó€Hô Œu�WÕ'Ó(Ó)€Dä
˜SÓ
!€CàÒÜ�=Š=˜¤§
¡
×+Ò+÷1ô �]Š]˜5¤"×"4Ñ"4×5Ò5ö5ð Ÿ;™;ˆLä¤s¨5£zÔ2€Ià”2—8’8œBŸH™HÓ%×)Ñ)Ô)Ø—j‘j ¸e�jÓDˆÜ×Ò˜{¸sÔCˆßŒeÔ<¹Ó<�e‰eÔ<¹Ó<Ó<‰ô �5‹zˆÜ‹uˆÜ�$‹i˜$ÔØœ3˜t›9Õ$ˆEØ�K‰KœœE¤<°°UÈÀÔ#OÓPÖQÜ”B—H’HœT $›Z¨yÔ9×;Ñ;Ó<ˆñ ˜TÔ"×)Ñ)¨%°eÐ)Ó<€DØˆ9Ðr.   )Úposition_numc                ó²   a€ Vf   T p\        V 4      \        V4      rSe   V3R lpMRp\        W3W#WEV4      w  r‰\        W‰3W3R7      P                  V4      # )aU  Generate a sparse matrix of the given shape and density with randomly
distributed values.

.. warning::

    This function returns a sparse matrix -- not a sparse array.
    You are encouraged to use `random_array` to take advantage of the
    sparse array functionality.

Parameters
----------
m, n : int
    shape of the matrix
density : real, optional
    density of the generated matrix: density equal to one means a full
    matrix, density of 0 means a matrix with no non-zero items.
format : str, optional
    sparse matrix format.
dtype : dtype, optional
    type of the returned matrix values.
rng : `numpy.random.Generator`, optional
    Pseudorandom number generator state. When `rng` is None, a new
    `numpy.random.Generator` is created using entropy from the
    operating system. Types other than `numpy.random.Generator` are
    passed to `numpy.random.default_rng` to instantiate a ``Generator``.

    This random state will be used for sampling the sparsity structure, but
    not necessarily for sampling the values of the structurally nonzero
    entries of the matrix.
data_rvs : callable, optional
    Samples a requested number of random values.
    This function should take a single argument specifying the length
    of the ndarray that it will return. The structurally nonzero entries
    of the sparse random matrix will be taken from the array sampled
    by this function. By default, uniform [0, 1) random values will be
    sampled using the same random state as is used for sampling
    the sparsity structure.

Returns
-------
res : sparse matrix

See Also
--------
random_array : constructs sparse arrays instead of sparse matrices

Examples
--------

Passing a ``np.random.Generator`` instance for better performance:

>>> import scipy as sp
>>> import numpy as np
>>> rng = np.random.default_rng()
>>> S = sp.sparse.random(3, 4, density=0.25, rng=rng)

Providing a sampler for the values:

>>> rvs = sp.stats.poisson(25, loc=10).rvs
>>> S = sp.sparse.random(3, 4, density=0.25, rng=rng, data_rvs=rvs)
>>> S.toarray()
array([[ 36.,   0.,  33.,   0.],   # random
       [  0.,   0.,   0.,   0.],
       [  0.,   0.,  36.,   0.]])

Building a custom distribution.
This example builds a squared normal from np.random:

>>> def np_normal_squared(size=None, rng=rng):
...     return rng.standard_normal(size) ** 2
>>> S = sp.sparse.random(3, 4, density=0.25, rng=rng,
...                      data_rvs=np_normal_squared)

Or we can build it from sp.stats style rvs functions:

>>> def sp_stats_normal_squared(size=None, rng=rng):
...     std_normal = sp.stats.distributions.norm_gen().rvs
...     return std_normal(size=size, random_state=rng) ** 2
>>> S = sp.sparse.random(3, 4, density=0.25, rng=rng,
...                      data_rvs=sp_stats_normal_squared)

Or we can subclass sp.stats rv_continuous or rv_discrete:

>>> class NormalSquared(sp.stats.rv_continuous):
...     def _rvs(self,  size=None, random_state=rng):
...         return rng.standard_normal(size) ** 2
>>> X = NormalSquared()
>>> Y = X()  # get a frozen version of the distribution
>>> S = sp.sparse.random(3, 4, density=0.25, rng=rng, data_rvs=Y.rvs)
Nc                 ó   <€ S! V 4      # r@   r¦   )r°   Údata_rvss   &€r,   Údata_rvs_kwÚrandom.<locals>.data_rvs_kwo  s   ø€ Ù˜D“>Ð!r.   rA   )ri   rA  r   rW   )
rZ   r[   r8  r&   rN   r:  r^  r_  rZ  rB  s
   &&&&&&f   r,   Úrandomra    sa   ø€ ðz 	‚yØˆÜˆq‹6”3�q“6€qàÒö	"ð ˆÜ˜˜ °¸[ÓI�I€DÜ�t�k¨!¨Ô0×9Ñ9¸&ÓAÐAr.   c                ó   € \        WW#WE4      # )a,  Generate a sparse matrix of the given shape and density with uniformly
distributed values.

.. warning::

    This function returns a sparse matrix -- not a sparse array.
    You are encouraged to use `random_array` to take advantage
    of the sparse array functionality.

Parameters
----------
m, n : int
    shape of the matrix
density : real, optional
    density of the generated matrix: density equal to one means a full
    matrix, density of 0 means a matrix with no non-zero items.
format : str, optional
    sparse matrix format.
dtype : dtype, optional
    type of the returned matrix values.
rng : `numpy.random.Generator`, optional
    Pseudorandom number generator state. When `rng` is None, a new
    `numpy.random.Generator` is created using entropy from the
    operating system. Types other than `numpy.random.Generator` are
    passed to `numpy.random.default_rng` to instantiate a ``Generator``.

Returns
-------
res : sparse matrix

Notes
-----
Only float types are supported for now.

See Also
--------
random : Similar function allowing a custom random data sampler
random_array : Similar to random() but returns a sparse array

Examples
--------
>>> from scipy.sparse import rand
>>> matrix = rand(3, 4, density=0.25, format="csr", rng=42)
>>> matrix
<Compressed Sparse Row sparse matrix of dtype 'float64'
    with 3 stored elements and shape (3, 4)>
>>> matrix.toarray()
array([[0.05641158, 0.        , 0.        , 0.65088847],  # random
       [0.        , 0.        , 0.        , 0.14286682],
       [0.        , 0.        , 0.        , 0.        ]])

)ra  )rZ   r[   r8  r&   rN   r:  s   &&&&&&r,   Úrandrc  w  s   € ôl �!˜¨Ó4Ð4r.   )r\   rŠ   r‹   rÀ   rÇ   rû   rÿ   r  rc  ra  rY   r6  r†   r  r�   rC  r-   r7   r<   )NF)NNN)ÚdNr@   )T)NN)F)r9  NNNN)r9  r   NNN)r9  r   NN)BÚ__doc__Ú__docformat__Ú__all__r(  r«   rn   rl   rr   Únumpyr!   Úscipy._lib._utilr   r   r   Úscipy._lib.deprecationr   Ú_sputilsr   r   r   r	   Ú_sparsetoolsr
   Ú_bsrr   r   Ú_coor   r   Ú_cscr   r   Ú_csrr   r   Ú_diar   r   Ú_baser   r   r-   r<   r7   r\   r†   rY   r‹   Úfloatr�   rŽ   rŠ   rÀ   rÇ   rÜ   rí   rû   rÿ   r  r  rù   r6  rC  rA  ra  rc  r¦   r.   r,   Ú<module>rt     sÊ  ðñð &€ò6€ó
 Û Û 	Û 
Û Û ç QÑ QÝ +ß FÓ Få $ß 'ß 'ß 'ß 'ß 'ç $ð2˜aô 2òj+1ô\IôX?DðDiI¨ð iI°$ð iI¸tð iIÈ8ô iIðX  d°4¸xô c*ôL11ñh'(˜að '( uð '(°Tõ '(ôT"WðJ �Q˜e¨Dô //ôdpRôfC$òL(9òV59ôp,Eô^-Rô`=Cð@+) $ð +)¨dô +)ô\]Gô@QXñh �NÓ#ðe@ 4ð e@°ð e@¸Tð e@Øðe@Ø(,óe@ó $ðe@ôP,ñ^ �N°Ô3ófBó 4ðfBñR �N°Ô3ó55ó 4ò55r.   