class_docstr: Resampling from the sample rate `old_sr` to `new_sr`.
class_docstr_tok: ["Resampling","from","the","sample","rate","`","old_sr","`","to","`","new_sr","`","."]
docstr: Resample x.
  Args:
      x (Tensor): signal to resample, time should be the last dimension
      output_length (None or int): This can be set to the desired output length
          (last dimension). Allowed values are between 0 and
          ceil(length * new_sr / old_sr). When None (default) is specified, the
          floored output length will be used. In order to select the largest possible
          size, use the `full` argument.
      full (bool): return the longest possible output from the input. This can be useful
          if you chain resampling operations, and want to give the `output_length` only
          for the last one, while passing `full=True` to all the other ones.
docstr_tok: ["Resample","x.","Args",":","x","(","Tensor",")",":","signal","to","resample",",","time","should","be","the","last","dimension","output_length","(","None","or","int",")",":","This","can","be","set","to","the","desired","output","length","(","last","dimension",")",".","Allowed","values","are","between","0","and","ceil","(","length","*","new_sr","\/","old_sr",")",".","When","None","(","default",")","is","specified",",","the","floored","output","length","will","be","used",".","In","order","to","select","the","largest","possible","size",",","use","the","`","full","`","argument",".","full","(","bool",")",":","return","the","longest","possible","output","from","the","input",".","This","can","be","useful","if","you","chain","resampling","operations",",","and","want","to","give","the","`","output_length","`","only","for","the","last","one",",","while","passing","`","full=True","`","to","all","the","other","ones","."]
code: def forward(
      self,
      x: torch.Tensor,
      output_length: Optional[int] = None,
      full: bool = False,
  ):
      """
      Resample x.
      Args:
          x (Tensor): signal to resample, time should be the last dimension
          output_length (None or int): This can be set to the desired output length
              (last dimension). Allowed values are between 0 and
              ceil(length * new_sr / old_sr). When None (default) is specified, the
              floored output length will be used. In order to select the largest possible
              size, use the `full` argument.
          full (bool): return the longest possible output from the input. This can be useful
              if you chain resampling operations, and want to give the `output_length` only
              for the last one, while passing `full=True` to all the other ones.
      """
      if self.old_sr == self.new_sr:
          return x
      shape = x.shape
      length = x.shape[-1]
      x = x.reshape(-1, length)
      x = F.pad(
          x[:, None],
          (self._width, self._width + self.old_sr),
          mode="replicate",
      )
      ys = F.conv1d(x, self.kernel, stride=self.old_sr)  # type: ignore
      y = ys.transpose(1, 2).reshape(list(shape[:-1]) + [-1])
  
      float_output_length = torch.as_tensor(
          self.new_sr * length / self.old_sr
      )
      max_output_length = torch.ceil(float_output_length).long()
      default_output_length = torch.floor(float_output_length).long()
  
      if output_length is None:
          applied_output_length = (
              max_output_length if full else default_output_length
          )
      elif output_length < 0 or output_length > max_output_length:
          raise ValueError(
              f"output_length must be between 0 and {max_output_length}"
          )
      else:
          applied_output_length = torch.tensor(output_length)
          if full:
              raise ValueError(
                  "You cannot pass both full=True and output_length"
              )
      return y[..., :applied_output_length]
  
file_path: julius/julius/resample.py
imports: import math
  from typing import Optional
  import torch
  from torch.nn import functional
  from .core import sinc
  from .utils import simple_repr
label_desc: Use image node_id 3 for calling the ResampleFrac obj's underlying member method code with example usage: obj.forward(x, output_length, full) and returns: y, x