IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

ComplexSIMD

struct ComplexSIMD[dtype: DType, length: SIMDLength]

Represents a complex SIMD value.

The class provides basic methods for manipulating complex values.

Parameters​

  • ​dtype (DType): DType of the value.
  • ​length (SIMDLength): SIMD width of the value.

Fields​

  • ​re (ComplexSIMD[dtype, length].element_type): The real part of the complex SIMD value.
  • ​im (ComplexSIMD[dtype, length].element_type): The imaginary part of the complex SIMD value.

Implemented traits​

AnyType, Copyable, Deinitable, Equatable, ImplicitlyCopyable, Movable, RegisterPassable, TrivialRegisterPassable, Writable, _Expable

comptime members​

element_type​

comptime element_type = SIMD[dtype, length]

The SIMD type used for real and imaginary parts.

type​

comptime type = dtype

The data type of the complex components.

Methods​

__init__​

def __init__(re: SIMD[dtype, length], im: SIMD[dtype, length] = 0) -> Self

Initializes a complex SIMD value.

Args:

def __init__(*, from_interleaved: SIMD[dtype, (Int(2) * SIMD(length))]) -> Self

Initializes a complex SIMD value.

Args:

def __init__(*, from_deinterleaved: SIMD[dtype, (Int(2) * SIMD(length))]) -> Self

Initializes a complex SIMD value.

Args:

__neg__​

def __neg__(self) -> Self

Negates the complex value.

Returns:

Self: The negative of the complex value.

__eq__​

def __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__​

def __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__​

def __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__​

def __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.

def __mul__(self, rhs: Scalar[dtype]) -> Self

Multiplies a complex value to a scalar.

Args:

Returns:

Self: A product of self and rhs.

__truediv__​

def __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__​

def __rmul__(self, lhs: Scalar[dtype]) -> Self

Multiplies a complex value to a scalar.

Args:

Returns:

Self: A product of self and lhs.

__imul__​

def __imul__(mut self, rhs: Self)

Multiplies two complex values inplace.

Args:

  • ​rhs (Self): Complex value to multiply with.

def __imul__(mut self, rhs: Scalar[dtype])

Multiplies a complex value to a scalar inplace.

Args:

write_to​

def write_to(self, mut writer: T)

Formats this complex value to the provided Writer.

Args:

  • ​writer (T): The object to write to.

write_repr_to​

def write_repr_to(self, mut writer: T)

Formats the complex value for debug representation.

Args:

  • ​writer (T): The Writer to write the representation to.

__abs__​

def __abs__(self) -> SIMD[dtype, length]

Returns the magnitude of the complex value.

Returns:

SIMD[dtype, length]: Value of sqrt(re*re + im*im).

conj​

def conj(self) -> Self

Return the complex conjugate of self.

Returns:

Self: The complex conjugate of self.

norm​

def norm(self) -> SIMD[dtype, length]

Returns the magnitude of the complex value.

Returns:

SIMD[dtype, length]: Value of sqrt(re*re + im*im).

squared_norm​

def squared_norm(self) -> SIMD[dtype, length]

Returns the squared magnitude of the complex value.

Returns:

SIMD[dtype, length]: Value of re*re + im*im.

fma​

def 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​

def 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__​

def __exp__(self) -> Self

Computes the exponential of the complex value.

Returns:

Self: The exponential of the complex value.