
    `i}                     *    d dl Z d Zd ZddZddZdS )    Nc                    t           j        j                            |d          }|dk     rt	          d          | j        dk    r|                                 } | j        j        dv rt           j	        n| j        }| t          j
        |dz   |                              dd| j        z  z             z  }t          j        |dd	          S )
a  Computes 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_deprecate_as_int
ValueErrorndimravelr   kindfloat64arangereshapemoveaxis)xr   r   outs       n/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/polynomial/polynomial.py
polyvanderr      s     /
#
5
5c5
A
AC
Qww6777v{{GGIIGLE11DLLqwE
t{37%000889NOO
OC=a$$$    c                    t           j        j                            | g          \  } | j        dz
  }|dk    rt          d          t          j        |d| j                  }|dddfxx         | dd         | d         z  z  cc<   |S )a3  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
2
2CQ
&1*C
axxIJJJXcRqw///F
111b5MMMQssVae^#MMMMr   Tc                    t          j        |dd          }|j        j        dv r|dz   }t	          | t
          t          f          rt          j        |           } t	          | t           j                  r'|r%|	                    |j
        d| j        z  z             }|d         | dz  z   }t          d	t          |          dz             D ]}||          || z  z   }|S )
a  
    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   polyvalr6   1   s    r 	
1AE***Aw|&&G!eT]## LOO!T\"" -v -IIagQV+,,	
21B1c!ffqj!!  rURT\Ir   c                    t          j        |dd          }|j        j        dv r|                    t           j                  }t          | t          t          f          rt          j	        |           } t          | t           j
                  rG|r&|                    |j        d| j        z  z             }n| j        |j        k    rt          d          t          j        | |z
  d          S )	a  
    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.   r/   r   r0   r   r   prod)r   rr3   s      r   polyvalfromrootsr=   y   s    d 	
1AE***Aw|&&HHT[!!!eT]## LOO!T\"" M 	M		!'DK/00AAVqvKLLL9QU####r   )T)r
   r   r"   r6   r=    r   r   <module>r?      sc    % % %.  ,E E E EP<$ <$ <$ <$ <$ <$r   