torchoptics.functional#
Functions used in the torchoptics package.
Functions#
|
Calculate the centroid of an intensity distribution. |
|
Calculate the standard deviation of an intensity distribution. |
|
Perform a 2D convolution using Fast Fourier Transforms (FFT). |
|
Return the Discrete Fourier Transform sample frequencies with gradient tracking. |
|
Construct the evolution function for spatial coherence given an evolution operator \(U\). |
|
Compute the inner product of two 2D vectors. |
|
Return linspace values with gradient tracking. |
|
Return a 2D meshgrid with gradient tracking. |
|
Compute the outer product of two 2D vectors. |
|
Interpolate data from a 2D plane onto a new plane. |
Package Contents#
- torchoptics.functional.calculate_centroid(intensity, meshgrid)#
Calculate the centroid of an intensity distribution.
- Parameters:
intensity (torch.Tensor)
meshgrid (tuple[torch.Tensor, torch.Tensor])
- Return type:
- torchoptics.functional.calculate_std(intensity, meshgrid)#
Calculate the standard deviation of an intensity distribution.
- Parameters:
intensity (torch.Tensor)
meshgrid (tuple[torch.Tensor, torch.Tensor])
- Return type:
- torchoptics.functional.conv2d_fft(input, weight, fft_padding=0)#
Perform a 2D convolution using Fast Fourier Transforms (FFT).
Unlike the
torch.nn.functional.conv2d()function, which performs cross-correlation,conv2d_fft()performs a convolution operation where the kernel is flipped.- Parameters:
input (torch.Tensor) – Input tensor to be convolved of shape \((..., iH, iW)\).
weight (torch.Tensor) – Filters of shape \((..., kH, kW)\).
fft_padding (int) – Number of extra zeros appended to the input in each spatial dimension before the FFT. Does not affect the output size, but can improve FFT performance when the padded size has favorable prime factors. Default:
0.
- Returns:
Convolved output tensor of shape \((..., oH, oW)\).
- Return type:
- torchoptics.functional.fftfreq_grad(n, d)#
Return the Discrete Fourier Transform sample frequencies with gradient tracking.
- Parameters:
n (int) – The number of samples.
d (torch.Tensor) – The sample spacing.
- Returns:
The sample frequencies.
- Return type:
- torchoptics.functional.get_coherence_evolution(evolution_func)#
Construct the evolution function for spatial coherence given an evolution operator \(U\).
The input function applies the evolution \(U\) to a
Fieldinstance:\[\psi \to U \psi\]while the returned function extends this transformation to a
SpatialCoherenceinstance:\[\Gamma \to U \Gamma U^\dagger\]which can be expressed equivalently as:
\[\Gamma \to \left( U (U \Gamma)^\dagger \right)^\dagger.\]- Parameters:
evolution_func (collections.abc.Callable[Ellipsis, torchoptics.fields.Field])
- Return type:
collections.abc.Callable[Ellipsis, torchoptics.fields.Field]
- torchoptics.functional.inner2d(vec1, vec2)#
Compute the inner product of two 2D vectors.
- Parameters:
vec1 (torch.Tensor) – The first vector.
vec2 (torch.Tensor) – The second vector.
- Returns:
The inner product.
- Return type:
- torchoptics.functional.linspace_grad(start, end, steps)#
Return linspace values with gradient tracking.
- Parameters:
start (torch.Tensor) – The starting value.
end (torch.Tensor) – The ending value.
steps (int) – The number of steps.
- Returns:
The linearly spaced values.
- Return type:
- torchoptics.functional.meshgrid2d(bounds, shape)#
Return a 2D meshgrid with gradient tracking.
- Parameters:
bounds (torch.Tensor | Sequence[torch.Tensor]) – The bounds of the grid.
shape (Sequence) – The shape of the grid.
- Returns:
The 2D meshgrid.
- Return type:
- torchoptics.functional.outer2d(vec1, vec2)#
Compute the outer product of two 2D vectors.
- Parameters:
vec1 (torch.Tensor) – The first vector.
vec2 (torch.Tensor) – The second vector.
- Returns:
The outer product.
- Return type:
- torchoptics.functional.plane_sample(data, data_plane, interpolated_plane, interpolation_mode)#
Interpolate data from a 2D plane onto a new plane.
- Parameters:
data (torch.Tensor) – The input data to interpolate.
data_plane (PlanarGrid) – The plane containing the input data.
interpolated_plane (PlanarGrid) – The plane to interpolate the data to.
interpolation_mode (str) – The interpolation mode.
- Returns:
The interpolated data.
- Return type: