o
    i                     @   sd  d dl mZmZ d dlZddlmZmZmZ 			ddej	dej	dee
 d	ee d
ee
 dej	fddZ		ddej	dej	dee
 d	ee dej	f
ddZ		ddej	dej	dee
 d	ee dej	f
ddZ				ddej	dej	dee
 d	ee dee
 dee
 deej	df fddZ				ddej	dej	dee
 d	ee dee
 dee dej	fddZdS )     )OptionalTupleN   )sdr_losssdrbss_eval_sourcesFestref	zero_meanclamp_dbpairwisereturnc                 C   s   t | |d|||dS )Nr   )filter_lengthr
   r   r   )r   )r   r	   r
   r   r    r   W/home/ubuntu/.local/lib/python3.10/site-packages/fast_bss_eval/numpy/scale_invariant.pysi_sdr_loss   s   r   c              	   C   s   t || d||dddS )Nr   FT)r   r
   r   return_permchange_signr   r   r	   r
   r   r   r   r   si_sdr_pit_loss   s   r   c                 C   s   t | |||ddS )NT)r
   r   r   )r   r   r   r   r   pairwise_si_sdr_loss)   s   r   r   r   .c              
   C      t | |dd||||dS )a  
    Compute the scale-invariant signal-to-distortion ratio (SI-SDR) only.

    This function computes the SDR for all pairs of est/ref signals and finds the
    permutation maximizing the SDR.

    The order of ref/est follows the convention of bss_eval (i.e., ref first).

    Parameters
    ----------
    ref: numpy.ndarray (..., n_channels_est, n_samples)
        The estimated signals
    est: numpy.ndarray (..., n_channels_ref, n_samples)
        The groundtruth reference signals
    filter_length: int, optional
        The length of the distortion filter allowed (default: ``512``)
    use_cg_iter: int, optional
        If provided, an iterative method is used to solve for the distortion
        filter coefficients instead of direct Gaussian elimination.
        This can speed up the computation of the metrics in case the filters
        are long. Using a value of 10 here has been shown to provide
        good accuracy in most cases and is sufficient when using this
        loss to train neural separation networks.
    zero_mean: bool, optional
        When set to True, the mean of all signals is subtracted prior
        to computation of the metrics (default: ``False``)
    clamp_db: bool, optional
        If provided, the resulting metrics are clamped to be in the range ``[-clamp_db, clamp_db]``
    load_diag: float, optional
        If provided, this small value is added to the diagonal coefficients of
        the system metrics when solving for the filter coefficients.
        This can help stabilize the metric in the case where some of the reference
        signals may sometimes be zero
    return_perm: bool, optional
        If set to True, the optimal permutation of the estimated signals is
        also returned (default: ``False``)
    change_sign: bool, optional
        If set to True, the sign is flipped and the negative SDR is returned
        (default: ``False``)

    Returns
    -------
    cisdr: numpy.ndarray, (..., n_channels_est)
        The SDR of the input signal
    perm: numpy.ndarray, (..., n_channels_est), optional
        The index of the corresponding reference signal.
        Only returned if ``return_perm == True``
    r   N)r   use_cg_iterr
   r   r   r   r   )r	   r   r
   r   r   r   r   r   r   si_sdr2   s   8r   Tcompute_permutation	load_diagc              
   C   r   )a  
    This function computes the SI-SDR, SI-SIR, and SI-SAR for the input
    reference and estimated signals.

    The order of ref/est follows the convention of bss_eval (i.e., ref first).

    Parameters
    ----------
    ref: numpy.ndarray (..., n_channels_est, n_samples)
        The estimated signals
    est: numpy.ndarray (..., n_channels_ref, n_samples)
        The groundtruth reference signals
    zero_mean: bool, optional
        When set to True, the mean of all signals is subtracted prior
        to computation of the metrics (default: ``False``)
    clamp_db: bool, optional
        If provided, the resulting metrics are clamped to be in the range ``[-clamp_db, clamp_db]``
    compute_permutation: bool, optional
        When this flag is true, the optimal permutation of the estimated signals
        to maximize the SIR is computed (default: ``True``)
    load_diag: float, optional
        If provided, this small value is added to the diagonal coefficients of
        the system metrics when solving for the filter coefficients.
        This can help stabilize the metric in the case where some of the reference
        signals may sometimes be zero

    Returns
    -------
    si-sdr: numpy.ndarray, (..., n_channels_est)
        The scale-invariant signal-to-distortion-ratio (SDR)
    si-sir: numpy.ndarray, (..., n_channels_est)
        The scale-invariant signal-to-interference-ratio (SIR)
    si-sar: numpy.ndarray, (..., n_channels_est)
        The scale-invariant signal-to-interference-ratio (SIR)
    perm: numpy.ndarray, (..., n_channels_est)
        The index of the corresponding reference signal (only when
        ``compute_permutation == True``)
    r   N)r   r   r
   r   r   r   )r   )r	   r   r
   r   r   r   r   r   r   si_bss_eval_sourcesv   s   /r   )FNF)FN)FNFF)FNTN)typingr   r   numpynpmetricsr   r   r   ndarrayboolfloatr   r   r   r   r   r   r   r   r   <module>   s    



G