o
    Qi+                     @   s&   d dl mZ d dlmZ dddZdS )    )check_random_state)randomized_svd   Nc                 C   s\   |dks	t |trt|}| jd }||krtd||f t| |||d\}}}|||fS )a  
    :param X: scipy.sparse.csr_matrix
        Input matrix
    :param n_components: int
        Size of embedding dimension
    :param n_iter: int
        Maximum number of iteration. Default is 5
    :param random_state: random state
        Default is None

    Returns
    ----------
    U : numpy.ndarray
        Representation matrix of rows. shape = (n_rows, n_components)
    Sigma : numpy.ndarray
        Eigenvalue of dimension. shape = (n_components, n_components)
        Diagonal value are in decreasing order
    VT : numpy.ndarray
        Representation matrix of columns. shape = (n_components, n_cols)

    Usage
    -----
        >>> U, Sigma, VT = svd(X, n_components=100)
    N   z/n_components must be < n_features; got %d >= %d)n_iterrandom_state)
isinstanceintr   shape
ValueErrorr   )Xn_componentsr   r   
n_featuresUSigmaVT r   E/home/ubuntu/.local/lib/python3.10/site-packages/soynlp/utils/math.pysvd   s   

r   )r   N)sklearn.utilsr   sklearn.utils.extmathr   r   r   r   r   r   <module>   s    