o
    X۷i                     @  s^   d dl mZ d dlZd dlZd dlZd dlmZ dd Zg dZdZ	dd	 Z
ejd
d ZdS )    )annotationsN)_utilc                 C  s|   t |  t | | jd |jd krtd| dddtjddf |dtjddddf  }|d|jdd  S )av  
    Khatri-rao product

    A column-wise Kronecker product of two matrices

    Parameters
    ----------
    a : (n, k) array_like
        Input array
    b : (m, k) array_like
        Input array

    Returns
    -------
    c:  (n*m, k) ndarray
        Khatri-rao product of `a` and `b`.

    See Also
    --------
    .. seealso:: :func:`scipy.linalg.khatri_rao`

       z6The number of columns for both arrays should be equal..N)   )r   
_assert_2dshape
ValueErrorcupynewaxisreshape)abc r   R/home/ubuntu/vllm_env/lib/python3.10/site-packages/cupyx/scipy/linalg/_matfuncs.py
khatri_rao
   s   

4r   )g D`lCg D`\Cg `=Hb;Cg 	eCg JXBg  "5Bg  /cBg   \L8Bg   pķAg    syAg    S-Ag     @g     f@g      ?g{Gz@c                 C  s  | j dkrtjd| jdS | jd }t| jtjr| jntj}t| 	 | }| tj
||d|  }tjj|dd }|tk}|rUtttt|t d }nd}|d|  }|| }|| }	||	 }
tj
|jd |d}tjt|d}t|||	|
|\}}}}||
| |  }|
| | }tj| | || }|}t|D ]}|| }qt|jtjrt|nt|}||9 }|S )a  Compute the matrix exponential.

    Parameters
    ----------
    a : ndarray, 2D

    Returns
    -------
    matrix exponential of `a`

    Notes
    -----
    Uses (a simplified) version of Algorithm 2.3 of [1]_:
    a [13 / 13] Pade approximant with scaling and squaring.

    Simplifications:

        * we always use a [13/13] approximate
        * no matrix balancing

    References
    ----------
    .. [1] N. Higham, SIAM J. MATRIX ANAL. APPL. Vol. 26(4), p. 1179 (2005)
       https://doi.org/10.1137/04061101X

    r   )r   r   )dtyper   )ordr   )sizer
   zerosr   r   
issubdtypeinexactfloat64diagsumeyelinalgnormitemth13intmathceillog2floatasarrayr   _expm_innersolverangecomplexfloatingcmathexp)r   na_dtypemuAnrmAscalesA2A4A6Ebbu1u2v1v2uvr13x_emur   r   r   expm@   sF   


"
rC   c           	      C  s   |d | |d |  |d |  }|d | |d |  |d |  |d |   }|d | |d	 |  |d
 |  }|d | |d |  |d |  |d |   }||||fS )N      	            r      
            r   r   r   )	r7   r4   r5   r6   r   r9   r:   r;   r<   r   r   r   r'      s
   $0$0r'   )
__future__r   r"   r+   r
   cupy.linalgr   r   r   r    rC   fuser'   r   r   r   r   <module>   s    $N