Ë
    þ�Dj”:  ã                   ó*  — d Z ddlZddlmZmZmZmZ ddlZddlZ	ddl
mZ ddlmZ ddlmZmZ g d¢Ze	j&                  e	j(                  e	j*                  e	j,                  e	j.                  e	j0                  e	j2                  eee	j4                  e	j6                  e	j8                  e	j:                  e	j<                  e	j>                  e	j@                  e	jB                  gZ"i Z#d„ Z$d„ Z%d	„ Z&d
„ Z'd„ Z(d'd„Z)d(de	jT                  fd„Z+d)d„Z,de	jZ                  de	jZ                  fd„Z.de/fd„Z0de/fd„Z1d*ddœde/fd„Z2de/fd„Z3de/fd„Z4de/fd„Z5d+d„Z6d,ddœde7e8df   fd„Z9d„ Z:de/fd„Z;	 d,ded eed!      deed"f   fd#„Z<d$„ Z=d,d%„Z>de	jT                  fd&„Z?y)-z, Utility functions for sparse matrix module
é    N)ÚAnyÚLiteralÚOptionalÚUnion)Úprod)Únp_longÚnp_ulong)
ÚupcastÚgetdtypeÚgetdataÚisscalarlikeÚ	isintlikeÚisshapeÚ
issequenceÚisdenseÚismatrixÚget_sum_dtypec                  óô   — t         j                  t        | «      «      }|�|S t        j                  | Ž }t
        D ].  }t        j                  ||«      sŒ|t         t        | «      <   |c S  t        d| ›�«      ‚)aË  Returns the nearest supported sparse dtype for the
    combination of one or more types.

    upcast(t0, t1, ..., tn) -> T  where T is a supported dtype

    Examples
    --------
    >>> from scipy.sparse._sputils import upcast
    >>> upcast('int32')
    <type 'numpy.int32'>
    >>> upcast('bool')
    <type 'numpy.bool_'>
    >>> upcast('int32','float32')
    <type 'numpy.float64'>
    >>> upcast('bool',complex,float)
    <type 'numpy.complex128'>

    z#no supported conversion for types: )Ú_upcast_memoÚgetÚhashÚnpÚresult_typeÚsupported_dtypesÚcan_castÚ	TypeError)ÚargsÚtr
   s      úYC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\scipy/sparse/_sputils.pyr
   r
      su   € ô( 	×Ñœ˜d›Ó$€AØ€}Øˆä�^‰^˜TÐ"€Fäò ˆÜ�;‰;�v˜qÕ!Ø'(ŒLœ˜d›Ñ$ØŠHðô
 Ð9¸$¸ÐBÓ
CÐCó    c                  óŠ   — t         j                  | «      }|�|S t        t        t        j
                  | «      Ž }|t         | <   |S )z9Same as `upcast` but taking dtype.char as input (faster).)r   r   r
   Úmapr   Údtype)r   r   s     r   Úupcast_charr$   :   s@   € ä×Ñ˜Ó€AØ€}ØˆÜ””B—H‘H˜dÓ#Ð$€AØ„L�ÑØ€Hr    c                 óL   — t        j                  dg| ¬«      |z  j                  S )z`Determine data type for binary operation between an array of
    type `dtype` and a scalar.
    r   ©r#   )r   Úarrayr#   )r#   Úscalars     r   Úupcast_scalarr)   D   s"   € ô �H‰H�a�S Ô&¨Ñ/×6Ñ6Ð6r    c                 ó>  — | j                   j                  t        j                   t        j                  «      j                  kD  rØ| j                  dk(  r| j                  t        j                  «      S | j                  «       }| j                  «       }|t        j                  t        j                  «      j                  kD  s0|t        j                  t        j                  «      j                  k  rt        d«      ‚| j                  t        j                  «      S | S )zž
    Down-cast index array to np.intp dtype if it is of a larger dtype.

    Raise an error if the array contains a value that is too large for
    intp.
    r   zzCannot deal with arrays with indices larger than the machine maximum address size (e.g. 64-bit indices on 32-bit machine).)
r#   Úitemsizer   ÚintpÚsizeÚastypeÚmaxÚminÚiinfoÚ
ValueError)ÚarrÚmaxvalÚminvals      r   Údowncast_intp_indexr6   K   sÁ   € ð ‡y�y×ÑœBŸH™H¤R§W¡WÓ-×6Ñ6Ò6Ø�8‰8�qŠ=Ø—:‘:œbŸg™gÓ&Ð&Ø—‘“ˆØ—‘“ˆØ”B—H‘HœRŸW™WÓ%×)Ñ)Ò)¨V´b·h±h¼r¿w¹wÓ6G×6KÑ6KÒ-KÜð Hó Ið Ið �z‰zœ"Ÿ'™'Ó"Ð"Ø€Jr    c                 ó‚   — | j                   }|j                  r| S t        j                  | |j	                  d«      ¬«      S )a  
    Ensure that the data type of the NumPy array `A` has native byte order.

    `A` must be a NumPy array.  If the data type of `A` does not have native
    byte order, a copy of `A` with a native byte order is returned. Otherwise
    `A` is returned.
    Únativer&   )r#   Úisnativer   ÚasarrayÚnewbyteorder)ÚAÚdts     r   Ú	to_nativer>   _   s5   € ð 
�‰€BØ	‡{‚{ð ˆÜ�:‰:�a˜rŸ™¨xÓ8Ô9Ð9r    c                 ó  — | €	 |j                   }|S t        j                   | «      }|t        j                  k(  rt        d«      ‚|S # t        $ r/}|�t        j                   |«      }nt        d«      |‚Y d}~|S d}~ww xY w)aQ  Function used to simplify argument processing. If 'dtype' is not
    specified (is None), returns a.dtype; otherwise returns a np.dtype
    object created from the specified dtype argument. If 'dtype' and 'a'
    are both None, construct a data type out of the 'default' parameter.
    Furthermore, 'dtype' must be in 'allowed' set.
    Nzcould not interpret data typez0object dtype is not supported by sparse matrices)r#   ÚAttributeErrorr   r   Úobject_r2   )r#   ÚaÚdefaultÚnewdtypeÚes        r   r   r   o   s“   € ð €}ð	HØ—w‘wˆHð €Oô —8‘8˜E“?ˆØ”r—z‘zÒ!ÜØBóð ð €Oøô ò 	HØÐ"ÜŸ8™8 GÓ,‘äÐ ?Ó@ÀaÐGó ð €Oûð	Hús   „A Á	A?Á$A:Á:A?FÚreturnc                 ó`   — t        j                  | ||¬«      }t        |j                  «       |S )z‰
    This is a wrapper of `np.array(obj, dtype=dtype, copy=copy)`
    that will generate a warning if the result is an object array.
    )r#   Úcopy)r   r'   r   r#   )Úobjr#   rH   Údatas       r   r   r   ‰   s)   € ô
 �8‰8�C˜u¨4Ô0€Dô ˆT�Z‰ZÔØ€Kr    c                 óª  — t        j                  t        j                  t         j                  «      j                  «      }t        j                  t        j                  t         j                  «      j                  «      }t        j
                  «       j                  dk(  rt         j                  nt         j                  }|�*t        j                  |«      }||kD  rt         j                  }t        | t         j                  «      r| f} | D ]Ã  }t        j                  |«      }t        j                  |j                  t         j                  «      rŒG|ri|j                  dk(  rŒYt        j                  |j                  t         j                  «      r+|j	                  «       }|j                  «       }||k\  r||k  rŒ²t         j                  } |S  |S )a&  
    Based on input (integer) arrays `a`, determine a suitable index data
    type that can hold the data in the arrays.

    Parameters
    ----------
    arrays : tuple of array_like
        Input arrays whose types/contents to check
    maxval : float, optional
        Maximum value needed
    check_contents : bool, optional
        Whether to check the values in the arrays and not just their types.
        Default: False (check only the types)

    Returns
    -------
    dtype : dtype
        Suitable index data type (int32 or int64)

    é   r   )r   Úint32r1   r0   r/   Úintcr+   Úint64Ú
isinstanceÚndarrayr:   r   r#   r-   Ú
issubdtypeÚinteger)Úarraysr4   Úcheck_contentsÚint32minÚint32maxr#   r3   r5   s           r   Úget_index_dtyperX   •   s=  € ô, �x‰xœŸ™¤§¡Ó*×.Ñ.Ó/€HÜ�x‰xœŸ™¤§¡Ó*×.Ñ.Ó/€Hô Ÿ™›	×*Ñ*¨aÒ/ŒB�HŠH´R·X±X€EØÐÜ—‘˜&Ó!ˆØ�HÒÜ—H‘HˆEä�&œ"Ÿ*™*Ô%Ø�ˆàò ˆÜ�j‰j˜‹oˆÜ�{‰{˜3Ÿ9™9¤b§h¡hÕ/ÙØ—8‘8˜q’=àÜ—]‘] 3§9¡9¬b¯j©jÔ9Ø ŸW™W›Y�FØ ŸW™W›Y�FØ Ò)¨f¸Ò.@à ä—H‘HˆEØà€Lð#ð" €Lr    r#   c                 óô   — | j                   dk(  r4t        j                  | t        j                  «      rt        j                  S t        j                  | t        j                  «      rt        j                  S | S )z Mimic numpy's casting for np.sumÚu)Úkindr   r   ÚuintÚint_r&   s    r   r   r   Ì   sH   € à‡z�z�SÒœRŸ[™[¨´·±Ô8Ü�w‰wˆÜ	‡{�{�5œ"Ÿ'™'Ô"Ü�w‰wˆØ€Lr    c                 óh   — t        j                  | «      xs t        | «      xr | j                  dk(  S )z8Is x either a scalar, an array scalar, or a 0-dim array?r   )r   Úisscalarr   Úndim©Úxs    r   r   r   Õ   s&   € ä�;‰;�q‹>Ò9œg a›jÒ8¨Q¯V©V°q©[Ð9r    c                 ó  — t        j                  | «      dk7  ry	 t        j                  | «       y# t        t
        f$ rC 	 t        t        | «      | k(  «      }n# t        t
        f$ r Y Y yw xY w|rd}t        |«      ‚|cY S w xY w)zsIs x appropriate as an index into a sparse matrix? Returns True
    if it can be cast safely to a machine int.
    r   Fz4Inexact indices into sparse matrices are not allowedT)r   r`   ÚoperatorÚindexr   r2   ÚboolÚint)rb   Ú	loose_intÚmsgs      r   r   r   Ú   sˆ   € ô 
‡w�wˆqƒz�Q‚Øð
Ü�‰�qÔð øô ”zÐ"ò ð	ÜœS ›V q™[Ó)‰IøÜœ:Ð&ò 	Úð	úáØHˆCÜ˜S“/Ð!ØÒðús3   ›1 ±BÁAÁBÁA,Á(BÁ+A,Á,BÂB)Úallow_1dc                óp   — t        | «      }|dk7  r|r|dk(  sy| D ]  }t        |«      s y|sŒ|dk  sŒ y y)zžIs x a valid tuple of dimensions?

    If nonneg, also checks that the dimensions are non-negative.
    If allow_1d, shapes of length 1 or 2 are allowed.
    é   é   Fr   T)Úlenr   )rb   Únonnegrj   r`   Úds        r   r   r   ð   sI   € ô ˆq‹6€DØˆq‚y™( t¨q¢yØØò ˆÜ˜Œ|ÙÚ�a˜!“eÙð	ð
 r    c                 óÜ   — t        | t        t        f«      xr( t        | «      dk(  xs t	        j
                  | d   «      xs+ t        | t        j                  «      xr | j                  dk(  S )Nr   rm   )rP   ÚlistÚtuplern   r   r_   rQ   r`   ©r   s    r   r   r     sW   € Ü˜œD¤%˜=Ó)ò /Ü�‹V�q‰[Ò-œBŸK™K¨¨!©Ó-ò:ä˜œ2Ÿ:™:Ó&Ò8¨A¯F©F°a©Kð;r    c                 óÈ   — t        | t        t        f«      xr t        | «      dkD  xr t	        | d   «      xs+ t        | t
        j                  «      xr | j                  dk(  S )Nr   rl   )rP   rr   rs   rn   r   r   rQ   r`   rt   s    r   r   r     sV   € Ü˜œD¤%˜=Ó)ò -Ü�‹V�a‰Zò-Ü& q¨¡tÓ,ò8ä˜œ2Ÿ:™:Ó&Ò6¨1¯6©6°Q©;ð9r    c                 ó6   — t        | t        j                  «      S ©N)rP   r   rQ   ra   s    r   r   r     s   € Ü�aœŸ™Ó$Ð$r    c                 ó*  — | €y t        | «      }|t        k(  rt        d«      ‚t        j                  t        j
                  |«      t        j                  «      st        d|j                  › �«      ‚d| cxk  rdk  st        d«      ‚ t        d«      ‚y )NzlTuples are not accepted for the 'axis' parameter. Please pass in one of the following: {-2, -1, 0, 1, None}.zaxis must be an integer, not éþÿÿÿrm   zaxis out of range)	Útypers   r   r   rR   r#   rS   Ú__name__r2   )ÚaxisÚ	axis_types     r   Úvalidateaxisr~     s“   € Ø€|ØÜ�T“
€Ið ”EÒÜð 0ó 1ð 	1ô �=‰=œŸ™ )Ó,¬b¯j©jÔ9ÜÐ7¸	×8JÑ8JÐ7KÐLÓMÐMà�$ŒO˜!ŠOÜÐ,Ó-Ð-ð ÜÐ,Ó-Ð-ð r    .c                óØ  — t        | «      dk(  rt        d«      ‚t        | «      dk(  r"	 t        | d   «      }t        d„ |D «       «      }nt        d„ | D «       «      }|€P|rt        |«      dvr$t        d«      ‚t        |«      d	k7  rt        d
«      ‚t        d„ |D «       «      rït        d«      ‚t        |«      }t        |«      D ��cg c]  \  }}|dk  sŒ|‘Œ }}}|s+t        |«      }	|	|k7  r¤t        dj                  ||«      «      ‚t        |«      dk(  rp|d   }
t        |d|
 ||
dz   d z   «      }t        ||«      \  }}|dk7  r-t        d„ |D «       «      }t        dj                  ||«      «      ‚|d|
 |fz   ||
dz   d z   }nt        d«      ‚t        |«      d	k7  r|rt        |«      dk(  st        d«      ‚|S # t        $ r t	        j
                  | d   «      f}Y �Œ†w xY wc c}}w )au  Imitate numpy.matrix handling of shape arguments

    Parameters
    ----------
    args : array_like
        Data structures providing information about the shape of the sparse array.
    current_shape : tuple, optional
        The current shape of the sparse array or matrix.
        If None (default), the current shape will be inferred from args.
    allow_1d : bool, optional
        If True, then 1-D or 2-D arrays are accepted.
        If False (default), then only 2-D arrays are accepted and an error is
        raised otherwise.

    Returns
    -------
    new_shape: tuple
        The new shape after validation.
    r   z8function missing 1 required positional argument: 'shape'rm   c              3   óF   K  — | ]  }t        j                  |«      –— Œ y ­wrw   ©rd   re   ©Ú.0Úargs     r   ú	<genexpr>zcheck_shape.<locals>.<genexpr>E  s   è ø€ ÒH°cœhŸn™n¨S×1ÑHùó   ‚!c              3   óF   K  — | ]  }t        j                  |«      –— Œ y ­wrw   r�   r‚   s     r   r…   zcheck_shape.<locals>.<genexpr>G  s   è ø€ Ò>°#œ(Ÿ.™.¨×-Ñ>ùr†   N)rm   rl   z2shape must be a 1- or 2-tuple of positive integersrl   z,shape must be a 2-tuple of positive integersc              3   ó&   K  — | ]	  }|d k  –— Œ y­w)r   N© )rƒ   rp   s     r   r…   zcheck_shape.<locals>.<genexpr>P  s   è ø€ Ò(˜ˆq�1�uÑ(ùs   ‚z#'shape' elements cannot be negativez-cannot reshape array of size {} into shape {}c              3   ó.   K  — | ]  }|d k  rdn|–— Œ y­w)r   ÚnewshapeNr‰   )rƒ   rb   s     r   r…   zcheck_shape.<locals>.<genexpr>b  s   è ø€ Ò!PÀ°°A²¡*¸1Ó"<Ñ!Pùs   ‚z&can only specify one unknown dimensionz$matrix shape must be two-dimensional)rn   r   Úiterrs   rd   re   r2   Úanyr   Ú	enumerateÚformatÚdivmod)r   Úcurrent_shaperj   Ú
shape_iterÚ	new_shapeÚcurrent_sizeÚirb   Únegative_indexesÚnew_sizeÚskipÚ	specifiedÚunspecifiedÚ	remainderÚ	err_shapes                  r   Úcheck_shaper�   (  s$  € ô( ˆ4ƒy�A‚~Üð "ó #ð 	#ä
ˆ4ƒy�A‚~ð	IÜ˜d 1™g›ˆJô ÑH¸ZÔHÓH‰IäÑ>¸Ô>Ó>ˆ	àÐÙÜ�9‹~ VÑ+Ü ð ",ó -ð -ä�‹^˜qÒ ÜÐKÓLÐLÜÑ(˜iÔ(Ô(ÜÐBÓCÐCô ˜MÓ*ˆô +4°IÓ*>×H¡$ ! QÀ!ÀaÃ%šAÐHÐÑHÙÜ˜I“ˆHØ˜<Ò'Ü Ð!Pß"(¡&¨°yÓ"AóCð CäÐ!Ó" aÒ'Ø# AÑ&ˆDÜ˜Y u¨Ð-°	¸$¸q¹&¸'Ð0BÑBÓCˆIÜ%+¨L¸)Ó%DÑ"ˆK˜Ø˜AŠ~Ü!Ñ!PÀiÔ!PÓP�	Ü ð "$ß$*¡F¨<¸Ó$CóEð Eà! % 4Ð(¨K¨>Ñ9¸IÀdÈ1ÁfÀgÐ<NÑN‰IäÐEÓFÐFä
ˆ9ƒ~˜Ò¡H´°Y³À1Ò1DÜÐ?Ó@Ð@àÐøôU ò 	4Ü!Ÿ™¨¨Q©Ó0Ð3‹Ið	4üó* Is   ©F= ÃG&ÃG&Æ="G#Ç"G#c                 óÄ   — | j                  dd«      }| j                  dd«      }| r7t        dj                  dj                  | j	                  «       «      «      «      ‚||fS )a?  Unpack keyword arguments for reshape function.

    This is useful because keyword arguments after star arguments are not
    allowed in Python 2, but star keyword arguments are. This function unpacks
    'order' and 'copy' from the star keyword arguments (with defaults) and
    throws an error for any remaining.
    ÚorderÚCrH   Fz/reshape() got unexpected keywords arguments: {}z, )Úpopr   r�   ÚjoinÚkeys)ÚkwargsrŸ   rH   s      r   Úcheck_reshape_kwargsr¥   o  sZ   € ð �J‰J�w Ó$€EØ�:‰:�f˜eÓ$€DÙÜÐIß™ §	¡	¨&¯+©+«-Ó 8Ó9ó;ð 	;à�$ˆ;Ðr    c                 óz   — t        t        j                  j                  d«      dd«      }|duxr t	        | |«      S )zV
    Check whether object is pydata/sparse matrix, avoiding importing the module.
    ÚsparseÚSparseArrayN)ÚgetattrÚsysÚmodulesr   rP   )ÚmÚbase_clss     r   Úis_pydata_spmatrixr®   €  s6   € ô ”s—{‘{—‘ xÓ0°-ÀÓF€HØ˜4ÐÒ;¤J¨q°(Ó$;Ð;r    r„   Útarget_format©ÚcscÚcsrzsp.spmatrixc                 ó¢   — t        | «      rC| j                  «       } |�| j                  |«      } | S | j                  dvr| j	                  «       } | S )z_
    Convert a pydata/sparse array to scipy sparse matrix,
    pass through anything else.
    r°   )r®   Úto_scipy_sparseÚasformatr�   Útocsc)r„   r¯   s     r   Úconvert_pydata_sparse_to_scipyr·   ˆ  sS   € ô ˜#ÔØ×!Ñ!Ó#ˆØÐ$Ø—,‘,˜}Ó-ˆCð €Jð �Z‰Z˜~Ñ-Ø—)‘)“+ˆCØ€Jr    c                  óf   — t        j                  | i |¤Žj                  t         j                  «      S rw   )r   r'   ÚviewÚmatrix)r   r¤   s     r   rº   rº   ž  s%   € Ü�8‰8�TÐ$˜VÑ$×)Ñ)¬"¯)©)Ó4Ð4r    c                 óÄ   — t        | t        j                  «      r|�| j                  |k(  r| S t        j                  | |¬«      j                  t        j                  «      S )Nr&   )rP   r   rº   r#   r:   r¹   )rJ   r#   s     r   Úasmatrixr¼   ¢  sD   € Ü�$œŸ	™	Ô"¨¨¸¿¹ÀuÒ9LØˆÜ�:‰:�d %Ô(×-Ñ-¬b¯i©iÓ8Ð8r    c                 ó0  — t        | t        j                  j                  «      r| j	                  «       S t        | t        j
                  «      r:t        j                  | j                  «       | j                  | j                  ¬«      S t        | t        j                  «      rWt        j                  | j                  | j                  ¬«      }t        j                  j                  | j                  |«       |S | j!                  «       j	                  «       S )zñAccess nonzero values, possibly after summing duplicates.

    Parameters
    ----------
    s : sparse array
        Input sparse array.

    Returns
    -------
    data: ndarray
      Nonzero values of the array, with shape (s.nnz,)

    )r#   Úcountr&   )rP   ÚspÚ_dataÚ_data_matrixÚ_deduped_dataÚ	dok_arrayr   ÚfromiterÚvaluesr#   ÚnnzÚ	lil_arrayÚemptyÚ_csparsetoolsÚlil_flatten_to_arrayrJ   Útocoo)ÚsrJ   s     r   Ú_todatarÍ   ª  s®   € ô �!”R—X‘X×*Ñ*Ô+Ø�‰Ó Ð ä�!”R—\‘\Ô"Ü�{‰{˜1Ÿ8™8›:¨Q¯W©W¸A¿E¹EÔBÐBä�!”R—\‘\Ô"Ü�x‰x˜Ÿ™ Q§W¡WÔ-ˆÜ
×Ñ×-Ñ-¨a¯f©f°dÔ;Øˆà�7‰7‹9×"Ñ"Ó$Ð$r    )NN)NF)r‰   NF)F)rF   Nrw   )@Ú__doc__rª   Útypingr   r   r   r   rd   Únumpyr   Úmathr   Úscipy.sparser§   r¿   Úscipy._lib._utilr   r	   Ú__all__Úbool_ÚbyteÚubyteÚshortÚushortrN   ÚuintcÚlonglongÚ	ulonglongÚfloat32Úfloat64Ú
longdoubleÚ	complex64Ú
complex128Úclongdoubler   r   r
   r$   r)   r6   r>   r   rQ   r   rX   r#   r   rf   r   r   r   r   r   r   r~   rs   rg   r�   r¥   r®   r·   rº   r¼   rÍ   r‰   r    r   ú<module>rã      sÇ  ðñó ß 0Ó 0Û Û Ý Ý ß .òL€ð —H‘H˜bŸg™g r§x¡x°·±¸2¿9¹9ÀbÇgÁgØ—H‘H˜g x°·±¸b¿l¹lØ—J‘J §
¡
¨B¯M©MØ—L‘L "§-¡-°·±ðAÐ ð
 €òDòDò7òò(:ó ñ4	¨B¯J©Jó 	ó4ðn˜Ÿ™ð  b§h¡hó ð:�tó :ð
�Dó ð,¨ò °4ó ð";�Tó ;ð9�4ó 9ð%�$ó %ó.ð.D°eò DÀÀcÈ3ÀhÁó DòNð"<˜Tó <ð @DñØ	ðØ% g¨lÑ&;Ñ<ðà
ˆ3�ÐÑóò,5ó9ð%�"—*‘*ô %r    