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
96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
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. |
Source code in models/tts/styledtts2/diffusion/utils.py
11 12 13 14 15 16 17 18 19 20 |
|
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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
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
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
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
23 24 25 26 27 28 29 30 31 32 33 |
|
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
36 37 38 39 40 41 42 43 44 45 |
|
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
169 170 171 172 173 174 175 176 177 178 179 |
|
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
84 85 86 87 88 89 90 91 92 93 |
|
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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
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. |
Source code in models/tts/styledtts2/diffusion/utils.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|