
    `i                     ~    d dl Z d dlZd dlmZ ddZddZ ej        dddd          Zdd efd	Zdd
Z	ddZ
ddZdS )    N)_corec                    t          | t          j                  r| j        }nHt	          j        |           }|dk    rt          j        |           } |dk    rt	          j        |           } |dk    rP| j        t          |          z   }t          j        ||f| j	                  }| |
                    |          dd<   |S |dk    r't          j        | 
                    |                    S t          d          )a  Returns a diagonal or a diagonal array.

    Args:
        v (array-like): Array or array-like object.
        k (int): Index of diagonals. Zero indicates the main diagonal, a
            positive value an upper diagonal, and a negative value a lower
            diagonal.

    Returns:
        cupy.ndarray: If ``v`` indicates a 1-D array, then it returns a 2-D
        array with the specified diagonal filled by ``v``. If ``v`` indicates a
        2-D array, then it returns the specified diagonal of ``v``. In latter
        case, if ``v`` is a :class:`cupy.ndarray` object, then its view is
        returned.

    .. seealso:: :func:`numpy.diag`

          dtypeNzInput must be 1- or 2-d.)
isinstancecupyndarrayndimnumpyarraysizeabszerosr   diagonal
ValueError)vkr   r   rets        i/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/_creation/matrix.pydiagr      s    & !T\"" vz!}}199
1A199AAqyyvAj$QW555Q
	z!**Q--(((3444    c                     t          j        |           rt          j        |           } t          j        |                                 |          S )aE  Creates a diagonal array from the flattened input.

    Args:
        v (array-like): Array or array-like object.
        k (int): Index of diagonals. See :func:`cupy.diag` for detail.

    Returns:
        cupy.ndarray: A 2-D diagonal array with the diagonal copied from ``v``.

    .. seealso:: :func:`numpy.diagflat`

    )r   isscalarasarrayr
   r   ravel)r   r   s     r   diagflatr   /   s?     ~a M!9QWWYY"""r   zint32 m, int32 kzT outzK
    int row = i / m;
    int col = i % m;
    out = (col <= row + k);
    cupy_tric                 \    || }t          j        | |f|          }t          |||          S )a  Creates an array with ones at and below the given diagonal.

    Args:
        N (int): Number of rows.
        M (int): Number of columns. ``M == N`` by default.
        k (int): The sub-diagonal at and below which the array is filled. Zero
            is the main diagonal, a positive value is above it, and a negative
            value is below.
        dtype: Data type specifier.

    Returns:
        cupy.ndarray: An array with ones at and below the given diagonal.

    .. seealso:: :func:`numpy.tri`

    Nr   )r
   empty_tri_kernel)NMr   r   outs        r   trir&   N   s8    " 	y
*aV5
)
)
)Cq!S!!!r   c                     t          j        |           } t          | j        dd         |t          d}t          j        || | j                            d                    S )a}  Returns a lower triangle of an array.

    Args:
        m (array-like): Array or array-like object.
        k (int): The diagonal above which to zero elements. Zero is the main
            diagonal, a positive value is above it, and a negative value is
            below.

    Returns:
        cupy.ndarray: A lower triangle of an array.

    .. seealso:: :func:`numpy.tril`

    Nr   r   r   r
   r   r&   shapeboolwherer   typemr   masks      r   trilr2   f   sO     	QA...D:dAqw||A///r   c                     t          j        |           } t          | j        dd         |dz
  t          d}t          j        || j                            d          |           S )a  Returns an upper triangle of an array.

    Args:
        m (array-like): Array or array-like object.
        k (int): The diagonal below which to zero elements. Zero is the main
            diagonal, a positive value is above it, and a negative value is
            below.

    Returns:
        cupy.ndarray: An upper triangle of an array.

    .. seealso:: :func:`numpy.triu`

    r(   Nr   r)   r   r*   r/   s      r   triur4   {   sS     	QA!4000D:dAGLLOOQ///r   Fc                    t          j        |           } | j        dk    rt          d          |t	          |           }t          j        t	          |           |ft          j        | j        t                              }|s|dddddf         n|}t          j
        |                     dd          t          j        |          |           |S )a  Returns a Vandermonde matrix.

    Args:
        x (array-like): 1-D array or array-like object.
        N (int, optional): Number of columns in the output.
            ``N = len(x)`` by default.
        increasing (bool, optional): Order of the powers of the columns.
            If True, the powers increase from right to left,
            if False (the default) they are reversed.

    Returns:
        cupy.ndarray: A Vandermonde matrix.

    .. seealso:: :func:`numpy.vander`

    r   z.x must be a one-dimensional array or sequence.Nr   )r%   )r
   r   r   r   lenr!   r   promote_typesr   intpowerreshapearange)xr#   
increasingr   tmps        r   vanderr@      s    " 	QAv{{IJJJyFF
CFFA;e&9!'3&G&GHHHA&
-!AAAtttG**ACJqyyQQS9999Hr   )r   )NF)r   r
   r   r   r   ElementwiseKernelr"   floatr&   r2   r4   r@    r   r   <module>rD      s           %5 %5 %5 %5P# # # #& &e%
 	 	 Qe " " " "00 0 0 0*0 0 0 0*     r   