mrpro.utils.RandomGenerator
- class mrpro.utils.RandomGenerator[source]
Bases:
object
Generate random numbers for various purposes.
Uses a fixed seed to ensure reproducibility.
- Provides:
- Scalar uniform random numbers:
int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64, complex64, complex128
- Tensor of uniform random numbers:
int8_tensor, int16_tensor, int32_tensor, int64_tensor, uint8_tensor, float32_tensor, float64_tensor, complex64_tensor, complex128_tensor (Note: uint16, uint32, uint64 tensors are not yet supported by PyTorch)
- Tuple of uniform random numbers:
int8_tuple, int16_tuple, int32_tuple, int64_tuple, uint8_tuple, uint16_tuple, uint32_tuple, uint64_tuple, float32_tuple, float64_tuple, complex64_tuple, complex128_tuple
- ascii(size: int) str [source]
Generate a random ASCII string.
- Parameters:
size (
int
) – Length of the string.- Returns:
Random ASCII string.
- complex128(low: float = 0, high: float = 1.0) complex [source]
Generate a complex128 scalar with uniform amplitude in [low, high).
The phase is uniformly distributed in [-π, π].
- complex128_tensor(size: Sequence[int] | int = (1,), low: float = 0.0, high: float = 1.0) Tensor [source]
Generate a complex128 tensor with uniform amplitude in [low, high).
The phase is uniformly distributed in [-π, π].
- complex128_tuple(size: int, low: float = 0, high: float = 1) tuple[complex, ...] [source]
Generate a tuple of complex128 numbers with uniform amplitude in [low, high).
The phase is uniformly distributed in [-π, π].
- complex64(low: float = 0, high: float = 1.0) complex [source]
Generate a complex64 scalar with uniform amplitude in [low, high).
The phase is uniformly distributed in [-π, π].
- complex64_tensor(size: Sequence[int] | int = (1,), low: float = 0.0, high: float = 1.0) Tensor [source]
Generate a complex64 tensor with uniform amplitude in [low, high).
The phase is uniformly distributed in [-π, π].
- complex64_tuple(size: int, low: float = 0, high: float = 1) tuple[complex, ...] [source]
Generate a tuple of complex64 numbers with uniform amplitude in [low, high).
The phase is uniformly distributed in [-π, π].
- float32(low: float = 0.0, high: float = 1.0) float [source]
Generate a float32 scalar with uniform distribution in [low, high).
- float32_tensor(size: Sequence[int] | int = (1,), low: float = 0.0, high: float = 1.0) Tensor [source]
Generate a float32 tensor with uniform distribution in [low, high).
- float32_tuple(size: int, low: float = 0, high: float = 1) tuple[float, ...] [source]
Generate a tuple of float32 numbers with uniform distribution in [low, high).
- float64(low: float = 0.0, high: float = 1.0) float [source]
Generate a float64 scalar with uniform distribution in [low, high).
- float64_tensor(size: Sequence[int] | int = (1,), low: float = 0.0, high: float = 1.0) Tensor [source]
Generate a float64 tensor with uniform distribution in [low, high).
- float64_tuple(size: int, low: float = 0, high: float = 1) tuple[float, ...] [source]
Generate a tuple of float64 numbers with uniform distribution in [low, high).
- gaussian_variable_density_samples(shape: Sequence[int], low: int, high: int, fwhm: float = float('inf'), always_sample: Sequence[int] = ()) Tensor [source]
Generate Gaussian variable density samples.
Generates indices in [low, high[ with a gaussian weighting.
- Parameters:
shape (
Sequence
[int
]) – Shape of the output tensor. The generated indices are 1D and in the last dimension. All other dimensions are batch dimensions.low (
int
) – Lower bound of the sampling domain.high (
int
) – Upper bound of the sampling domain.fwhm (
float
, default:float('inf')
) – Full-width at half-maximum of the Gaussian.always_sample (
Sequence
[int
], default:()
) – indices that should always included in the samples. For example,range(-n_center//2, n_center//2)
- Returns:
1D tensor of selected indices.
- int16(low: int = -1 << 15, high: int = 1 << 15 - 1) int [source]
Generate an int16 scalar with uniform distribution in [low, high).
- int16_tensor(size: Sequence[int] | int = (1,), low: int = -1 << 15, high: int = 1 << 15) Tensor [source]
Generate an int16 tensor with uniform distribution in [low, high).
- int16_tuple(size: int, low: int = -1 << 15, high: int = 1 << 15) tuple[int, ...] [source]
Generate a tuple of int16 numbers with uniform distribution in [low, high).
- int32(low: int = -1 << 31, high: int = 1 << 31 - 1) int [source]
Generate an int32 scalar with uniform distribution in [low, high).
- int32_tensor(size: Sequence[int] | int = (1,), low: int = -1 << 31, high: int = 1 << 31) Tensor [source]
Generate an int32 tensor with uniform distribution in [low, high).
- int32_tuple(size: int, low: int = -1 << 31, high: int = 1 << 31) tuple[int, ...] [source]
Generate a tuple of int32 numbers with uniform distribution in [low, high).
- int64(low: int = -1 << 63, high: int = 1 << 63 - 1) int [source]
Generate an int64 scalar with uniform distribution in [low, high).
- int64_tensor(size: Sequence[int] | int = (1,), low: int = -1 << 63, high: int = 1 << 63) Tensor [source]
Generate an int64 tensor with uniform distribution in [low, high).
- int64_tuple(size: int, low: int = -1 << 63, high: int = 1 << 63) tuple[int, ...] [source]
Generate a tuple of int64 numbers with uniform distribution in [low, high).
- int8(low: int = -1 << 7, high: int = 1 << 7 - 1) int [source]
Generate an int8 scalar with uniform distribution in [low, high).
- int8_tensor(size: Sequence[int] | int = (1,), low: int = -1 << 7, high: int = 1 << 7) Tensor [source]
Generate an int8 tensor with uniform distribution in [low, high).
- int8_tuple(size: int, low: int = -1 << 7, high: int = 1 << 7) tuple[int, ...] [source]
Generate a tuple of int8 numbers with uniform distribution in [low, high).
- rand_like(x: Tensor, low: float = 0.0, high: float = 1.0) Tensor [source]
Generate a tensor with the same shape and dtype as
x
, filled with uniform random numbers.
- rand_tensor(size: Sequence[int], dtype: dtype, low: float | int = 0, high: int | float = 1) Tensor [source]
Generate a tensor of given shape and dtype with uniform random numbers in [low, high).
- randn_tensor(size: Sequence[int], dtype: dtype) Tensor [source]
Generate a tensor of given shape and dtype with standard normal distribution.
- randperm(n: int, *, dtype: dtype = torch.int64) Tensor [source]
Generate a random permutation of integers from 0 to n - 1.
- uint16(low: int = 0, high: int = 1 << 16 - 1) int [source]
Generate a uint16 scalar with uniform distribution in [low, high).
- uint16_tuple(size: int, low: int = 0, high: int = 1 << 16 - 1) tuple[int, ...] [source]
Generate a tuple of uint16 numbers with uniform distribution in [low, high).
- uint32(low: int = 0, high: int = 1 << 32 - 1) int [source]
Generate a uint32 scalar with uniform distribution in [low, high).
- uint32_tuple(size: int, low: int = 0, high: int = 1 << 32 - 1) tuple[int, ...] [source]
Generate a tuple of uint32 numbers with uniform distribution in [low, high).
- uint64(low: int = 0, high: int = 1 << 64 - 1) int [source]
Generate a uint64 scalar with uniform distribution in [low, high).
- uint64_tuple(size: int, low: int = 0, high: int = 1 << 64 - 1) tuple[int, ...] [source]
Generate a tuple of uint64 numbers with uniform distribution in [low, high).
- uint8(low: int = 0, high: int = 1 << 8 - 1) int [source]
Generate a uint8 scalar with uniform distribution in [low, high).
- uint8_tensor(size: Sequence[int] | int = (1,), low: int = 0, high: int = 1 << 8 - 1) Tensor [source]
Generate a uint8 tensor with uniform distribution in [low, high).
- uint8_tuple(size: int, low: int = 0, high: int = 1 << 8 - 1) tuple[int, ...] [source]
Generate a tuple of uint8 numbers with uniform distribution in [low, high).
- __eq__(value, /)
Return self==value.
- __new__(**kwargs)