Mojo struct
ComplexSIMD
@register_passable(trivial)
struct ComplexSIMD[dtype: DType, size: Int]
Represents a complex SIMD value.
The class provides basic methods for manipulating complex values.
Parameters
Fields
- re (
ComplexSIMD[dtype, size].element_type): The real part of the complex SIMD value. - im (
ComplexSIMD[dtype, size].element_type): The imaginary part of the complex SIMD value.
Implemented traits
AnyType,
Copyable,
Equatable,
ImplicitlyCopyable,
ImplicitlyDestructible,
Movable,
Stringable,
Writable,
_Expable
comptime members
__copyinit__is_trivial
comptime __copyinit__is_trivial = True
__del__is_trivial
comptime __del__is_trivial = True
__moveinit__is_trivial
comptime __moveinit__is_trivial = True
element_type
comptime element_type = SIMD[dtype, size]
The SIMD type used for real and imaginary parts.
type
comptime type = dtype
The data type of the complex components.
Methods
__init__
__init__(re: SIMD[dtype, size], im: SIMD[dtype, size] = 0) -> Self
Initializes a complex SIMD value.
Args:
__init__(*, from_interleaved: SIMD[dtype, (2 * size)]) -> Self
Initializes a complex SIMD value.
Args:
- from_interleaved (
SIMD): An interleaved vector of complex values e.g.[0, 1, 1, 0]where the pattern is[re0, im0, re1, im1].
__init__(*, from_deinterleaved: SIMD[dtype, (2 * size)]) -> Self
Initializes a complex SIMD value.
Args:
- from_deinterleaved (
SIMD): A deinterleaved vector of complex values e.g.[0, 1, 1, 0]where the pattern is[re0, re1, im0, im1].
__neg__
__neg__(self) -> Self
Negates the complex value.
Returns:
Self: The negative of the complex value.
__eq__
__eq__(self, rhs: Self) -> Bool
Compares two ComplexSIMD for equality.
Args:
- rhs (
Self): The ComplexSIMD to compare with.
Returns:
Bool: True if all elements of the ComplexSIMD are equal, False otherwise.
__add__
__add__(self, rhs: Self) -> Self
Adds two complex values.
Args:
- rhs (
Self): Complex value to add.
Returns:
Self: A sum of this and RHS complex values.
__sub__
__sub__(self, rhs: Self) -> Self
Subtracts two complex values.
Args:
- rhs (
Self): Complex value to subtract.
Returns:
Self: A difference of this and RHS complex values.
__mul__
__mul__(self, rhs: Self) -> Self
Multiplies two complex values.
Args:
- rhs (
Self): Complex value to multiply with.
Returns:
Self: A product of this and RHS complex values.
__mul__(self, rhs: Scalar[dtype]) -> Self
Multiplies a complex value to a scalar.
Args:
- rhs (
Scalar): Scalar value to multiply with.
Returns:
Self: A product of self and rhs.
__truediv__
__truediv__(self, rhs: Self) -> Self
Divides two complex values.
Args:
- rhs (
Self): Complex value to divide by.
Returns:
Self: A quotient of this and RHS complex values.
__rmul__
__rmul__(self, lhs: Scalar[dtype]) -> Self
Multiplies a complex value to a scalar.
Args:
- lhs (
Scalar): Scalar value to multiply with.
Returns:
Self: A product of self and lhs.
__imul__
__imul__(mut self, rhs: Self)
Multiplies two complex values inplace.
Args:
- rhs (
Self): Complex value to multiply with.
__imul__(mut self, rhs: Scalar[dtype])
Multiplies a complex value to a scalar inplace.
Args:
- rhs (
Scalar): Scalar value to multiply with.
__str__
write_to
write_to(self, mut writer: T)
Formats this complex value to the provided Writer.
Args:
- writer (
T): The object to write to.
__abs__
__abs__(self) -> SIMD[dtype, size]
Returns the magnitude of the complex value.
Returns:
SIMD: Value of sqrt(re*re + im*im).
conj
conj(self) -> Self
Return the complex conjugate of self.
Returns:
Self: The complex conjugate of self.
norm
norm(self) -> SIMD[dtype, size]
Returns the magnitude of the complex value.
Returns:
SIMD: Value of sqrt(re*re + im*im).
squared_norm
squared_norm(self) -> SIMD[dtype, size]
Returns the squared magnitude of the complex value.
Returns:
SIMD: Value of re*re + im*im.
fma
fma(self, b: Self, c: Self) -> Self
Computes FMA operation.
Compute fused multiple-add with two other complex values:
result = self * b + c
Args:
- b (
Self): Multiplier complex value. - c (
Self): Complex value to add.
Returns:
Self: Computed Self * B + C complex value.
squared_add
squared_add(self, c: Self) -> Self
Computes Square-Add operation.
Compute Self * Self + C.
Args:
- c (
Self): Complex value to add.
Returns:
Self: Computed Self * Self + C complex value.
__exp__
__exp__(self) -> Self
Computes the exponential of the complex value.
Returns:
Self: The exponential of the complex value.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!