
      iJ                     .    d dl Z d dlmZmZ i Zd ZddZy)    N)rfftirfftc                     	 t         |    S # t        $ r Y nw xY wt        | t              r| dkD  sJ | }	 |}dD ]  }||z  dk(  s||z  }||z  dk(  r |dk(  r|t         | <   |S |dz  }6)a7  
    Returns the next largest number ``n >= size`` whose prime factors are all
    2, 3, or 5. These sizes are efficient for fast fourier transforms.
    Equivalent to :func:`scipy.fftpack.next_fast_len`.

    Note: This function was originally copied from the https://github.com/pyro-ppl/pyro
    repository, where the license was Apache 2.0. Any modifications to the original code can be
    found at https://github.com/asteroid-team/torch-audiomentations/commits

    :param int size: A positive number.
    :returns: A possibly larger number.
    :rtype int:
    r   )            )_NEXT_FAST_LENKeyError
isinstanceint)size	next_size	remainingns       |/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torch_audiomentations/utils/convolution.pynext_fast_lenr      s    d##  dC TAX--I
	Aa-1$a	 a-1$  >#,N4 Q	 s    	c                    | j                  d      }|j                  d      }|dk(  r	||z   dz
  }nN|dk(  rt        ||      t        ||      z
  dz   }n,|dk(  rt        ||      }nt        dj	                  |            ||z   dz
  }t        |      }t        | |      }t        ||      }	||	z  }
t        |
|      }||z
  dz  }|d	|||z   f   S )
a  
    Computes the 1-d convolution of signal by kernel using FFTs.
    The two arguments should have the same rightmost dim, but may otherwise be
    arbitrarily broadcastable.

    Note: This function was originally copied from the https://github.com/pyro-ppl/pyro
    repository, where the license was Apache 2.0. Any modifications to the original code can be
    found at https://github.com/asteroid-team/torch-audiomentations/commits

    :param torch.Tensor signal: A signal to convolve.
    :param torch.Tensor kernel: A convolution kernel.
    :param str mode: One of: 'full', 'valid', 'same'.
    :return: A tensor with broadcasted shape. Letting ``m = signal.size(-1)``
        and ``n = kernel.size(-1)``, the rightmost size of the result will be:
        ``m + n - 1`` if mode is 'full';
        ``max(m, n) - min(m, n) + 1`` if mode is 'valid'; or
        ``max(m, n)`` if mode is 'same'.
    :rtype torch.Tensor:
    fullr	   validsamezUnknown mode: {})r   r   .)r   maxmin
ValueErrorformatr   r   r   )signalkernelmodemr   truncatepadded_sizefast_ftt_sizef_signalf_kernelf_resultresult	start_idxs                r   convolver)   (   s    ( 	BABAv~q519	q!9s1ay(1,	q!9+224899 a%!)K!+.MFm,HFm,H("H8}-Fx'A-I#y9x#77788    )r   )torchtorch_audiomentations.utils.fftr   r   r
   r   r)    r*   r   <module>r.      s     7@)9r*   