o
    pi                     @   sR   d dl Z d dlmZ d dlmZ d dlZd dlmZ d dl	m
Z
 G dd dZdS )    N)Path)Optional)download_from_hf_hub)	vbx_setupc                   @   s   e Zd Zd Z	ddeeB deeB defddZedd Z	d	e
jfd
dZe				ddeeB dedB dedB dedB deeB dB ded  fddZdS )PLDA   transform_npzplda_npzlda_dimensionc                 C   s    t ||\| _| _| _|| _d S )N)r   _xvec_tf_plda_tf	_plda_psir
   )selfr   r	   r
    r   L/home/ubuntu/.local/lib/python3.10/site-packages/pyannote/audio/core/plda.py__init__$   s   
zPLDA.__init__c                 C   s   | j d| j S )z+Between-class covariance in the PLDA space.N)r   r
   )r   r   r   r   phi-   s   zPLDA.phi
embeddingsc                 C   s   | j | || jdS )a@  

        Parameters
        ----------
        embeddings : (num_embeddings, embedding_dimension) ndarray
            Embeddings to be transformed into the PLDA space.

        Returns
        -------
        fea : (num_embeddings, lda_dimension) ndarray
            Embeddings transformed into the PLDA space.
        )lda_dim)r   r   r
   )r   r   r   r   r   __call__2   s   zPLDA.__call__N
checkpoint	subfolderrevisiontoken	cache_dirreturnc           	      K   s   t j|r.|durtd|r!t|| d }t|| d }n7t|d }t|d }n*t|}d|v r:tdt|d||||d}t|d||||d}|du sV|du rXdS | ||S )a  Load PLDA from disk or Huggingface Hub

        Parameters
        ----------
        checkpoint : Path or str
            Path to checkpoint or a model identifier from the hf.co model hub.
        subfolder : str, optional
            Folder inside the hf.co model repo.
        revision : str, optional
            Revision when loading from the huggingface.co model hub.
        token : str, optional
            When loading a private hf.co model, set `token`
            to True or to a string containing your hugginface.co authentication
            token that can be obtained by running `huggingface-cli login`
        cache_dir: Path or str, optional
            Path to model cache directory.
        Nz0Revisions cannot be used with local checkpoints.zxvec_transform.npzzplda.npz@z:Revisions must be passed with `revision` keyword argument.)r   r   r   r   )ospathisdir
ValueErrorr   strr   )	clsr   r   r   r   r   kwargspath_to_transformpath_to_pldar   r   r   from_pretrainedA   s@   		
zPLDA.from_pretrained)r   )NNNN)__name__
__module____qualname____doc__r!   r   intr   propertyr   npndarrayr   classmethodr   r&   r   r   r   r   r   !   s>    
	

r   )r   pathlibr   typingr   numpyr-   pyannote.audio.utils.hf_hubr   pyannote.audio.utils.vbxr   r   r   r   r   r   <module>   s   