
    
9j                    8    S SK Jr  S SKrS rS rSS jrSS jrg)    )annotationsNc                   [         R                  R                  R                  US5      nUS:  a  [	        S5      eU R
                  S:X  a  U R                  5       n U R                  R                  S;   a  [         R                  OU R                  nU [         R                  " US-   US9R                  SSU R
                  -  -   5      -  n[         R                  " USS	5      $ )
zComputes the Vandermonde matrix of given degree.

Args:
    x (cupy.ndarray): array of points
    deg (int): degree of the resulting matrix.

Returns:
    cupy.ndarray: The Vandermonde matrix

.. seealso:: :func:`numpy.polynomial.polynomial.polyvander`

degr   zdegree must be non-negativebiu   )dtype)r   r	   )cupy
polynomial	polyutils_as_int
ValueErrorndimravelr   kindfloat64arangereshapemoveaxis)xr   r   outs       T/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/polynomial/polynomial.py
polyvanderr      s     //
#
#
+
+C
7C
Qw677vv{GGIGGLLE1DLLqwwE
t{{37%0889NO
OC==a$$    c                   [         R                  R                  R                  U /5      u  n U R                  S-
  nUS:X  a  [        S5      e[         R                  " USU R                  S9nUSS2S4==   U SS U S   -  -  ss'   U$ )a  Computes the companion matrix of c.

Args:
    c (cupy.ndarray): 1-D array of polynomial coefficients
        ordered from low to high degree.

Returns:
    cupy.ndarray: Companion matrix of dimensions (deg, deg).

.. seealso:: :func:`numpy.polynomial.polynomial.polycompanion`

r   r   z.Series must have maximum degree of at least 1.r	   )kr   N)r   r   r   	as_seriessizer   eyer   )cr   matrixs      r   polycompanionr#      s}     //
#
#
-
-qc
2CQ
&&1*C
axIJJXXcRqww/F
1b5MQsVae^#MMr   c                   [         R                  " USSS9nUR                  R                  S;   a  US-   n[	        U [
        [        45      (       a  [         R                  " U 5      n [	        U [         R                  5      (       a2  U(       a+  UR                  UR                  SU R                  -  -   5      nUS   U S-  -   n[        S	[        U5      S-   5       H  nX*    X0-  -   nM     U$ )
aG  
Evaluate a polynomial at points x.

If `c` is of length `n + 1`, this function returns the value

.. math:: p(x) = c_0 + c_1 * x + ... + c_n * x^n

The parameter `x` is converted to an array only if it is a tuple or a
list, otherwise it is treated as a scalar. In either case, either `x`
or its elements must support multiplication and addition both with
themselves and with the elements of `c`.

If `c` is a 1-D array, then `p(x)` will have the same shape as `x`.  If
`c` is multidimensional, then the shape of the result depends on the
value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
scalars have shape (,).

Trailing zeros in the coefficients will be used in the evaluation, so
they should be avoided if efficiency is a concern.

Parameters
----------
x : array_like, compatible object
    If `x` is a list or tuple, it is converted to an ndarray, otherwise
    it is left unchanged and treated as a scalar. In either case, `x`
    or its elements must support addition and multiplication with
    with themselves and with the elements of `c`.
c : array_like
    Array of coefficients ordered so that the coefficients for terms of
    degree n are contained in c[n]. If `c` is multidimensional the
    remaining indices enumerate multiple polynomials. In the two
    dimensional case the coefficients may be thought of as stored in
    the columns of `c`.
tensor : boolean, optional
    If True, the shape of the coefficient array is extended with ones
    on the right, one for each dimension of `x`. Scalars have dimension 0
    for this action. The result is that every column of coefficients in
    `c` is evaluated for every element of `x`. If False, `x` is broadcast
    over the columns of `c` for the evaluation.  This keyword is useful
    when `c` is multidimensional. The default value is True.

Returns
-------
values : ndarray, compatible object
    The shape of the returned array is described above.

See Also
--------
numpy.polynomial.polynomial.polyval

Notes
-----
The evaluation uses Horner's method.

r   Fndmincopy?bBhHiIlLqQpPg        r
   r	   r      )r   arrayr   char
isinstancetuplelistasarrayndarrayr   shaper   rangelen)r   r!   tensorc0is        r   polyvalr7   3   s    r 	

1AE*Aww||&G!eT]##LLO!T\\""vIIaggQVV+,	
21B1c!fqj!rURT\ "Ir   c                   [         R                  " USSS9nUR                  R                  S;   a  UR	                  [         R
                  5      n[        U [        [        45      (       a  [         R                  " U 5      n [        U [         R                  5      (       aX  U(       a,  UR                  UR                  SU R                  -  -   5      nO%U R                  UR                  :  a  [        S5      e[         R                  " X-
  SS9$ )	a5  
Evaluate a polynomial specified by its roots at points x.

If `r` is of length `N`, this function returns the value

.. math:: p(x) = \prod_{n=1}^{N} (x - r_n)

The parameter `x` is converted to an array only if it is a tuple or a
list, otherwise it is treated as a scalar. In either case, either `x`
or its elements must support multiplication and addition both with
themselves and with the elements of `r`.

If `r` is a 1-D array, then `p(x)` will have the same shape as `x`.  If `r`
is multidimensional, then the shape of the result depends on the value of
`tensor`. If `tensor` is ``True`` the shape will be r.shape[1:] + x.shape;
that is, each polynomial is evaluated at every value of `x`. If `tensor` is
``False``, the shape will be r.shape[1:]; that is, each polynomial is
evaluated only for the corresponding broadcast value of `x`. Note that
scalars have shape (,).

Parameters
----------
x : array_like, compatible object
    If `x` is a list or tuple, it is converted to an ndarray, otherwise
    it is left unchanged and treated as a scalar. In either case, `x`
    or its elements must support addition and multiplication with
    with themselves and with the elements of `r`.
r : array_like
    Array of roots. If `r` is multidimensional the first index is the
    root index, while the remaining indices enumerate multiple
    polynomials. For instance, in the two dimensional case the roots
    of each polynomial may be thought of as stored in the columns of `r`.
tensor : boolean, optional
    If True, the shape of the roots array is extended with ones on the
    right, one for each dimension of `x`. Scalars have dimension 0 for this
    action. The result is that every column of coefficients in `r` is
    evaluated for every element of `x`. If False, `x` is broadcast over the
    columns of `r` for the evaluation.  This keyword is useful when `r` is
    multidimensional. The default value is True.

Returns
-------
values : ndarray, compatible object
    The shape of the returned array is described above.

See Also
--------
numpy.polynomial.polynomial.polyvalfroomroots
r   Fr%   r(   r
   z,x.ndim must be < r.ndim when tensor == Falser   )axis)r   r*   r   r+   astypedoubler,   r-   r.   r/   r0   r   r1   r   r   prod)r   rr4   s      r   polyvalfromrootsr>   {   s    d 	

1AE*Aww||&HHT[[!!eT]##LLO!T\\""		!''DK/0AVVqvvKLL99QU##r   )T)
__future__r   r   r   r#   r7   r>    r   r   <module>rA      s!    " %.,EP<$r   