ó
    pñ:i9  ã                   óÒ   • S SK r S SKrS SKrS SKrS SKJr  SSKJr  S SK	J
s  Jr  S SKJr  SSKJr  S/rS r " S	 S5      rS
 r\R*                  4S jrS\R*                  S.S jjrg)é    N)Úprodé   )Ú_dierckx)Ú	csr_array)Ú_not_a_knotÚ	NdBSplinec                 ó–   • [         R                  " U [         R                  5      (       a  [         R                  $ [         R                  $ )z>Return np.complex128 for complex dtypes, np.float64 otherwise.)ÚnpÚ
issubdtypeÚcomplexfloatingÚ
complex128Úfloat64©Údtypes    Ú_/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/scipy/interpolate/_ndbspline.pyÚ
_get_dtyper      s-   € ä	‡}‚}�UœB×.Ñ.×/Ñ/Ü�}‰}Ðä�z‰zÐó    c                   ój   • \ rS rSrSrSS.S jr\S 5       r\S 5       rSSS.S	 jr	\
SS
 j5       rSrg)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-product 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                óô  • [        X15      u  U l        U l        u  U l        U l        Uc  Sn[        U5      U l        [        R                  " U5      U l	        U R                  R                  S   nU R                  R                  U:  a  [        SU S35      e[        U5       HŽ  nU R                  U   nU R                  U   nUR                  S   U-
  S-
  n	U R                  R                  U   U	:w  d  MU  [        SU SU R                  R                  U    S[!        U5       S	U	 S
U S35      e   [#        U R                  R$                  5      n
[        R&                  " U R                  U
S9U l	        g )NTr   zCoefficients must be at least z-dimensional.r   z,Knots, coefficients and degree in dimension z are inconsistent: got z coefficients for z knots, need at least z for k=Ú.r   )Ú_preprocess_inputsÚ_kÚ_indices_k1dÚ_tÚ_len_tÚboolr   r
   ÚasarrayÚcÚshapeÚndimÚ
ValueErrorÚrangeÚtÚkÚlenr   r   Úascontiguousarray)Úselfr%   r    r&   r   r"   ÚdÚtdÚkdÚnÚdts              r   Ú__init__ÚNdBSpline.__init__M   sT  € Ü=OÐPQÓ=UÑ:ˆŒ�Ô"Ñ$: T¤W¨d¬kàÑØˆKÜ Ó,ˆÔä—’˜A“ˆŒà�w‰w�}‰}˜QÑˆØ�6‰6�;‰;˜ÓÜÐ=¸d¸VÀ=ÐQÓRÐRä�t–ˆAØ—‘˜‘ˆBØ—‘˜‘ˆBØ—‘˜‘˜bÑ  1Ñ$ˆAà�v‰v�|‰|˜A‰ !Õ#Ü ð $%Ø%& Cð ()Ø)-¯©¯©°a©Ð(9ð :%Ü%(¨£W IÐ-CÀAÀ3ð G'Ø'( c¨ð	",ó -ð -ñ ô ˜Ÿ™Ÿ™Ó%ˆÜ×%Ò% d§f¡f°BÑ7ˆ�r   c                 ó,   • [        U R                  5      $ ©N)Útupler   ©r)   s    r   r&   ÚNdBSpline.ki   s   € ä�T—W‘W‹~Ðr   c                 ón   ^ • [        U 4S j[        T R                  R                  S   5       5       5      $ )Nc              3   ód   >#   • U  H%  nTR                   US TR                  U   24   v •  M'     g 7fr2   )r   r   )Ú.0r*   r)   s     €r   Ú	<genexpr>ÚNdBSpline.t.<locals>.<genexpr>p   s-   øé € ÐRÒ:Q°Q�T—W‘W˜Q  §¡¨Q¡ Ð/Ö0Ò:Qùs   ƒ-0r   )r3   r$   r   r!   r4   s   `r   r%   ÚNdBSpline.tm   s(   ø€ ô ÔR¼%ÀÇÁÇÁÈaÑ@PÔ:QÓRÓRÐRr   )Únur   c                óö  • U R                   R                  S   nUc  U R                  n[        U5      nUc%  [        R
                  " U4[        R                  S9nOŽ[        R                  " U[        R                  S9nUR                  S:w  d  UR                  S   U:w  a&  [        SU< S[        U R                  5       S35      e[        US:  5      (       a  [        SU< 35      e[        R                  " U[        S9nUR                  nUR                  S	US	   5      n[        R                  " U5      nUS	   U:w  a  [        S
U SU 35      eU R                   R"                  R$                  S:H  nU R                   nU(       a)  U R                   R                  U:X  a  U R                   S   nUR'                  [        5      nUR                  UR                  SU S-   5      nUR)                  5       n	[        R                  " UR*                   V
s/ s H  n
X¨R"                  R,                  -  PM     sn
[        R                  S9nUR                  S	   n[.        R0                  " UU R                   U R2                  U R4                  UUU	UUU R6                  5
      nUR'                  U R                   R"                  5      nUR                  USS	 U R                   R                  US -   5      $ s  sn
f )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``
r   Nr   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=r    ).N)r>   )r   r!   r   r   r
   ÚzerosÚint64r   r"   r#   r'   r%   ÚanyÚfloatÚreshaper(   r    r   ÚkindÚviewÚravelÚstridesÚitemsizer   Úevaluate_ndbspliner   r   r   )r)   Úxir<   r   r"   Úxi_shapeÚwas_complexÚccÚc1Úc1rÚsÚ_strides_c1Únum_c_trÚouts                 r   Ú__call__ÚNdBSpline.__call__r   s‚  € ð* �w‰w�}‰}˜QÑˆàÑØ×*Ñ*ˆKÜ˜;Ó'ˆà‰:Ü—’˜4˜'¬¯©Ñ2‰Bä—’˜B¤b§h¡hÑ/ˆ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ð —f‘f—l‘l×'Ñ'¨3Ñ.ˆØ�V‰VˆÞ˜4Ÿ6™6Ÿ;™;¨$Ó.ð —‘˜	Ñ"ˆBØ�W‰W”U‹^ˆð �Z‰Z˜Ÿ™  $˜¨%Ñ/Ó0ˆØ�h‰h‹jˆô —j’jØ+-¯:ª:ó"7Ú+5 að #$§x¡x×'8Ñ'8Ô"8Ù+5ñ"7Ü>@¿h¹hñHˆð —8‘8˜B‘<ˆÜ×)Ò)¨"Ø!%§¡Ø!%§¡Ø!%§¡Ø!#Ø!,Ø!$Ø!)Ø!,Ø!%×!2Ñ!2ó

ˆð �h‰h�t—v‘v—|‘|Ó$ˆØ�{‰{˜8 C R˜=¨4¯6©6¯<©<¸¸Ð+>Ñ>Ó?Ð?ùò!"7s   È"K6c                 óî  ^^• [         R                  " U[        S9nUR                  S   n[	        U5      U:w  a  [        S[	        U5       SU< S35      e[        TU5      u  mnu  nm[        UU4S j[        U5       5       5      nUSS S	-   n	[         R                  " U	SSS2   [         R                  S9SSS2   R                  5       n
[        R                  " UUTTXj5      u  p¼n[        X¼U45      $ )
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   c              3   ó@   >#   • U  H  nTU   TU   -
  S -
  v •  M     g7f©r   N© )r8   r*   r&   Úlen_ts     €€r   r9   Ú*NdBSpline.design_matrix.<locals>.<genexpr>ç   s"   øé € ÐA²[°˜˜a™ 1 Q¡4™¨!Ö+²[ùs   ƒr   N)r   )r
   r   rB   r!   r'   r#   r   r3   r$   Úcumprodr@   Úcopyr   Ú	_coloc_ndr   )ÚclsÚxvalsr%   r&   r   r"   r   r   Úc_shapeÚcsÚcstridesÚdataÚindicesÚindptrrZ   s      `          @r   Údesign_matrixÚNdBSpline.design_matrixÁ   sú   ù€ ô0 —
’
˜5¬Ñ.ˆØ�{‰{˜2‰ˆÜˆq‹6�T‹>ÜØ<¼SÀ»V¸Hð EØ‘9˜Aðóð ô (:¸!¸QÓ'?Ñ$ˆˆ<™˜"˜eô
 ÕA´U¸4´[ÓAÓAˆð �Q�Rˆ[˜4ÑˆÜ—:’:˜b¡ 2 ™h¬b¯h©hÑ7¹¸"¸Ñ=×BÑBÓDˆô !)× 2Ò 2°5Ø�E˜1˜ló!6Ñˆ�vô ˜$¨Ð0Ó1Ð1r   )r   r   r   r   r    r   )T)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r/   Úpropertyr&   r%   rT   Úclassmethodrg   Ú__static_attributes__rY   r   r   r   r      s_   † ñ1ðd 04õ 8ð8 ñó ðð ñSó ðSð "&°4õ M@ð^ ó02ó ó02r   c           
      óÆ  • [        U[        5      (       d  [        SU S35      e[        U5      n [        U 5        [
        R                  " U  Vs/ s H  n[        R                  " U5      PM     sn[
        R                  S9n [        U 5      U:w  a%  [        S[        U5       S[        U 5      < S35      e[        U5      n[        U5       GH6  n[
        R                  " X   5      nX   nUR                  S   U-
  S-
  nUS:  a  [        S	U S
35      eUR                  S:w  a  [        SU S35      eXvS-   :  a  [        SSU-  S-    SU SU S35      e[
        R                  " U5      S:  R                  5       (       a  [        SU S35      e[        [
        R                  " XVUS-    5      5      S:  a  [        SU S35      e[
        R                   " U5      R#                  5       (       a  GM*  [        SU S35      e   [        S U  5       5      n[
        R$                  " [
        R&                  " [)        U5      5      U5      n	[
        R                  " U	[
        R                  S9R*                  R-                  5       n
[        U5      nU Vs/ s H  n[        U5      PM     nn[
        R.                  " U[1        U5      4[2        S9nUR5                  [
        R6                  5        [        U5       H  nX   XÔS[        X   5      24'   M     [
        R                  " U[
        R                  S9nX
XÜ44$ ! [         a
    U 4U-  n  GNf = fs  snf s  snf )z“Helpers: validate and preprocess NdBSpline inputs.

Parameters
----------
k : int or tuple
   Spline orders
t_tpl : tuple or array-likes
   Knots.
z-Expect `t` to be a tuple of array-likes. Got z	 instead.r   z	len(t) = z != len(k) = r   r   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.c              3   ó*   #   • U  H	  oS -   v •  M     g7frX   rY   )r8   r,   s     r   r9   Ú%_preprocess_inputs.<locals>.<genexpr>-  s   é € Ð%¢1˜R�q–&¢1ùs   ‚N)Ú
isinstancer3   r#   r'   Ú	TypeErrorr
   r   ÚoperatorÚindexr@   r$   r!   r"   ÚdiffrA   ÚuniqueÚisfiniteÚallÚunravel_indexÚaranger   ÚTr]   ÚemptyÚmaxrB   ÚfillÚnan)r&   Út_tplr"   Úkir*   r+   r,   r-   r!   re   r   ÚtirZ   r   s                 r   r   r   õ   s)  € ô �eœU×#Ñ#Üð  Ø %˜w ið1ó 
ð 	
ô
 ˆu‹:€DðÜˆAŒô
 	�
Š
±Ó3²¨2”H—N’N 2Ö&±Ñ3¼2¿8¹8ÑD€Aä
ˆ1ƒv�ƒ~Ü˜9¤S¨£Z L°´S¸³V±K¸qÐAÓBÐBô ˆu‹:€DÜ�4�[ˆÜ�ZŠZ˜™Ó!ˆØ‰TˆØ�H‰H�Q‰K˜"Ñ˜qÑ ˆØ�‹6ÜÐ:¸1¸#ð >*ð +ó ,ð ,à�7‰7�a‹<ÜÐ8¸¸ð <1ð 2ó 3ð 3à�A‰v‹:Ü˜~¨a°©d°Q©h¨Zð 8!Ø!#  N°1°#°Qð8ó 9ð 9ä�GŠG�B‹K˜!‰O× Ñ ×"Ñ"ÜÐ2°1°#ð 66ð 7ó 8ð 8äŒr�yŠy˜˜q 1™u˜Ó&Ó'¨!Ó+Üð  +Ø+,¨#¨Qð0ó 1ð 1ä�{Š{˜2‹×"Ñ"×$Ô$ÜÐ2°1°#ð 6.ð /ó 0ð 0ñ) ô2 Ñ%¡1Ó%Ó%€EÜ×ÒœrŸyšy¬¨e«Ó5°uÓ=€GÜ—:’:˜g¬R¯X©XÑ6×8Ñ8×=Ñ=Ó?€Lô ˆu‹:€DÙ$Ó%šu˜ŒS�ŽW™u€EÐ%Ü	�Š�4œ˜U›Ð$¬EÑ	2€BØ‡G�GŒB�F‰F„OÜ�4Ž[ˆØ %¡ˆˆnŒs�5‘8‹}ˆnÐÓñ ä�JŠJ�u¤B§H¡HÑ-€Eà˜R˜KÐ'Ð'øôk ó àˆD�‰I‹ðüò 4ùòT &s   ±M Á MÊMÍMÍMc           
      óF  • [         R                  " UR                  [         R                  5      (       a6  [	        XR
                  U40 UD6n[	        XR                  U40 UD6nUSU-  -   $ UR                  S:X  a�  UR                  S   S:w  an  [         R                  " U5      n[        UR                  S   5       H:  nU" XS S 2U4   40 UD6u  US S 2U4'   nUS:w  d  M%  [        SU< SU< SU S35      e   U$ U" X40 UD6u  phUS:w  a  [        SU< S	U< S35      eU$ )
Ny              ð?rr   r   r   z	solver = z returns info =z for column r   z returns info = )r
   r   r   r   Ú_iter_solveÚrealÚimagr"   r!   Ú
empty_liker$   r#   )	ÚaÚbÚsolverÚsolver_argsr‰   rŠ   ÚresÚjÚinfos	            r   rˆ   rˆ   A  s  € ô
 
‡}‚}�Q—W‘Wœb×0Ñ0×1Ñ1Ü˜1Ÿf™f fÑ<°Ñ<ˆÜ˜1Ÿf™f fÑ<°Ñ<ˆØ�b˜‘g‰~Ðà‡v�v�ƒ{�q—w‘w˜q‘z A“~Ü�mŠm˜AÓˆÜ�q—w‘w˜q‘zÖ"ˆAÙ$ Qª!¨Q¨$©Ñ?°;Ñ?‰OˆC’�1�‰I�tØ�q�yÜ  I F¡;Ð.>¸±x¸|ÈAÈ3ÈaÐ!PÓQÐQñ #ð ˆ
á˜1Ñ/ ;Ñ/‰	ˆØ�1‹9Ü 	 ™{Ð*;°D±9¸AÐ>Ó?Ð?Øˆ
r   ©rŽ   c                ób  ^ ^• [        T 5      n[        S T  5       5      n [        T5        [        T 5       HN  u  px[        [        R
                  " U5      5      n	U	TU   ::  d  M/  [        SU	 SU STU    STU   S-    S3	5      e   [        UU 4S j[        U5       5       5      n
[        R                  " [        R                  " T 6  Vs/ s H  o»PM     sn[        S	9n[        R                  XÊT5      nUR                  n[        US
U 5      [        XåS
 5      4nUR!                  U5      nU["        R$                  :w  a$  [&        R(                  " [*        US9nSU;  a  SUS'   U" UU40 UD6nUR!                  XnUS
 -   5      n[        U
UT5      $ ! [         a
    T4U-  m GN|f = fs  snf )a1  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   ó8   #   • U  H  n[        U5      v •  M     g 7fr2   )r'   )r8   Úxs     r   r9   Úmake_ndbspl.<locals>.<genexpr>y  s   é € Ð,¢V ”S˜—V�V¢Vùs   ‚z
There are z points in dimension z, but order z requires at least  r   z points per dimension.c              3   óv   >#   • U  H.  n[        [        R                  " TU   [        S 9TU   5      v •  M0     g7f)r   N)r   r
   r   rB   )r8   r*   r&   Úpointss     €€r   r9   r—   ˆ  s5   øé € ð $Ú"�!ô œ"Ÿ*š* V¨A¡Y´eÑ<¸aÀ¹d×CÐCÚ"ùs   ƒ69r   Nr“   Úatolg�íµ ÷Æ°>)r'   r3   rv   Ú	enumerater
   Ú
atleast_1dr#   r$   r   Ú	itertoolsÚproductrB   r   rg   r!   r   rC   ÚsslÚspsolveÚ	functoolsÚpartialrˆ   )r™   Úvaluesr&   rŽ   r�   r"   rK   r*   ÚpointÚnumptsr%   Úxvr`   ÚmatrÚv_shapeÚ
vals_shapeÚvalsÚcoefs   ` `               r   Úmake_ndbsplr¬   Y  s¾  ù€ ô> ˆv‹;€DÜÑ,¡VÓ,Ó,€HðÜˆAŒô
 ˜fÖ%‰ˆÜ”R—]’] 5Ó)Ó*ˆØ�Q�q‘T�>Ü˜z¨&¨Ð1FÀqÀcð J+Ø+,¨Q©4¨&ð 1!Ø!" 1¡ a¡ Ð(>ð@ó Að Añ &ô 	õ $Ü˜T”{ó$ó 	$€Aä�JŠJ¤Y×%6Ò%6¸Ñ%?Ó@Ò%?˜ršÑ%?Ñ@ÌÑN€Eô ×"Ñ" 5¨QÓ/€Dð
 �l‰l€GÜ�w˜u �~Ó&¬¨W°U¨^Ó(<Ð=€JØ�>‰>˜*Ó%€Dà”—‘ÓÜ×"Ò"¤;°vÑ>ˆØ˜Ó$à"&ˆK˜Ñá�$˜Ñ, Ñ,€DØ�<‰<˜¨4¨5 >Ñ1Ó2€DÜ�Q˜˜aÓ Ð øôC ó àˆD�‰I‹ðüò As   ¡F ÃF,ÆF)Æ(F))é   )r�   r¡   rw   Únumpyr
   Úmathr   Ú r   Úscipy.sparse.linalgÚsparseÚlinalgrŸ   Úscipy.sparser   Ú	_bsplinesr   Ú__all__r   r   r   Úgcrotmkrˆ   r¬   rY   r   r   Ú<module>r¸      sc   ðÛ Û Û Û å å ç !Ð !Ý "å "àˆ-€ò÷X2ñ X2òvI(ðX !Ÿ[™[ô ð0E!¨s¯{©{÷ E!r   