Ë
    û�Dj,3  ã                   óÆ   — d dl Z d dlZd dlZd dlZd dlmZ ddlmZ d dl	m
c mZ d dlmZ ddlmZ dgZd„ Z G d	„ d«      Zej(                  fd
„Zdej(                  dœd„Zy)é    N)Úprodé   )Ú_bspl)Ú	csr_array)Ú_not_a_knotÚ	NdBSplinec                 óŠ   — t        j                  | t         j                  «      rt         j                  S t         j                  S )z>Return np.complex128 for complex dtypes, np.float64 otherwise.)ÚnpÚ
issubdtypeÚcomplexfloatingÚ
complex128Úfloat64©Údtypes    ú`C:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\scipy/interpolate/_ndbspline.pyÚ
_get_dtyper      s*   € ä	‡}�}�UœB×.Ñ.Ô/Ü�}‰}Ðä�z‰zÐó    c                   ó<   — e Zd ZdZddœd„Zdddœd„Zedd„«       Zy)	r   a©  Tensor product spline object.

    The value at point ``xp = (x1, x2, ..., xN)`` is evaluated as a linear
    combination of products of one-dimensional b-splines in each of the ``N``
    dimensions::

       c[i1, i2, ..., iN] * B(x1; i1, t1) * B(x2; i2, t2) * ... * B(xN; iN, tN)


    Here ``B(x; i, t)`` is the ``i``-th b-spline defined by the knot vector
    ``t`` evaluated at ``x``.

    Parameters
    ----------
    t : tuple of 1D ndarrays
        knot vectors in directions 1, 2, ... N,
        ``len(t[i]) == n[i] + k + 1``
    c : ndarray, shape (n1, n2, ..., nN, ...)
        b-spline coefficients
    k : int or length-d tuple of integers
        spline degrees.
        A single integer is interpreted as having this degree for
        all dimensions.
    extrapolate : bool, optional
        Whether to extrapolate out-of-bounds inputs, or return `nan`.
        Default is to extrapolate.

    Attributes
    ----------
    t : tuple of ndarrays
        Knots vectors.
    c : ndarray
        Coefficients of the tensor-produce spline.
    k : tuple of integers
        Degrees for each dimension.
    extrapolate : bool, optional
        Whether to extrapolate or return nans for out-of-bounds inputs.
        Defaults to true.

    Methods
    -------
    __call__
    design_matrix

    See Also
    --------
    BSpline : a one-dimensional B-spline object
    NdPPoly : an N-dimensional piecewise tensor product polynomial

    N)Úextrapolatec                ó¤  — t        |«      }	 t        |«       t        |«      |k7  r$t        dt        |«      ›dt        |«      ›d�«      ‚t        d„ |D «       «      | _        t        d„ |D «       «      | _        t        j                  |«      | _        |€d}t        |«      | _
        t        j                  |«      | _        t        |«      D �]§  }| j
                  |   }| j                  |   }|j                  d   |z
  dz
  }	|dk  rt        d	|› d
�«      ‚|j                  dk7  rt        d|› d�«      ‚|	|dz   k  rt        dd|z  dz   › d|› d|› d�«      ‚t        j                  |«      dk  j                  «       rt        d|› d�«      ‚t        t        j                   |||	dz    «      «      dk  rt        d|› d�«      ‚t        j"                  |«      j%                  «       st        d|› d�«      ‚| j                  j                  |k  rt        d|› d�«      ‚| j                  j                  |   |	k7  s�Œot        d|› d| j                  j                  |   › dt        |«      › d|	› d|› d�«      ‚ t'        | j                  j(                  «      }
t        j*                  | j                  |
¬«      | _        y # t        $ r
 |f|z  }Y �Œ¶w xY w)Nz	len(t) = z != len(k) = ú.c              3   óF   K  — | ]  }t        j                  |«      –— Œ y ­w©N)ÚoperatorÚindex)Ú.0Úkis     r   ú	<genexpr>z%NdBSpline.__init__.<locals>.<genexpr>Y   s   è ø€ Ò6¨b”x—~‘~ b×)Ñ6ùs   ‚!c              3   óR   K  — | ]  }t        j                  |t        ¬ «      –— Œ! y­w©r   N)r
   ÚascontiguousarrayÚfloat)r   Útis     r   r   z%NdBSpline.__init__.<locals>.<genexpr>Z   s    è ø€ ÒIÀ”r×+Ñ+¨B´e×<Ð<ÑIùs   ‚%'Tr   r   zSpline degree in dimension z cannot be negative.zKnot vector in dimension z must be one-dimensional.zNeed at least é   z knots for degree z in dimension zKnots in dimension z# must be in a non-decreasing order.z.Need at least two internal knots in dimension z should not have nans or infs.zCoefficients must be at least z-dimensional.z,Knots, coefficients and degree in dimension z are inconsistent: got z coefficients for z knots, need at least z for k=r   )ÚlenÚ	TypeErrorÚ
ValueErrorÚtupleÚkÚtr
   ÚasarrayÚcÚboolr   ÚrangeÚshapeÚndimÚdiffÚanyÚuniqueÚisfiniteÚallr   r   r!   )Úselfr*   r,   r)   r   r0   ÚdÚtdÚkdÚnÚdts              r   Ú__init__zNdBSpline.__init__M   sø  € Ü�1‹vˆð	Ü�ŒFô
 ˆq‹6�TŠ>Ü 	¤ A£˜{¨.¬s°1«v¨k¸Ð;Ó<Ð<äÑ6°AÔ6Ó6ˆŒÜÑIÀqÔIÓIˆŒÜ—‘˜A“ˆŒàÐØˆKÜ Ó,ˆÔä—‘˜A“ˆŒä�t“ó 	-ˆAØ—‘˜‘ˆBØ—‘˜‘ˆBØ—‘˜‘˜bÑ  1Ñ$ˆAØ�AŠvÜ Ð#>¸q¸cð B.ð "/ó 0ð 0à�w‰w˜!Š|Ü Ð#<¸Q¸Cð @5ð "6ó 7ð 7à�2˜‘6ŠzÜ  >°!°B±$¸±(°ð <%Ø%' D¨°q°c¸ð"<ó =ð =ä—‘˜“˜a‘×$Ñ$Ô&Ü Ð#6°q°cð ::ð ";ó <ð <ä”2—9‘9˜R  1 q¡5˜\Ó*Ó+¨aÒ/Ü ð $/Ø/0¨c°ð"4ó 5ð 5ä—;‘;˜r“?×&Ñ&Ô(Ü Ð#6°q°cð :2ð "3ó 4ð 4à�v‰v�{‰{˜TÒ!Ü ð $%Ø%& C }ð"6ó 7ð 7à�v‰v�|‰|˜A‰ !Ô#Ü ð $%Ø%& Cð ()Ø)-¯©¯©°a©Ð(9ð :%Ü%(¨£W IÐ-CÀAÀ3ð G'Ø'( c¨ð	",ó -ð -ð5	-ô@ ˜Ÿ™Ÿ™Ó%ˆÜ×%Ñ% d§f¡f°BÔ7ˆ�øôe ò 	à��T‘	‹Að	ús   �J< Ê<KËK)Únur   c                óð  — t        | j                  «      }|€| j                  }t        |«      }|€'t	        j
                  |ft        j                  ¬«      }n‡t	        j                  |t        j                  ¬«      }|j                  dk7  s|j                  d   |k7  r%t        d|›dt        | j                  «      › d�«      ‚t        |dk  «      rt        d|›�«      ‚t	        j                  |t        ¬«      }|j                  }|j                  d	|d	   «      }t	        j                  |«      }|d	   |k7  rt        d
|› d|› �«      ‚t	        j                  | j                  t	        j                   d«      ¬«      }| j                  D �cg c]  }t        |«      ‘Œ }}t	        j"                  |t%        |«      ft        ¬«      }	|	j'                  t        j(                  «       t+        |«      D ].  }
| j                  |
   |	|
dt        | j                  |
   «      …f<   Œ0 t	        j                  |t	        j                   d«      ¬«      }t-        d„ | j                  D «       «      }t	        j.                  t	        j0                  t3        |«      «      |«      }t	        j                  |t        j4                  ¬«      j6                  }| j8                  j                  | j8                  j                  d| dz   «      }|j;                  «       }t	        j                  |j<                  D �cg c]  }||j                   j>                  z  ‘Œ c}t        j4                  ¬«      }|j                  d	   }t	        j"                  |j                  dd	 |fz   |j                   ¬«      }tA        jB                  ||	|||||||||«       |j                  |dd	 | j8                  j                  |d z   «      S c c}w c c}w )a@  Evaluate the tensor product b-spline at ``xi``.

        Parameters
        ----------
        xi : array_like, shape(..., ndim)
            The coordinates to evaluate the interpolator at.
            This can be a list or tuple of ndim-dimensional points
            or an array with the shape (num_points, ndim).
        nu : array_like, optional, shape (ndim,)
            Orders of derivatives to evaluate. Each must be non-negative.
            Defaults to the zeroth derivivative.
        extrapolate : bool, optional
            Whether to exrapolate based on first and last intervals in each
            dimension, or return `nan`. Default is to ``self.extrapolate``.

        Returns
        -------
        values : ndarray, shape ``xi.shape[:-1] + self.c.shape[ndim:]``
            Interpolated values at ``xi``
        Nr   r   r   z)invalid number of derivative orders nu = z for ndim = r   z'derivatives must be positive, got nu = éÿÿÿÿzShapes: xi.shape=z
 and ndim=Úlongc              3   ó&   K  — | ]	  }|d z   –— Œ y­w)r   N© )r   r9   s     r   r   z%NdBSpline.__call__.<locals>.<genexpr>Á   s   è ø€ Ò. �b˜1•fÑ.ùs   ‚)r?   )"r%   r*   r   r-   r
   ÚzerosÚintcr+   r0   r/   r'   r2   r"   Úreshaper!   r)   r   ÚemptyÚmaxÚfillÚnanr.   r(   Úunravel_indexÚaranger   ÚintpÚTr,   ÚravelÚstridesÚitemsizer   Úevaluate_ndbspline)r6   Úxir=   r   r0   Úxi_shapeÚ_kr#   Úlen_tÚ_tr7   r/   ÚindicesÚ_indices_k1dÚc1Úc1rÚsÚ_strides_c1Únum_c_trÚouts                       r   Ú__call__zNdBSpline.__call__†   s9  € ô* �4—6‘6‹{ˆàÐØ×*Ñ*ˆKÜ˜;Ó'ˆàˆ:Ü—‘˜4˜'¬¯©Ô1‰Bä—‘˜B¤b§g¡gÔ.ˆBØ�w‰w˜!Š|˜rŸx™x¨™{¨dÒ2Ü Ø@¸2¸'ð BÜ! $§&¡&›k˜]¨!ð-ó.ð .ô �2˜‘6Œ{Ü Ð#KÀbÀWÐ!MÓNÐNô �Z‰Z˜¤%Ô(ˆØ—8‘8ˆØ�Z‰Z˜˜H R™LÓ)ˆÜ×!Ñ! "Ó%ˆà�B‰<˜4ÒÜÐ0°°
¸*ÀTÀFÐKÓLÐLô �Z‰Z˜Ÿ™¤b§h¡h¨vÓ&6Ô7ˆð $(§6¡6Ö*˜R”�R•Ð*ˆÐ*Ü�X‰X�tœS ›ZÐ(´Ô6ˆØ
�‰”—‘ŒÜ�t“ò 	/ˆAØ%)§V¡V¨A¡YˆBˆq�/”3�t—v‘v˜a‘y“>�/Ð!Ò"ð	/ä—
‘
˜5¬¯©°Ó(8Ô9ˆô Ñ. t§v¡vÔ.Ó.ˆÜ×"Ñ"¤2§9¡9¬T°%«[Ó#9¸5ÓAˆÜ—z‘z '´·±Ô9×;Ñ;ˆð �V‰V�^‰^˜DŸF™FŸL™L¨¨$Ð/°%Ñ7Ó8ˆØ�h‰h‹jˆô —j‘jØ+-¯:©:ö"7Ø&'ð #$ r§x¡x×'8Ñ'8Ó"8ò "7Ü>@¿g¹gôGˆð —8‘8˜B‘<ˆÜ�h‰h�r—x‘x  �}¨ {Ñ2¸"¿(¹(ÔCˆä× Ñ  Ø!#Ø!&Ø!#Ø!#Ø!,Ø!$Ø!)Ø!,Ø!-Ø!$ô
	'ð �{‰{˜8 C R˜=¨4¯6©6¯<©<¸¸Ð+>Ñ>Ó?Ð?ùòG +ùò""7s   ÆO.Ì) O3c                 ó†  — t        j                  |t        ¬«      }|j                  d   }t	        |«      |k7  rt        dt	        |«      › d|›d�«      ‚	 t	        |«       t        j                  |t         j                  ¬«      }t        j                  |||«      \  }}}	t        |||	f«      S # t        $ r	 |f|z  }Y Œ_w xY w)a  Construct the design matrix as a CSR format sparse array.

        Parameters
        ----------
        xvals :  ndarray, shape(npts, ndim)
            Data points. ``xvals[j, :]`` gives the ``j``-th data point as an
            ``ndim``-dimensional array.
        t : tuple of 1D ndarrays, length-ndim
            Knot vectors in directions 1, 2, ... ndim,
        k : int
            B-spline degree.
        extrapolate : bool, optional
            Whether to extrapolate out-of-bounds values of raise a `ValueError`

        Returns
        -------
        design_matrix : a CSR array
            Each row of the design matrix corresponds to a value in `xvals` and
            contains values of b-spline basis elements which are non-zero
            at this value.

        r   r?   z*Data and knots are inconsistent: len(t) = z for  ndim = r   )r
   r+   r"   r/   r%   r'   r&   Úint32r   Ú
_colloc_ndr   )
ÚclsÚxvalsr*   r)   r   r0   ÚkkÚdatarW   Úindptrs
             r   Údesign_matrixzNdBSpline.design_matrixÞ   sÁ   € ô0 —
‘
˜5¬Ô.ˆØ�{‰{˜2‰ˆÜˆq‹6�TŠ>ÜØ<¼SÀ»V¸Hð EØ�9˜Aðóð ð	Ü�ŒFô
 �Z‰Z˜¤§¡Ô*ˆÜ %× 0Ñ 0°¸¸2Ó >Ñˆˆg�vÜ˜$ ¨Ð0Ó1Ð1øô ò 	à��T‘	ŠAð	ús   ÁB. Â.C Â?C )T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r<   r_   Úclassmethodrh   rB   r   r   r   r      s6   „ ñ1ðd 04ô 78ðr "&°4ô V@ðp ò&2ó ñ&2r   c           
      ó.  — t        j                  |j                  t         j                  «      r8t	        | |j
                  |fi |¤Ž}t	        | |j                  |fi |¤Ž}|d|z  z   S |j                  dk(  r{|j                  d   dk7  rit        j                  |«      }t        |j                  d   «      D ]7  } || |d d …|f   fi |¤Ž\  |d d …|f<   }|dk7  sŒ$t        d|›d|›d|› d�«      ‚ |S  || |fi |¤Ž\  }}|dk7  rt        d|›d	|›d�«      ‚|S )
Ny              ð?r$   r   r   z	solver = z returns info =z for column r   z returns info = )r
   r   r   r   Ú_iter_solveÚrealÚimagr0   r/   Ú
empty_liker.   r'   )	ÚaÚbÚsolverÚsolver_argsrp   rq   ÚresÚjÚinfos	            r   ro   ro     s-  € ô
 
‡}�}�Q—W‘Wœb×0Ñ0Ô1Ü˜1˜aŸf™f fÑ<°Ñ<ˆÜ˜1˜aŸf™f fÑ<°Ñ<ˆØ�b˜‘g‰~Ðà‡v�v�‚{�q—w‘w˜q‘z A’~Ü�m‰m˜AÓˆÜ�q—w‘w˜q‘zÓ"ò 	RˆAÙ$ Q¨ª!¨Q¨$©Ñ?°;Ñ?‰OˆC’�1�‰I�tØ�q‹yÜ  I F ;Ð.>¸°x¸|ÈAÈ3ÈaÐ!PÓQÐQð	Rð ˆ
á˜1˜aÑ/ ;Ñ/‰	ˆˆTØ�1Š9Ü 	 ˜{Ð*;°D°9¸AÐ>Ó?Ð?Øˆ
r   ©ru   c                óZ  ‡ ‡— t        ‰ «      }t        d„ ‰ D «       «      }	 t        ‰«       t        ‰ «      D ]L  \  }}t        t	        j
                  |«      «      }	|	‰|   k  sŒ-t        d|	› d|› d‰|   › d‰|   dz   › d�	«      ‚ t        ˆˆ fd„t        |«      D «       «      }
t	        j                  t        j                  ‰ Ž D �cg c]  }|‘Œ c}t        ¬	«      }t        j                  ||
‰«      }|j                  }t        |d
| «      t        ||d
 «      f}|j!                  |«      }|t"        j$                  k7  r$t'        j(                  t*        |¬«      }d|vrd|d<    |||fi |¤Ž}|j!                  |||d
 z   «      }t        |
|‰«      S # t        $ r
 ‰f|z  ŠY �Œxw xY wc c}w )a™  Construct an interpolating NdBspline.

    Parameters
    ----------
    points : tuple of ndarrays of float, with shapes (m1,), ... (mN,)
        The points defining the regular grid in N dimensions. The points in
        each dimension (i.e. every element of the `points` tuple) must be
        strictly ascending or descending.      
    values : ndarray of float, shape (m1, ..., mN, ...)
        The data on the regular grid in n dimensions.
    k : int, optional
        The spline degree. Must be odd. Default is cubic, k=3
    solver : a `scipy.sparse.linalg` solver (iterative or direct), optional.
        An iterative solver from `scipy.sparse.linalg` or a direct one,
        `sparse.sparse.linalg.spsolve`.
        Used to solve the sparse linear system
        ``design_matrix @ coefficients = rhs`` for the coefficients.
        Default is `scipy.sparse.linalg.gcrotmk`
    solver_args : dict, optional
        Additional arguments for the solver. The call signature is
        ``solver(csr_array, rhs_vector, **solver_args)``

    Returns
    -------
    spl : NdBSpline object

    Notes
    -----
    Boundary conditions are not-a-knot in all dimensions.
    c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr   )r%   )r   Úxs     r   r   zmake_ndbspl.<locals>.<genexpr>@  s   è ø€ Ò, ”S˜—VÑ,ùs   ‚z
There are z points in dimension z, but order z requires at least  r   z points per dimension.c              3   ót   •K  — | ]/  }t        t        j                  ‰|   t        ¬ «      ‰|   «      –— Œ1 y­wr    )r   r
   r+   r"   )r   r7   r)   Úpointss     €€r   r   zmake_ndbspl.<locals>.<genexpr>O  s3   øè ø€ ò $Øô œ"Ÿ*™* V¨A¡Y´eÔ<¸aÀ¹d×Cñ $ùs   ƒ58r   Nrz   Úatolg�íµ ÷Æ°>)r%   r(   r&   Ú	enumerater
   Ú
atleast_1dr'   r.   r+   Ú	itertoolsÚproductr"   r   rh   r/   r   rE   ÚsslÚspsolveÚ	functoolsÚpartialro   )r   Úvaluesr)   ru   rv   r0   rS   r7   ÚpointÚnumptsr*   Úxvrd   ÚmatrÚv_shapeÚ
vals_shapeÚvalsÚcoefs   ` `               r   Úmake_ndbsplr’      sÇ  ù€ ô> ˆv‹;€DÜÑ, VÔ,Ó,€HðÜˆAŒô
 ˜fÓ%ò A‰ˆˆ5Ü”R—]‘] 5Ó)Ó*ˆØ�Q�q‘T‹>Ü˜z¨&¨Ð1FÀqÀcð J+Ø+,¨Q©4¨&ð 1!Ø!" 1¡ a¡ Ð(>ð@ó Að AðAô 	ô $Ü˜T“{ô$ó 	$€Aä�J‰J¤Y×%6Ñ%6¸Ð%?Ö@˜ršÒ@ÌÔN€Eô ×"Ñ" 5¨!¨QÓ/€Dð
 �l‰l€GÜ�w˜u �~Ó&¬¨W°T°U¨^Ó(<Ð=€JØ�>‰>˜*Ó%€Dà”—‘ÒÜ×"Ñ"¤;°vÔ>ˆØ˜Ñ$à"&ˆK˜Ñá�$˜Ñ, Ñ,€DØ�<‰<˜ 7¨4¨5 >Ñ1Ó2€DÜ�Q˜˜aÓ Ð øôC ò àˆD�‰I‹ðüò As   ¡F Ã	F(ÆF%Æ$F%)é   )rƒ   r‡   r   Únumpyr
   Úmathr   Ú r   Úscipy.sparse.linalgÚsparseÚlinalgr…   Úscipy.sparser   Ú	_bsplinesr   Ú__all__r   r   Úgcrotmkro   r’   rB   r   r   ú<module>rž      s\   ðÛ Û Û Û å å ç !Ð !Ý "å "àˆ-€ò÷k2ñ k2ð\ !Ÿ[™[ó ð0E!¨s¯{©{õ E!r   