Skip to main content

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

  • dtype (DType): DType of the value.
  • size (Int): SIMD width of the value.

Fields

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

Implemented traits

AnyType, Copyable, Movable, Stringable, UnknownDestructibility, Writable, _Expable

Aliases

element_type

alias element_type = SIMD[dtype, size]

type

alias type = dtype

Methods

__init__

__init__(re: SIMD[dtype, size], im: SIMD[dtype, size] = __init__[__mlir_type.!pop.int_literal](0)) -> Self

Initializes a complex SIMD value.

Args:

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

__neg__

__neg__(self) -> Self

Negates the complex value.

Returns:

The negative of the complex value.

__add__

__add__(self, rhs: Self) -> Self

Adds two complex values.

Args:

  • rhs (Self): Complex value to add.

Returns:

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:

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:

A product of this and RHS complex values.

__truediv__

__truediv__(self, rhs: Self) -> Self

Divides two complex values.

Args:

  • rhs (Self): Complex value to divide by.

Returns:

A quotient of this and RHS complex values.

__str__

__str__(self) -> String

Get the complex as a string.

Returns:

A string representation.

write_to

write_to[W: Writer](self, mut writer: W)

Formats this complex value to the provided Writer.

Parameters:

  • W (Writer): A type conforming to the Writable trait.

Args:

  • writer (W): The object to write to.

__abs__

__abs__(self) -> SIMD[dtype, size]

Returns the magnitude of the complex value.

Returns:

Value of sqrt(re*re + im*im).

norm

norm(self) -> SIMD[dtype, size]

Returns the magnitude of the complex value.

Returns:

Value of sqrt(re*re + im*im).

squared_norm

squared_norm(self) -> SIMD[dtype, size]

Returns the squared magnitude of the complex value.

Returns:

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:

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:

Computed Self * Self + C complex value.

__exp__

__exp__(self) -> Self

Computes the exponential of the complex value.

Returns:

The exponential of the complex value.

Was this page helpful?