Utils
closest_power_2(x)
Find the closest power of 2 to a given number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
float
|
The number to find the closest power of 2 to. |
required |
Returns:
Type | Description |
---|---|
int
|
The closest power of 2 to the given number. |
Source code in models/tts/styledtts2/diffusion/utils.py
default(val, d)
Return the value if it exists, otherwise return the default value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val |
Optional[T]
|
The value to check. |
required |
d |
Union[Callable[..., T], T]
|
The default value to return if the value does not exist. |
required |
Returns:
Type | Description |
---|---|
T
|
The value if it exists, otherwise the default value. |
Source code in models/tts/styledtts2/diffusion/utils.py
exists(val)
Check if a value is not None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val |
Optional[T]
|
The value to check. |
required |
Returns:
Type | Description |
---|---|
TypeGuard[T]
|
True if the value is not None, False otherwise. |
group_dict_by_prefix(prefix, d)
Group a dictionary by keys that start with a given prefix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix |
str
|
The prefix to group by. |
required |
d |
Dict
|
The dictionary to group. |
required |
Returns:
Type | Description |
---|---|
Tuple[Dict, Dict]
|
A tuple of two dictionaries: one with keys that start with the prefix, and one with keys that do not. |
Source code in models/tts/styledtts2/diffusion/utils.py
groupby(prefix, d, keep_prefix=False)
Group a dictionary by keys that start with a given prefix and optionally remove the prefix from the keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix |
str
|
The prefix to group by. |
required |
d |
Dict
|
The dictionary to group. |
required |
keep_prefix |
bool
|
Whether to keep the prefix in the keys. |
False
|
Returns:
Type | Description |
---|---|
Tuple[Dict, Dict]
|
A tuple of two dictionaries: one with keys that start with the prefix, and one with keys that do not. |
Source code in models/tts/styledtts2/diffusion/utils.py
iff(condition, value)
Return the value if the condition is True, None otherwise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
condition |
bool
|
The condition to check. |
required |
value |
T
|
The value to return if the condition is True. |
required |
Returns:
Type | Description |
---|---|
Optional[T]
|
The value if the condition is True, None otherwise. |
Source code in models/tts/styledtts2/diffusion/utils.py
is_sequence(obj)
Check if an object is a list or a tuple.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
T
|
The object to check. |
required |
Returns:
Type | Description |
---|---|
TypeGuard[Union[list, tuple]]
|
True if the object is a list or a tuple, False otherwise. |
Source code in models/tts/styledtts2/diffusion/utils.py
prefix_dict(prefix, d)
Add a prefix to all keys in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix |
str
|
The prefix to add. |
required |
d |
Dict
|
The dictionary to modify. |
required |
Returns:
Type | Description |
---|---|
Dict
|
The modified dictionary with the prefix added to all keys. |
Source code in models/tts/styledtts2/diffusion/utils.py
prod(vals)
Calculate the product of a sequence of integers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vals |
Sequence[int]
|
The sequence of integers. |
required |
Returns:
Type | Description |
---|---|
int
|
The product of the sequence of integers. |
Source code in models/tts/styledtts2/diffusion/utils.py
rand_bool(shape, proba)
Generate a tensor of random booleans.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape |
Tuple[int, ...]
|
The shape of the tensor. |
required |
proba |
float
|
The probability of a True value. |
required |
device |
The device to create the tensor on. |
required |
Returns:
Type | Description |
---|---|
A tensor of random booleans. |
Source code in models/tts/styledtts2/diffusion/utils.py
to_list(val)
Convert a value or a sequence of values to a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val |
Union[T, Sequence[T]]
|
The value or sequence of values to convert. |
required |
Returns:
Type | Description |
---|---|
List[T]
|
The value or sequence of values as a list. |