chuchichaestli.dwt.modes
Signal extension modes for the boundary handling of the wavelet transform.
Functions:
| Name | Description |
|---|---|
extension_indices |
Build the gather that extends a signal of length |
pad_signal |
Extend a tensor along one axis by the given signal extension mode. |
pad_signal_adjoint |
Transpose of |
extension_indices
cached
extension_indices(
n: int,
pad_lo: int,
pad_hi: int,
mode: ExtensionModeTypes,
) -> tuple[
torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor
]
Build the gather that extends a signal of length n past both ends.
The result is cached on CPU; callers move it to the device they need.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Length of the signal. |
required |
pad_lo
|
int
|
Number of samples prepended. |
required |
pad_hi
|
int
|
Number of samples appended. |
required |
mode
|
ExtensionModeTypes
|
Signal extension mode. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/chuchichaestli/dwt/modes.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
pad_signal
pad_signal(
x: torch.Tensor,
axis: int,
pad_lo: int,
pad_hi: int,
mode: ExtensionModeTypes = "zero",
) -> torch.Tensor
Extend a tensor along one axis by the given signal extension mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
torch.Tensor
|
Input tensor. |
required |
axis
|
int
|
Axis to extend, given as a non-negative or negative index. |
required |
pad_lo
|
int
|
Number of samples prepended. |
required |
pad_hi
|
int
|
Number of samples appended. |
required |
mode
|
ExtensionModeTypes
|
Signal extension mode. |
'zero'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a padding is negative. |
Source code in src/chuchichaestli/dwt/modes.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
pad_signal_adjoint
pad_signal_adjoint(
grad: torch.Tensor,
axis: int,
pad_lo: int,
pad_hi: int,
mode: ExtensionModeTypes = "zero",
length: int | None = None,
) -> torch.Tensor
Transpose of pad_signal, scattering a gradient back onto the samples.
The extension gathers, so its transpose scatters: every extended sample returns its share to the source it was read from, and to the two edges the anchored modes lean on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grad
|
torch.Tensor
|
Gradient with respect to the extended tensor. |
required |
axis
|
int
|
Axis that was extended. |
required |
pad_lo
|
int
|
Number of samples that were prepended. |
required |
pad_hi
|
int
|
Number of samples that were appended. |
required |
mode
|
ExtensionModeTypes
|
Signal extension mode that was used. |
'zero'
|
length
|
int | None
|
Length of the axis before extension; derived if omitted. |
None
|
Source code in src/chuchichaestli/dwt/modes.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |