NUFFT
torchlinops.linops.NUFFT
Bases: NUFFTBase
Non-uniform Fast Fourier Transform (type II) as a named linear operator.
Implemented as a Chain of zero-padding, FFT, and interpolation. Supports
forward (image-to-kspace) and adjoint (kspace-to-image) operations.
| ATTRIBUTE | DESCRIPTION |
|---|---|
**options |
oversamp : float Oversampling factor for fourier domain grid width : float Width of kernel to use for interpolation skip_prep_locs : bool Flag for skipping scaling/shifting/etc of locs toeplitz : bool If True, normal() performs toeplitz embedding calculation toeplitz_dtype : torch.dtype Data type for the toeplitz embedding. Probably should be torch.complex64
TYPE:
|
Source code in src/torchlinops/linops/nufft/nufft.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 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 127 128 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 172 173 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 | |
__init__
prep_locs
cached
staticmethod
prep_locs(
locs: Shaped[Tensor, "... D"],
grid_size: tuple,
padded_size: tuple,
pad_mode: Literal["zero", "circular"] = "circular",
)
| PARAMETER | DESCRIPTION |
|---|---|
locs
|
Input tensor representing locations in the grid. The last dimension corresponds to spatial dimensions. Range is [-N//2, N//2]
TYPE:
|
grid_size
|
The original size of the grid before padding.
TYPE:
|
padded_size
|
The size of the grid after padding.
TYPE:
|
pad_mode
|
The type of padding applied. Can be "zero" for zero-padding or "circular" for circular padding. Default is "circular".
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Shaped[Tensor, '... D']
|
Adjusted locations tensor in [0, padded_size - 1], float dtype. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If an unrecognized |
Examples:
>>> _ = torch.manual_seed(0);
>>> locs = torch.rand(1000, 3) * 64 - 32 # [-32, 32]
>>> locs.min()
tensor(-31.9949)
>>> locs.max()
tensor(31.9896)
>>> grid_size = (64, 64, 64)
>>> padded_size = (80, 80, 80) # oversamp = 1.25
>>> locs_scaled_shifted = NUFFT.prep_locs(locs, grid_size, padded_size)
>>> locs_scaled_shifted.min()
tensor(0.0064)
>>> locs_scaled_shifted.max()
tensor(79.9871)
Notes
- Assumes that the input
locsare centered. - Adjusts the locations by scaling and shifting them according to the grid and padded sizes.
- Applies clamping or remainder operations based on the padding mode.
Source code in src/torchlinops/linops/nufft/nufft.py
torchlinops.linops.FastSamplingNUFFT
Bases: SamplingNUFFT
Non-uniform FFT (type II, sampling mode) without the FFT shift sandwich.
SamplingNUFFT builds [Pad, FFT(centered=True), Sampling]. The centered
FFT copies the full grid 3x per axis (ifftshift/fftshift rolls), in forward
and again through autograd's backward. This subclass applies the shift
theorem instead: it runs a plain fftn on the padded grid and folds the
centering into the gather indices plus a per-sample complex phase,
precomputed once per trajectory:
fftshift(fftn(ifftshift(x)))[l] = S(k) * fftn(x)[k],
k = (l - N//2) mod N,
S(k) = exp(-2j*pi * sum_d k_d * ((N_d + 1)//2) / N_d)
For all-even padded sizes S reduces to the parity sign
(-1)**sum_d k_d. Computes the same operator as SamplingNUFFT (to
complex64 rounding); inherits prep_locs, device, and options.
The centering phase lives at either end of the gather, selectable via the
phase_placement option (issue #210):
"samples"— phaseDiagonalafterSampling(per-sample phase):O(nlocs)multiplies forward+backward."grid"— per-axis broadcastDiagonals on the uncentered fftn grid beforeSampling:O(prod padded_size)multiplies forward+backward,O(sum N_d)storage."auto"(default) —"grid"iff the sample count exceedsprod(padded_size). resolved at build time, recorded asself.phase_placement_resolved.
Both placements compute the same operator: the unit-modulus phase commutes with the gather.
Source code in src/torchlinops/linops/nufft/fast_sampling_nufft.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 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 127 128 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 172 173 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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
fold_centering
cached
staticmethod
Fold the centered-FFT sandwich into plain-FFT gather indices + phase.
| PARAMETER | DESCRIPTION |
|---|---|
locs_prepared
|
Output of
TYPE:
|
padded_size
|
Oversampled grid size, one entry per spatial axis. |
| RETURNS | DESCRIPTION |
|---|---|
phase
|
complex64 tensor of shape
TYPE:
|
Source code in src/torchlinops/linops/nufft/fast_sampling_nufft.py
torchlinops.linops.nufft.toeplitz_psf
toeplitz_psf(
nufft: NUFFT,
inner: NamedLinop | None = None,
dtype: dtype | None = None,
oversamp: float = 2.0,
) -> NamedLinop
Compute the Toeplitz point spread function (PSF) for a NUFFT operator.
Constructs a PSF kernel that enables efficient A.H @ inner @ A
computation via FFT-based Toeplitz embedding, avoiding explicit
forward/adjoint NUFFT pairs.
| PARAMETER | DESCRIPTION |
|---|---|
nufft
|
The NUFFT operator to compute the PSF for.
TYPE:
|
inner
|
An optional inner linear operator applied between the forward and
adjoint NUFFT (e.g., density compensation). If
TYPE:
|
dtype
|
Data type for the PSF kernel. Defaults to
TYPE:
|
oversamp
|
Toeplitz oversampling factor. Default is 2.0.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NamedLinop
|
A |
Source code in src/torchlinops/linops/nufft/toeplitz.py
torchlinops.linops.nufft.rescale_locs
Perform a scale-and-shift operation on a single dimension of a locs tensor.
| PARAMETER | DESCRIPTION |
|---|---|
locs
|
The locs to rescale, shape [... D ...]
TYPE:
|
c0
|
The center and width parameter for the current locs
TYPE:
|
w0
|
The center and width parameter for the current locs
TYPE:
|
c1
|
The desired center and width parameters.
TYPE:
|
w1
|
The desired center and width parameters.
TYPE:
|
dim
|
The dimension of locs to unstack
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The rescaled trajectory coordinates. |