ó
    Eñiæ  ã            	       ó�   • S r SSKJr  SSKJr  S rS rS rS rS	 r	S
 r
S rS rS rS r\\\	\
\\\\S.rS rS rS rS rS rg)aj  
'Generic' Array API backend for RBF interpolation.

The general logic is this: `_rbfinterp.py` implements the user API and calls
into either `_rbfinterp_np` (the "numpy backend"), or `_rbfinterp_xp` (the
"generic backend".

The numpy backend offloads performance-critical computations to the
pythran-compiled `_rbfinterp_pythran` extension. This way, the call chain is

    _rbfinterp.py <-- _rbfinterp_np.py <-- _rbfinterp_pythran.py

The "generic" backend here is a drop-in replacement of the API of
`_rbfinterp_np.py` for use in `_rbfinterp.py` with non-numpy arrays.

The implementation closely follows `_rbfinterp_np + _rbfinterp_pythran`, with
the following differences:

  -  We used vectorized code not explicit loops in `_build_system` and
     `_build_evaluation_coefficients`; this is more torch/jax friendly;
  - RBF kernels are also "vectorized" and not scalar: they receive an
    array of norms not a single norm;
  - RBF kernels accept an extra xp= argument;

In general, we would prefer less code duplication. The main blocker ATM is
that pythran cannot compile functions with an xp= argument where xp is numpy.
é    )ÚLinAlgErroré   )Ú_monomial_powers_implc                 óŒ   • [        X5      nUR                  U5      nUR                  S   S:X  a  UR                  USU 45      nU$ )Nr   )r   ÚasarrayÚshapeÚreshape)ÚndimÚdegreeÚxpÚouts       Ú\/home/mande/repo/quber/.venv/lib/python3.13/site-packages/scipy/interpolate/_rbfinterp_xp.pyÚ_monomial_powersr       sB   € Ü
 Ó
-€CØ
�*‰*�S‹/€CØ
‡y�y��|�qÓØ�j‰j˜˜q $˜iÓ(ˆØ€Jó    c           	      ó4  • [        XX#XEU5      u  pxpš UR                  R                  Xx5      nXšU4$ ! [         a[    SnUR                  S   nUS:”  a8  [        X	-
  U
-  XVS9nUR                  R                  U5      nXý:  a	  SU SU S3n[        U5      ef = f)a¤  Build and solve the RBF interpolation system of equations.

Parameters
----------
y : (P, N) float ndarray
    Data point coordinates.
d : (P, S) float ndarray
    Data values at `y`.
smoothing : (P,) float ndarray
    Smoothing parameter for each data point.
kernel : str
    Name of the RBF.
epsilon : float
    Shape parameter.
powers : (R, N) int ndarray
    The exponents for each monomial in the polynomial.

Returns
-------
coeffs : (P + R, S) float ndarray
    Coefficients for each RBF and monomial.
shift : (N,) float ndarray
    Domain shift used to create the polynomial matrix.
scale : (N,) float ndarray
    Domain scaling used to create the polynomial matrix.

zSingular matrixr   )r   zqSingular matrix. The matrix of monomials evaluated at the data point coordinates does not have full column rank (Ú/z).)Ú_build_systemÚlinalgÚsolveÚ	Exceptionr   Úpolynomial_matrixÚmatrix_rankr   )ÚyÚdÚ	smoothingÚkernelÚepsilonÚpowersr   ÚlhsÚrhsÚshiftÚscaleÚcoeffsÚmsgÚnmonosÚpmatÚranks                   r   Ú_build_and_solve_systemr(   (   sÁ   € ô8 +Ø	ˆi °"ó
Ñ€CˆeðØ—‘—‘ Ó*ˆð& ˜ÐÐøô% ó ð
  ˆØ—‘˜a‘ˆØ�A‹:Ü$ a¡i°Ñ%6¸ÑFˆDØ—9‘9×(Ñ(¨Ó.ˆDØ‹}ðà!˜F ! F 8¨2ð/ð ô
 ˜#ÓÐð!ús
   “2 ²A%Bc                 ó   • U * $ ©N© ©Úrr   s     r   Úlinearr.   ^   s	   € Øˆ2€Ir   c                 óX   • UR                  U S:H  SU S-  UR                  U 5      -  5      $ )Nr   é   )ÚwhereÚlogr,   s     r   Úthin_plate_spliner3   b   s*   € à�8‰8�A˜‘F˜A˜q !™t b§f¡f¨Q£iÑ/Ó0Ð0r   c                 ó   • U S-  $ )Né   r+   r,   s     r   Úcubicr6   g   s   € Øˆa‰4€Kr   c                 ó   • U S-  * $ )Né   r+   r,   s     r   Úquinticr9   k   s   € Øˆq‰Dˆ5€Lr   c                 ó2   • UR                  U S-  S-   5      * $ )Nr0   r   ©Úsqrtr,   s     r   Úmultiquadricr=   o   s   € Ø�G‰G�A�q‘D˜1‘HÓÐÐr   c                 ó6   • SUR                  U S-  S-   5      -  $ ©Nç      ð?r0   r;   r,   s     r   Úinverse_multiquadricrA   s   s   € Ø�—‘˜˜A™ ™Ó$Ñ$Ð$r   c                 ó   • SU S-  S-   -  $ r?   r+   r,   s     r   Úinverse_quadraticrC   w   s   € Ø�!�Q‘$˜‘*ÑÐr   c                 ó,   • UR                  U S-  * 5      $ )Nr0   )Úexpr,   s     r   ÚgaussianrF   {   s   € Ø�6‰6�1�a‘4�%‹=Ðr   )r.   r3   r6   r9   r=   rA   rC   rF   c           
      ór   • U" UR                   R                  U SSS2SS24   U SS2SSS24   -
  SS9U5      $ )z+Evaluate RBFs, with centers at `x`, at `x`.Néÿÿÿÿ©Úaxis)r   Úvector_norm)ÚxÚkernel_funcr   s      r   Úkernel_matrixrN   ‹   sA   € áØ
�	‰	×Ñ˜a ¢aª 
™m¨a²°4º°
©mÑ;À"ÐÐEÀróð r   c                 ó<   • UR                  U SS2SSS24   U-  SS9$ )z9Evaluate monomials, with exponents from `powers`, at `x`.NrH   rI   )Úprod)rL   r   r   s      r   r   r   ’   s$   € à�7‰7�1’Q˜ša�Z‘= FÑ*°ˆ7Ð4Ð4r   c           
      ód  • UR                   S   nUR                   S   n[        U   n	UR                  U SS9n
UR                  U SS9nXº-   S-  nXº-
  S-  nUR	                  US:H  SU5      nX-  nX-
  U-  n[        XéU5      n[        XõU5      nUR                  UR                  UU4SS9UR                  UR                  UR                  Xˆ45      4SS9/SS9UR                  UR                  X&R                  U5      /5      5      -   nUR                  XR                  X‡45      /SS9nUUXÍ4$ )aÙ  Build the system used to solve for the RBF interpolant coefficients.

Parameters
----------
y : (P, N) float ndarray
    Data point coordinates.
d : (P, S) float ndarray
    Data values at `y`.
smoothing : (P,) float ndarray
    Smoothing parameter for each data point.
kernel : str
    Name of the RBF.
epsilon : float
    Shape parameter.
powers : (R, N) int ndarray
    The exponents for each monomial in the polynomial.

Returns
-------
lhs : (P + R, P + R) float ndarray
    Left-hand side matrix.
rhs : (P + R, S) float ndarray
    Right-hand side matrix.
shift : (N,) float ndarray
    Domain shift used to create the polynomial matrix.
scale : (N,) float ndarray
    Domain scaling used to create the polynomial matrix.

r   r   rI   r0   g        r@   )r   ÚNAME_TO_FUNCÚminÚmaxr1   rN   r   ÚconcatÚTÚzerosÚdiag)r   r   r   r   r   r   r   Úsr-   rM   ÚminsÚmaxsr!   r"   ÚyepsÚyhatÚout_kernelsÚout_polyr   r    s                       r   r   r   —   sS  € ð< 	
�‰�‰
€AØ�‰�Q‰€AÜ˜vÑ&€Kð �6‰6�!˜!ˆ6Ð€DØ�6‰6�!˜!ˆ6Ð€DØ‰[˜!‰O€EØ‰[˜!‰O€Eð �H‰H�U˜c‘\ 3¨Ó.€Eà‰9€DØ‰I�uÑ€Dä  °BÓ7€KÜ  ¨rÓ2€Hà
�)‰)à	�‰�K Ð*°ˆÐ	3Ø	�‰�H—J‘J §¡¨!¨Ó 0Ð1¸ˆÐ	:ð	
ð ð ð ð
 —‘˜Ÿ	™	 9¯h©h°q«kÐ":Ó;Ó<ñ=€Cð �)‰)�QŸ™ ! Ó(Ð)°ˆ)Ð
2€Cà��UÐ!Ð!r   c                 óü   • [         U   nX-  n	X-  n
X-
  U-  nUR                  U" UR                  R                  U
SS2SSS24   U	SSS2SS24   -
  SS9U5      UR	                  USS2SSS24   U-  SS9/SS9nU$ )a-  Construct the coefficients needed to evaluate
the RBF.

Parameters
----------
x : (Q, N) float ndarray
    Evaluation point coordinates.
y : (P, N) float ndarray
    Data point coordinates.
kernel : str
    Name of the RBF.
epsilon : float
    Shape parameter.
powers : (R, N) int ndarray
    The exponents for each monomial in the polynomial.
shift : (N,) float ndarray
    Shifts the polynomial domain for numerical stability.
scale : (N,) float ndarray
    Scales the polynomial domain for numerical stability.

Returns
-------
(Q, P + R) float ndarray

NrH   rI   )rR   rU   r   rK   rP   )rL   r   r   r   r   r!   r"   r   rM   r\   ÚxepsÚxhatÚvecs                r   Ú_build_evaluation_coefficientsrd   Õ   s²   € ô8 ˜vÑ&€Kà‰9€DØ‰9€DØ‰I�uÑ€Dð �)‰)áØ—	‘	×%Ñ%Øš˜D¢!˜Ñ$ t¨D²!²Q¨JÑ'7Ñ7¸bð &ð àóð
 �G‰G�Dš˜D¢!˜Ñ$¨Ñ.°RˆGÐ8ð	
ð ð ð 	€Cð €Jr   c	           
      ó&   • [        XX#XEXh5      n	X—-  $ r*   )rd   )
rL   r   r   r   r   r!   r"   r#   r   rc   s
             r   Úcompute_interpolationrf     s   € Ü
(Ø	ˆf˜v¨eó€Cð ‰<Ðr   N)Ú__doc__Únumpy.linalgr   Ú_rbfinterp_commonr   r   r(   r.   r3   r6   r9   r=   rA   rC   rF   rR   rN   r   r   rd   rf   r+   r   r   Ú<module>rj      s�   ðñõ6 %Ý 4òò3 òlò1ò
òòò%òòð
 Ø)ØØØØ/Ø)Øñ	€òò5ò
;"ò|.óbr   