
    
9j)                        S SK Jr  S SKrS SKrS SKJr  SS jrSS jr\R                  " SSSS	5      rSS \	4S
 jr
SS jrSS jrSS jrg)    )annotationsN)_corec                   [        U [        R                  5      (       a  U R                  nON[        R                  " U 5      nUS:X  a  [        R
                  " U 5      n US:X  a  [        R
                  " U 5      n US:X  aM  U R                  [        U5      -   n[        R                  " X34U R                  S9nXR                  U5      SS& U$ US:X  a%  [        R
                  " U R                  U5      5      $ [        S5      e)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        O/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/_creation/matrix.pydiagr   	   s    & !T\\""vvzz!}19

1A19AAqyvvAjj$QWW5Q
	zz!**Q-((344    c                    [         R                  " U 5      (       a  [         R                  " U 5      n [        R                  " U R                  5       U5      $ )a)  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   1   s8     ~~aMM!99QWWY""r   zint32 m, int32 kzT outzK
    int row = i / m;
    int col = i % m;
    out = (col <= row + k);
    cupy_tric                P    Uc  U n[         R                  " X4US9n[        XU5      $ )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`

r   )r   empty_tri_kernel)NMr   r	   outs        r   trir'   P   s-    " 	y
**aV5
)CqS!!r   c                    [         R                  " U 5      n [        U R                  SS U[        S.6n[         R
                  " X U R                  R                  S5      5      $ )aY  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   trilr3   h   sF     	QA.D::dqww||A//r   c                    [         R                  " U 5      n [        U R                  SS US-
  [        S.6n[         R
                  " X R                  R                  S5      U 5      $ )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+   r0   s      r   triur5   }   sJ     	QA!40D::dGGLLOQ//r   c                   [         R                  " U 5      n U R                  S:w  a  [        S5      eUc  [	        U 5      n[         R
                  " [	        U 5      U4[        R                  " U R                  [        5      S9nU(       d  USS2SSS24   OUn[         R                  " U R                  SS5      [         R                  " U5      US9  U$ )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   vanderrA      s    " 	QAvv{IJJyF

CFA;e&9&9!''3&GHA&!AttG*ACJJqyyQQS9Hr   )r   )NF)
__future__r   r   r   r   r   r   ElementwiseKernelr#   floatr'   r3   r5   rA    r   r   <module>rF      s[    "   %5P#& %%
 	 Qe "00*0*r   