_tensor_utils Module#
_tensor_utils Module#
- waloviz._tensor_utils.broadcast_to_channels(tensor: Union[Tensor, Tuple[Tensor, Tensor]], channels: int) Union[Tensor, Tuple][source]#
- Given a hierarchical tensor object recursively broadcast all leaf tensors to have exactly 2 dimensions and the same amount of channels as the
wav.Parameters#
tensortorch.Tensor | (torch.Tensor, torch.Tensor)A hierarchical tensor object with varying amounts of channels
Returns#
objtorch.TensorA hierarchical tensor object with the same amount of channels
Raises#
ValueError- When a leaf tensor has 0 non squeezable dimensionsORWhen the initial amount of channels of a leaf tensor was larger than the target amount
- waloviz._tensor_utils.handle_dict_axes(over_curve_names: Optional[List[str]], over_curve_axes: Dict[str, str]) List[Optional[str]][source]#
- Handles the case where
over_curve_axesis a dict and converts it to a list.Parameters#
over_curve_namesList[str] | None.
over_curve_axesDict[str, str].
Returns#
over_curve_axesList[str | None].
Raises#
ValueError- When
over_curve_axeswas a dict butover_curve_nameswas not provided
- waloviz._tensor_utils.handle_dict_colors(over_curve_names: Optional[List[str]], over_curve_colors: Dict[str, str]) List[Optional[str]][source]#
- Handles the case where
over_curve_colorsis a dict and converts it to a list.Parameters#
over_curve_namesList[str] | None.
over_curve_colorsDict[str, str].
Returns#
over_curve_colorsList[str | None].
Raises#
ValueError- When
over_curve_colorswas a dict butover_curve_nameswas not provided
- waloviz._tensor_utils.handle_dict_over_curve(over_curve: Dict[str, Any], over_curve_names: Optional[List[str]]) Tuple[List[Any], List[str]][source]#
- Handles the case where
over_curveis a dict and converts it to a list.Parameters#
over_curveDict[str, Any].
over_curve_namesList[str] | None.
Returns#
over_curveList[Any].
over_curve_namesList[str].
Raises#
ValueError- When
over_curve_nameswas provided butover_curvewas a dict
- waloviz._tensor_utils.handle_list_over_curve(over_curve: List[Any], over_curve_names: Optional[List[str]], over_curve_colors: Optional[Union[List[Optional[str]], Dict[str, str]]], over_curve_axes: Optional[Union[List[Optional[str]], List[str], Dict[str, str]]]) Optional[List[str]][source]#
- Handles the case where
over_curveis a list, makes a bunch of validations and generatesover_curve_namesif None were provided.Parameters#
over_curveDict[str, Any].
over_curve_namesList[str] | None.
over_curve_colorsList[str] | None.
over_curve_axesList[str] | None.
Returns#
over_curve_namesList[str].
Raises#
ValueError- When
over_curve_nameswas provided but of a different size fromover_curveORWhenover_curve_colorswas provided but of a different size fromover_curveORWhenover_curve_axeswas provided but of a different size fromover_curve
- waloviz._tensor_utils.preprocess_over_curve(wav: Tensor, sr: int, channels: int, over_curve: Optional[Union[List[Any], Dict[str, Any], ndarray, Tensor, Tuple[Any, Any], Any]], over_curve_names: Optional[Union[str, List[str]]] = None, over_curve_colors: Optional[Union[str, List[Optional[str]], Dict[str, str]]] = None, over_curve_axes: Optional[Union[str, List[Optional[str]], List[str], Dict[str, str]]] = None) Tuple[Optional[List[Tensor]], Optional[List[str]], Optional[List[Optional[str]]], Optional[List[str]]][source]#
- Converts user defined overlaid curves related options into a standard format, in terms of object structure and types.
Parameters#
wavtorch.TensorLoaded audio tensor
srintResolved sample-rate
channelsintThe amount of channels in
wavover_curvetensorlike | List[tensorlike] | Dict[str, tensorlike] | callableUser provided
over_curve_namesList[str]User provided
over_curve_colorsList[str]User provided
over_curve_axesList[str]User provided
Returns#
over_curveList[torch.Tensor]Standardized
over_curve_namesList[str]Standardized
over_curve_colorsList[str]Standardized
over_curve_axesList[str]User provided
Raises#
ValueError- When
over_curve_nameswas provided but of a different size fromover_curveORWhenover_curve_colorswas provided but of a different size fromover_curveORWhenover_curve_axeswas provided but of a different size fromover_curveORWhenover_curve_colorswas a dict butover_curve_nameswas not providedORWhenover_curve_axeswas a dict butover_curve_nameswas not providedORWhenover_curve_nameswas provided butover_curvewas a dictORWhenover_curvecontained an(X,Y)tuple of size not equal to 2ORWhenover_curvecontained an(X,Y)tuple whereX.shape != Y.shape
- waloviz._tensor_utils.single_value_to_list(over_curve: Optional[Union[List[Any], Dict[str, Any], ndarray, Tensor, Tuple[Any, Any], Any]], over_curve_names: Optional[Union[str, List[str]]] = None, over_curve_colors: Optional[Union[str, List[Optional[str]], Dict[str, str]]] = None, over_curve_axes: Optional[Union[str, List[Optional[str]], List[str], Dict[str, str]]] = None) Tuple[Optional[Union[List[Any], Dict[str, Any], ndarray, Tensor, Tuple[Any, Any], Any]], Optional[List[str]], Optional[Union[List[Optional[str]], Dict[str, str]]], Optional[Union[List[Optional[str]], List[str], Dict[str, str]]]][source]#
- Makes sure that if single values were provided they are wrapped in single element lists.
Parameters#
over_curvetensorlike | List[tensorlike] | Dict[str, tensorlike] | callableUser provided
over_curve_namesList[str]User provided
over_curve_colorsList[str]User provided
over_curve_axesList[str]User provided
Returns#
over_curvetensorlike | List[tensorlike] | Dict[str, tensorlike] | callable.
over_curve_namesList[str].
over_curve_colorsList[str].
over_curve_axesList[str].
- waloviz._tensor_utils.skip_to_size(tensor: Union[Tensor, Tuple], max_size: int) Union[Tensor, Tuple][source]#
- Given a hierarchical tensor object skip equally spaced tensor values along the time dimension (
dim=-1) to become lower than themax_sizevalue.This helps with the responsiveness of the player and avoids errors at thecost of losing information.This is used for both the overlaid curves and the spectrogram itself.Parameters#
tensortorch.Tensor | (torch.Tensor, torch.Tensor)A hierarchical tensor object with an unknown time size
max_sizeintThe maximum allowed time dimension size
Returns#
objtorch.TensorA hierarchical tensor object with a time size lower than
max_size
- waloviz._tensor_utils.to_tensor(obj: Any) Union[Tensor, Tuple[Tensor, Tensor], Tuple][source]#
- Given a hierarchical object recursively converts all leaf nodes into PyTorch tensors.
Parameters#
objAnyA hierarchical tuple object
Returns#
objtorch.TensorA hierarchical tuple tensor object
- waloviz._tensor_utils.validate_XY_over_curve(over_curve: Union[List[Any], Dict[str, Any], ndarray, Tensor, Tuple[Any, Any], Any]) None[source]#
- If the
over_curvehas X and Y tensors, make sure their of the same shape.Parameters#
over_curveList[torch.Tensor | (torch.Tensor, torch.Tensor)]Either a list of tensors or
(X,Y)tuples of tensors
Raises#
ValueError- When
over_curvecontained an(X,Y)tuple of size not equal to 2ORWhenover_curvecontained an(X,Y)tuple whereX.shape != Y.shape