o
    si                  	   @   sH   d dl Z dde jdede jfddZdde jd	edede jfd
dZdS )    Nfeatsdimreturnc                 C   s`   |dkrt | d|ddd|S | | j}| dddf | dddf  |dddf< |S )a  Compute delta coefficients of a tensor.

    Args:
        feats: Input features to compute deltas with.
        dim: feature dimension in the feats tensor.

    Returns:
        Tensor: Tensor of deltas.

    Examples
        >>> import torch
        >>> phase = torch.randn(2, 257, 100)
        >>> # Compute instantaneous frequency
        >>> inst_freq = compute_delta(phase, dim=-1)
        >>> # Or group delay
        >>> group_delay = compute_delta(phase, dim=-2)
    r   r   .   N)compute_delta	transpose	new_zerosshape)r   r   delta r   G/home/ubuntu/.local/lib/python3.10/site-packages/asteroid/dsp/deltas.pyr      s
   ,r   r   orderc                 C   s8   | g}t |D ]}|t|d |d qtj||dS )a  Concatenate delta coefficients of a tensor to itself.

    Args:
        feats: Input features to compute deltas with.
        order: Order of the delta e.g with order==2, compute delta of delta
            as well.
        dim: feature dimension in the feats tensor.

    Returns:
        Tensor: Concatenation of the features, the deltas and subsequent deltas.

    Examples
        >>> import torch
        >>> phase = torch.randn(2, 257, 100)
        >>> # Compute second order instantaneous frequency
        >>> phase_and_inst_freq = concat_deltas(phase, order=2, dim=-1)
        >>> # Or group delay
        >>> phase_and_group_delay = concat_deltas(phase, order=2, dim=-2)
    r   r   )rangeappendr   torchcat)r   r   r   	all_feats_r   r   r   concat_deltas   s   r   )r   )r   r   )r   Tensorintr   r   r   r   r   r   <module>   s    $