meddlr.ops#

Meddlr provides some utilities for complex, categorical, and fft-related operations. All operations assume the first dimension is the batch dimension.

Complex Utilities#

These utilities are used to perform complex arithmetic with both complex tensors and real views of compex tensors, where the last dimension is 2 for real/imaginary components. Because these utilities are optimized for complex numbers, they will fail on real-valued tensors that do not follow the real-view convention described above.

Note, because these utilites support real-view tensors, if the last dimension is 2, it will be interpreted as a real-view of a complex tensor. In your code, we recommend using complex tensors when handling complex numbers to avoid ambiguity between real and complex numbers.

meddlr.ops.complex.abs

Computes the absolute value (magnitude) of a complex-valued input tensor (x).

meddlr.ops.complex.angle

Computes the phase of a complex-valued input tensor (x).

meddlr.ops.complex.center_crop

Apply a center crop to the input image or batch of complex images.

meddlr.ops.complex.channels_first

Permute complex-valued x to channels-first convention.

meddlr.ops.complex.channels_last

Permute complex-valued x to channels-last convention.

meddlr.ops.complex.conj

Computes the complex conjugate of complex-valued input tensor (x).

meddlr.ops.complex.from_polar

Computes real and imaginary values from polar representation.

meddlr.ops.complex.get_mask

Returns a binary mask for where x is nonzero with eps tolerance.

meddlr.ops.complex.imag

Gets imaginary component of complex tensor.

meddlr.ops.complex.is_complex

Returns if x is a complex-tensor.

meddlr.ops.complex.is_complex_as_real

Returns True if the tensor follows the real-view convention for complex numbers.

meddlr.ops.complex.matmul

Computes complex-valued matrix product of X and Y.

meddlr.ops.complex.mul

Multiplies two complex-valued tensors x and y.

meddlr.ops.complex.power_method

Iteratively computes first singular value of X using power method.

meddlr.ops.complex.real

Gets real component of complex tensor.

meddlr.ops.complex.rss

Compute the root-sum-of-squares (RSS) for complex inputs.

meddlr.ops.complex.svd

Computes singular value decomposition of batch of complex-valued matrices.

meddlr.ops.complex.to_numpy

Convert real-valued PyTorch tensor to complex-valued numpy array.

meddlr.ops.complex.to_tensor

Convert complex-valued numpy array to real-valued PyTorch tensor.

Categorical Utilities#

These utilities are designed to perform categorical operations on tensors, such as converting between categorical and one-hot representations and converting from logits to probabilities.

meddlr.ops.categorical_to_one_hot

Converts categorical predictions to one-hot encoded predictions.

meddlr.ops.logits_to_prob

Converts logits to probabilities.

meddlr.ops.one_hot_to_categorical

Converts one-hot encoded predictions to categorical predictions.

meddlr.ops.pred_to_categorical

Converts one-hot encoded predictions or logits to category.

Fourier Transform Utilities#

meddlr.ops.fft2c

Apply centered 2 dimensional Fast Fourier Transform.

meddlr.ops.fft3c

Apply centered 2 dimensional Fast Fourier Transform.

meddlr.ops.fftc

Apply 1D centered Fast Fourier Transform (FFT).

meddlr.ops.fftnc

Apply nD centered fast fourier transform.

meddlr.ops.fftshift

Similar to np.fft.fftshift but applies to PyTorch Tensors

meddlr.ops.ifft2c

Apply centered 2-dimensional Inverse Fast Fourier Transform.

meddlr.ops.ifft3c

Apply centered 2-dimensional Inverse Fast Fourier Transform.

meddlr.ops.ifftc

Apply centered 2 dimensional Fast Fourier Transform.

meddlr.ops.ifftnc

Apply nD centered inverse fast fourier transform.

meddlr.ops.ifftshift

Similar to np.fft.ifftshift but applies to PyTorch Tensors