
    (ph4:                         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   )_bspl)	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    O/var/www/html/venv/lib/python3.13/site-packages/scipy/interpolate/_ndbspline.py
_get_dtyper      s-    	}}UB..//}}zz    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   =OPQ=U:"$:TWdkK,Aww}}Q66;;=dV=QRRtABBb 1$Avv||A!#  $%%&C ())-a(9 :%%(WI-CA3 G''(c	", - -  %%%dffB7r   c                 ,    [        U R                  5      $ N)tupler   r)   s    r   r&   NdBSpline.ki   s    TWW~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:QQTWWQQ/0:Qs   -0r   )r3   r$   r   r!   r4   s   `r   r%   NdBSpline.tm   s(     R%a@P:QRRRr   )nur   c                X   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
XR"                  R,                  -  PM     sn
[        R.                  S9nUR                  S	   n[        R0                  " UR                  SS	 U4-   UR"                  S9n[2        R4                  " UU R                   U R6                  U R8                  UUU	UUU R:                  U5        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intcr   r"   r#   r'   r%   anyfloatreshaper(   r    r   kindviewravelstridesitemsizeintpemptyr   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   * ww}}Q**K;':4'1BBbgg.Bww!|rxx{d2 @2' B!$&&k]!-. . 26{{ #KbW!MNN ZZ%(88ZZHRL)!!"%B<40
*TFKLL ffll''3.VV466;;$. 	"BWWU^ ZZ$%/0hhj jj+-::"7+5a #$xx'8'8"8+5"7>@ggG 88B<hhrxx}{2"((C  !%!%!%!#!,!$!)!,!%!2!2!$
	' hhtvv||${{8CR=466<<+>>??%"7s   "L'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UU
5      u  pn[        XU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1Q4!+[s   r   N)r   )r
   r   rB   r!   r'   r#   r   r3   r$   cumprodrI   copyr   
_colloc_ndr   )clsxvalsr%   r&   r   r"   r   r   c_shapecscstridesdataindicesindptrr\   s      `          @r   design_matrixNdBSpline.design_matrix   s    0 

5.{{2q6T><SVH E9A  (:!Q'?$<"e
 AU4[AA QR[4::b2hbgg6tt<AAC !& 0 00205010<08!:v $011r   )r   r   r   r   r    r   )T)__name__
__module____qualname____firstlineno____doc__r/   propertyr&   r%   rV   classmethodri   __static_attributes__r[   r   r   r   r      s_    1d 04 88   S S "&4 O@b 32 3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[
        R0                  " U[3        U5      4[4        S9nUR7                  [
        R8                  5        [        U5       H  nX   XS[        X   5      24'   M     [
        R                  " U[
        R                  S9nX
X44$ ! [         a
    U 4U-  n  GNf = fs  snf s  snf )zHelpers: 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rZ   r[   )r8   r,   s     r   r9   %_preprocess_inputs.<locals>.<genexpr>2  s     %1Rq&1s   N)
isinstancer3   r#   r'   	TypeErrorr
   r   operatorindexint32r$   r!   r"   diffrA   uniqueisfiniteallunravel_indexaranger   rI   Tr_   rJ   maxrB   fillnan)r&   t_tplr"   kir*   r+   r,   r-   r!   rg   r   tir\   r   s                 r   r   r      s)    eU##   %wi1 
 	

 u:DA
 	

32HNN2&3288DA
1v~9SZLSVKqABB u:D4[ZZ!THHQK"q 6:1# >* + , ,77a<8 <1 2 3 3Av:~adQhZ 8!!#N1#Q8 9 9GGBK!O  ""21# 66 7 8 8ryyq1u&'!+  ++,#Q0 1 1{{2""$$21# 6. / 0 0) 2 %1%%Eryye5u=G::gRWW577<<>L u:D$%uSWuE%	4U$E	2BGGBFFO4[ %ns58}n JJuBHH-ERK''k  DI 4T &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              ?rt   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   F  s   
 
}}QWWb00111fff<<1fff<<bg~vv{qwwqzA~mmAqwwqz"A$Q!Q$?;?OC1Itqy IF;.>x|A3a!PQQ # 
1/;/	19	{*;D9A>??
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  oPM     sn[        S	9n[        R                  XT5      nUR                  n[        US
U 5      [        XS
 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>~  s     ,VSVVVs   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      $"! "**VAYe<adCC"s   69r   Nr   atolgư>)r'   r3   rx   	enumerater
   
atleast_1dr#   r$   r   	itertoolsproductrB   r   ri   r!   r   rC   sslspsolve	functoolspartialr   )r   valuesr&   r   r   r"   rM   r*   pointnumptsr%   xvrb   matrv_shape
vals_shapevalscoefs   ` `               r   make_ndbsplr   ^  s   > v;D,V,,HA
 f%R]]5)*QqT>z&1Fqc J++,Q4& 1!!"1a(>@ A A & 	 $T{$ 	$AJJY%6%6%?@%?r%?@NE ""5Q/D
 llGwu~&WU^(<=J>>*%D"";v>$"&K$,,D<<45>12DQa  C  DI As   F F,F)(F))   )r   r   ry   numpyr
   mathr    r   scipy.sparse.linalgsparselinalgr   scipy.sparser   	_bsplinesr   __all__r   r   r   gcrotmkr   r   r[   r   r   <module>r      sc          ! ! " "-]2 ]2@I(X ![[ 0E!s{{ E!r   