numojo.core.complex.complex_simd¶
ComplexSIMD (numojo.core.complex.complex_simd)
Implement the ComplexSIMD type and its operations.
This module provides a ComplexSIMD type that represents complex numbers using SIMD operations for efficient computation. It supports basic arithmetic operations like addition, subtraction, multiplication, and division, as well as other complex number operations like conjugation and absolute value.
Structs¶
ComplexSIMD¶
Memory convention: register_passable_trivial
Implements: AnyType, Copyable, ImplicitlyCopyable, ImplicitlyDestructible, Movable, RegisterPassable, Stringable, TrivialRegisterPassable, Writable
A SIMD-enabled complex number container (SoA layout).
Fields: re: SIMD vector of real parts. im: SIMD vector of imaginary parts.
The parameter cdtype determines the component precision (e.g. cf32, cf64).
The parameter width is the SIMD lane count; when width == 1 this acts like a scalar complex number.
Examples:
from numojo.prelude import *
var a = ComplexSIMD[cf32](1.0, 2.0)
var b = ComplexSIMD[cf32](3.0, 4.0)
print(a + b) # (4.0 + 6.0 j)
# SIMD width=2:
var a2 = ComplexSIMD[cf32, 2](
SIMD[cf32.dtype, 2](1.0, 1.5),
SIMD[cf32.dtype, 2](2.0, -0.5)
)
print(a2) # ( [1.0 2.0] + [1.5 -0.5]j )
Parameters:
cdtype(ComplexDType)width(Int)
Fields¶
re(SIMD[ComplexSIMD[cdtype, width].dtype, width])im(SIMD[ComplexSIMD[cdtype, width].dtype, width])
Aliases¶
dtype¶
Value: cdtype.dtype
Component dtype (underlying real/imag dtype).
__del__is_trivial¶
Value: True
__move_ctor_is_trivial¶
Value: True
__copy_ctor_is_trivial¶
Value: True
Methods¶
__init__¶
Overload 1¶
static
Copy constructor for ComplexSIMD.
Initializes a new ComplexSIMD instance by copying the values from another instance.
Args:
other(Self)
Returns:
Self
Overload 2¶
__init__(re: SIMD[ComplexSIMD[cdtype, width].dtype, width], im: SIMD[ComplexSIMD[cdtype, width].dtype, width]) -> Self
static
Constructs a ComplexSIMD from SIMD vectors of real and imaginary parts.
Args:
re(SIMD): SIMD vector containing the real components.im(SIMD): SIMD vector containing the imaginary components.
Returns:
Self
Overload 3¶
static
Constructs a ComplexSIMD where both real and imaginary parts are set to the same SIMD value.
Args:
val(SIMD): SIMD vector to broadcast to both real and imaginary components.
Returns:
Self
Overload 4¶
static
Constructs a ComplexSIMD from scalar integer real and imaginary values, broadcasted to SIMD lanes.
Args:
re(Int): Integer value for the real component.im(Int): Integer value for the imaginary component.
Returns:
Self
Overload 5¶
static
Constructs a ComplexSIMD where both real and imaginary parts are set to the same integer value broadcasted to SIMD lanes.
Args:
val(Int): Integer value to broadcast to both real and imaginary components.
Returns:
Self
__getitem__¶
Returns the complex number at the specified lane index.
Example:
from numojo.prelude import *
var c_simd = ComplexSIMD[cf32, 2](SIMD[f32, 2](1, 2), SIMD[f32, 2](3, 4))
var c0 = c_simd[0] # 1 + 3j
var c1 = c_simd[1] # 2 + 4j
Args:
self(Self)idx(Int): SIMD lane index (0 to width-1).
Returns:
ComplexSIMD
Raises
Error if lane index is out of range for the SIMD width.
__setitem__¶
Sets the complex scalar at the specified lane index.
Example:
from numojo.prelude import *
var c_simd = nm.ComplexSIMD[cf32, 2](SIMD[f32, 2](1, 2), SIMD[f32, 2](3, 4)) # [(1 + 3j), (2 + 4j)]
c_simd[0] = nm.CScalar[cf32](5, 6)
print(c_simd) # [(1 + 3j), (2 + 4j)] becomes [(5 + 6j), (2 + 4j)]
Args:
self(Self)[mut]idx(Int): SIMD lane index (0 to width-1).value(ComplexSIMD): ComplexScalar whose values will be assigned.
Raises
Error if lane index is out of range for the SIMD width.
__pos__¶
Returns the positive value of this ComplexSIMD (identity operation).
Args:
self(Self)
Returns:
Self
__invert__¶
__invert__(self) -> Self where (cdtype == ComplexDType.bool) if (cdtype == ComplexDType.bool) else cdtype.is_integral()
Element-wise logical NOT operation on this ComplexSIMD instance.
Args:
self(Self)
Returns:
Self
__eq__¶
Overload 1¶
Checks if two ComplexSIMD instances are exactly equal.
Args:
self(Self)other(Self)
Returns:
Bool
Overload 2¶
Checks if this ComplexSIMD instance is equal to the imaginary unit 1j.
Examples:
from numojo.prelude import *
var z1 = ComplexSIMD[cf64, 1](0.0, 1.0) # 0 + 1j
var z2 = ComplexSIMD[cf64, 1](1.0, 1.0) # 1 + 1j
print(z1 == `1j`) # True
print(z2 == `1j`) # False
Args:
self(Self)other(ImaginaryUnit): Imaginary unit (1j) to compare with this ComplexSIMD instance.
Returns:
Bool
__ne__¶
Overload 1¶
Checks if two ComplexSIMD instances are not equal.
Args:
self(Self)other(Self)
Returns:
Bool
Overload 2¶
Checks if this ComplexSIMD instance is not equal to the imaginary unit 1j.
Examples:
from numojo.prelude import *
var z1 = ComplexSIMD[cf64, 1](0.0, 1.0) # 0 + 1j
var z2 = ComplexSIMD[cf64, 1](1.0, 1.0) # 1 + 1j
print(z1 != `1j`) # False
print(z2 != `1j`) # True
Args:
self(Self)other(ImaginaryUnit): Imaginary unit (1j) to compare with this ComplexSIMD instance.
Returns:
Bool
__add__¶
Overload 1¶
Returns the element-wise sum of two ComplexSIMD instances.
Args:
self(Self)other(Self): Another ComplexSIMD instance.
Returns:
Self
Overload 2¶
Returns the sum of this ComplexSIMD instance and a scalar added to the real part.
Args:
self(Self)other(Scalar): Scalar value to add to the real component.
Returns:
Self
Overload 3¶
Returns the sum of this ComplexSIMD instance and a SIMD vector added to the real part.
Args:
self(Self)other(SIMD): SIMD vector to add to the real component.
Returns:
Self
Overload 4¶
Returns the sum of this ComplexSIMD instance and the imaginary unit 1j.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
var result = z + `1j` # 3 + 3j
print(result) # (3 + 3j)
Args:
self(Self)other(ImaginaryUnit): Imaginary unit (1j) to add to this complex number.
Returns:
Self
__sub__¶
Overload 1¶
Returns the element-wise difference of two ComplexSIMD instances.
Args:
self(Self)other(Self): Another ComplexSIMD instance.
Returns:
Self
Overload 2¶
Returns the difference of this ComplexSIMD instance and a scalar subtracted from the real part.
Args:
self(Self)other(Scalar): Scalar value to subtract from the real component.
Returns:
Self
Overload 3¶
Returns the difference of this ComplexSIMD instance and a SIMD vector subtracted from the real part.
Args:
self(Self)other(SIMD): SIMD vector to subtract from the real component.
Returns:
Self
Overload 4¶
Subtracts the imaginary unit 1j from this ComplexSIMD instance.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
var result = z - `1j` # 3 + 1j
print(result) # (3 + 1j)
Args:
self(Self)other(ImaginaryUnit): Imaginary unit (1j) to subtract from this complex number.
Returns:
Self
__mul__¶
Overload 1¶
Returns the element-wise product of two ComplexSIMD instances.
Args:
self(Self)other(Self): Another ComplexSIMD instance.
Returns:
Self
Overload 2¶
Returns the product of this ComplexSIMD instance and a scalar.
Args:
self(Self)other(Scalar): Scalar value to multiply with both real and imaginary parts.
Returns:
Self
Overload 3¶
Returns the product of this ComplexSIMD instance and a SIMD vector.
Args:
self(Self)other(SIMD): SIMD vector to multiply with both real and imaginary parts.
Returns:
Self
Overload 4¶
Returns the product of this ComplexSIMD instance and the imaginary unit 1j.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
var result = z * `1j` # -2 + 3j
print(result) # (-2 + 3j)
Args:
self(Self)other(ImaginaryUnit): Imaginary unit (1j) to multiply with this complex number.
Returns:
Self
__truediv__¶
Overload 1¶
Performs element-wise complex division of two ComplexSIMD instances.
Args:
self(Self)other(Self): Another ComplexSIMD instance to divide by.
Returns:
Self
Overload 2¶
Performs element-wise division of this ComplexSIMD instance by a scalar.
Args:
self(Self)other(Scalar): Scalar value to divide both real and imaginary parts by.
Returns:
Self
Overload 3¶
Performs element-wise division of this ComplexSIMD instance by a SIMD vector.
Args:
self(Self)other(SIMD): SIMD vector to divide both real and imaginary parts by.
Returns:
Self
Overload 4¶
Performs division of this ComplexSIMD instance by the imaginary unit 1j.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
var result = z / `1j` # 2 - 3j
print(result) # (2 - 3j)
Args:
self(Self)other(ImaginaryUnit): Imaginary unit (1j) to divide this complex number by.
Returns:
Self
__pow__¶
Raises this ComplexSIMD to an integer.
Args:
self(Self)n(Int): Integer exponent.
Returns:
Self
__and__¶
__and__(self, other: Self) -> Self where (cdtype == ComplexDType.bool) if (cdtype == ComplexDType.bool) else cdtype.is_integral()
Element-wise logical AND operation between two ComplexSIMD instances.
Args:
self(Self)other(Self): Another ComplexSIMD instance.
Returns:
Self
__or__¶
__or__(self, other: Self) -> Self where (cdtype == ComplexDType.bool) if (cdtype == ComplexDType.bool) else cdtype.is_integral()
Element-wise logical OR operation between two ComplexSIMD instances.
Args:
self(Self)other(Self): Another ComplexSIMD instance.
Returns:
Self
__xor__¶
__xor__(self, other: Self) -> Self where (cdtype == ComplexDType.bool) if (cdtype == ComplexDType.bool) else cdtype.is_integral()
Element-wise logical XOR operation between two ComplexSIMD instances.
Args:
self(Self)other(Self): Another ComplexSIMD instance.
Returns:
Self
__radd__¶
Overload 1¶
Returns the sum of a scalar and this ComplexSIMD instance, adding to the real part.
Args:
self(Self)other(Scalar): Scalar value to add to the real component.
Returns:
Self
Overload 2¶
Returns the sum of a SIMD vector and this ComplexSIMD instance, adding to the real part.
Args:
self(Self)other(SIMD): SIMD vector to add to the real component.
Returns:
Self
Overload 3¶
Returns the sum of the imaginary unit 1j and this ComplexSIMD instance.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
var result = `1j` + z # 3 + 3j
print(result) # (3 + 3j)
Args:
self(Self)other(ImaginaryUnit): Imaginary unit (1j) to add to this complex number.
Returns:
Self
__rsub__¶
Overload 1¶
Returns the difference of a scalar and this ComplexSIMD instance, subtracting from the real part.
Args:
self(Self)other(Scalar): Scalar value to subtract from the real component.
Returns:
Self
Overload 2¶
Returns the difference of a SIMD vector and this ComplexSIMD instance, subtracting from the real part.
Args:
self(Self)other(SIMD): SIMD vector to subtract from the real component.
Returns:
Self
Overload 3¶
Returns the difference of the imaginary unit 1j and this ComplexSIMD instance.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
var result = `1j` - z # -3 + (-1)j = -3 - 1j
print(result) # (-3 - 1j)
Args:
self(Self)other(ImaginaryUnit): Imaginary unit (1j) from which this complex number is subtracted.
Returns:
Self
__rmul__¶
Overload 1¶
Returns the product of a scalar and this ComplexSIMD instance.
Args:
self(Self)other(Scalar): Scalar value to multiply with both real and imaginary parts.
Returns:
Self
Overload 2¶
Returns the product of a SIMD vector and this ComplexSIMD instance.
Args:
self(Self)other(SIMD): SIMD vector to multiply with both real and imaginary parts.
Returns:
Self
Overload 3¶
Returns the product of the imaginary unit 1j and this ComplexSIMD instance.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
var result = `1j` * z # -2 + 3j
print(result) # (-2 + 3j)
Args:
self(Self)other(ImaginaryUnit): Imaginary unit (1j) to multiply with this complex number.
Returns:
Self
__rtruediv__¶
Overload 1¶
Performs element-wise division of a scalar by this ComplexSIMD instance.
Args:
self(Self)other(Scalar): Scalar value to be divided by this ComplexSIMD instance.
Returns:
Self
Overload 2¶
Performs element-wise division of a SIMD vector by this ComplexSIMD instance.
Args:
self(Self)other(SIMD): SIMD vector to be divided by this ComplexSIMD instance.
Returns:
Self
Overload 3¶
Performs division of the imaginary unit 1j by this ComplexSIMD instance.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 4.0) # 3 + 4j
var result = `1j` / z # 1j / (3 + 4j) = 0.16 - 0.12j
print(result) # (0.16 - 0.12j)
Args:
self(Self)other(ImaginaryUnit): Imaginary unit (1j) to be divided by this ComplexSIMD instance.
Returns:
Self
__iadd__¶
Overload 1¶
In-place addition of another ComplexSIMD instance.
Args:
self(Self)[mut]other(Self): Another ComplexSIMD instance.
Overload 2¶
In-place addition of a scalar to the real part of this ComplexSIMD instance.
Args:
self(Self)[mut]other(Scalar): Scalar value to add to the real component.
Overload 3¶
In-place addition of a SIMD vector to the real part of this ComplexSIMD instance.
Args:
self(Self)[mut]other(SIMD): SIMD vector to add to the real component.
Overload 4¶
In-place addition of the imaginary unit 1j to this ComplexSIMD instance.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
z += `1j` # Now z = 3 + 3j
print(z) # (3 + 3j)
Args:
self(Self)[mut]other(ImaginaryUnit): Imaginary unit (1j) to add to this complex number.
__isub__¶
Overload 1¶
In-place subtraction of another ComplexSIMD instance.
Args:
self(Self)[mut]other(Self): Another ComplexSIMD instance.
Overload 2¶
In-place subtraction of a scalar from the real part of this ComplexSIMD instance.
Args:
self(Self)[mut]other(Scalar): Scalar value to subtract from the real component.
Overload 3¶
In-place subtraction of a SIMD vector from the real part of this ComplexSIMD instance.
Args:
self(Self)[mut]other(SIMD): SIMD vector to subtract from the real component.
Overload 4¶
In-place subtraction of the imaginary unit 1j from this ComplexSIMD instance.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
z -= `1j` # Now z = 3 + 1j
print(z) # (3 + 1j)
Args:
self(Self)[mut]other(ImaginaryUnit): Imaginary unit (1j) to subtract from this complex number.
__imul__¶
Overload 1¶
In-place complex multiplication with another ComplexSIMD instance.
Args:
self(Self)[mut]other(Self): Another ComplexSIMD instance.
Overload 2¶
In-place multiplication of this ComplexSIMD instance by a scalar.
Args:
self(Self)[mut]other(Scalar): Scalar value to multiply with both real and imaginary parts.
Overload 3¶
In-place multiplication of this ComplexSIMD instance by a SIMD vector.
Args:
self(Self)[mut]other(SIMD): SIMD vector to multiply with both real and imaginary parts.
Overload 4¶
In-place multiplication of this ComplexSIMD instance by the imaginary unit 1j.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
z *= `1j` # Now z = -2 + 3j
print(z) # (-2 + 3j)
Args:
self(Self)[mut]other(ImaginaryUnit): Imaginary unit (1j) to multiply with this complex number.
__itruediv__¶
Overload 1¶
Performs in-place element-wise complex division of self by another ComplexSIMD instance.
Args:
self(Self)[mut]other(Self): Another ComplexSIMD instance to divide by.
Overload 2¶
Performs in-place element-wise division of this ComplexSIMD instance by a scalar.
Args:
self(Self)[mut]other(Scalar): Scalar value to divide both real and imaginary parts by.
Overload 3¶
Performs in-place element-wise division of this ComplexSIMD instance by a SIMD vector.
Args:
self(Self)[mut]other(SIMD): SIMD vector to divide both real and imaginary parts by.
Overload 4¶
Performs in-place division of this ComplexSIMD instance by the imaginary unit 1j.
Examples:
from numojo.prelude import *
var z = ComplexSIMD[cf64, 1](3.0, 2.0) # 3 + 2j
z /= `1j` # Now z = 2 - 3j
print(z) # (2 - 3j)
Args:
self(Self)[mut]other(ImaginaryUnit): Imaginary unit (1j) to divide this complex number by.
zero¶
static
Returns a ComplexSIMD instance with all real and imaginary components set to zero.
Example:
Returns:
Self
one¶
static
Returns a ComplexSIMD instance representing the complex number 1 + 0j.
Example:
Returns:
Self
i¶
static
Returns a ComplexSIMD instance representing the imaginary unit 0 + 1j.
Examples:
from numojo.prelude import *
# Create imaginary unit for different types
var i_f64 = ComplexSIMD[cf64].i() # (0 + 1j)
var i_f32 = ComplexSIMD[cf32].i() # (0 + 1j)
print(i_f64) # (0 + 1j)
# Use in complex arithmetic
var z = 3.0 + 4.0 * ComplexSIMD[cf64].i() # 3 + 4j
Returns:
Self
from_real_imag¶
from_real_imag(re: Scalar[ComplexSIMD[cdtype, width].dtype], im: Scalar[ComplexSIMD[cdtype, width].dtype]) -> Self
static
Constructs a ComplexSIMD instance from scalar real and imaginary values.
Example:
Args:
re(Scalar): Scalar value for the real component.im(Scalar): Scalar value for the imaginary component.
Returns:
Self
from_polar¶
from_polar(r: Scalar[ComplexSIMD[cdtype, width].dtype], theta: Scalar[ComplexSIMD[cdtype, width].dtype]) -> Self where ComplexSIMD[cdtype, width].dtype.is_floating_point()
static
Constructs a ComplexSIMD instance from polar coordinates.
Example:
Args:
r(Scalar): Magnitude (radius).theta(Scalar): Angle (in radians).
Returns:
Self
reciprocal¶
Returns the element-wise reciprocal (1 / self) of the ComplexSIMD instance.
Args:
self(Self)
Returns:
Self
Raises
elem_pow¶
Overload 1¶
Raises each component of this ComplexSIMD to the power of the corresponding component in another ComplexSIMD.
Args:
self(Self)other(Self): Another ComplexSIMD instance.
Returns:
Self
Overload 2¶
Raises each component of this ComplexSIMD to a scalar exponent.
Args:
self(Self)exponent(Scalar): Scalar exponent to apply to both real and imaginary parts.
Returns:
Self
allclose¶
allclose(self, other: Self, *, rtol: Scalar[ComplexSIMD[cdtype, width].dtype] = 1.0000000000000001E-5, atol: Scalar[ComplexSIMD[cdtype, width].dtype] = 1.0E-8) -> Bool
Checks if two ComplexSIMD instances are approximately equal within given tolerances.
For each lane, compares the real and imaginary parts using the formula: abs(a - b) <= atol + rtol * abs(b) where a and b are the corresponding components of self and other.
Note: For SIMD width > 1, all lanes must satisfy the tolerance criteria.
Args:
self(Self)other(Self): Another ComplexSIMD instance to compare against.rtol(Scalar): Relative tolerance.atol(Scalar): Absolute tolerance.
Returns:
Bool
write_to¶
Returns a string representation of the ComplexSIMD instance.
For width == 1, the format is: (re + im j). For width > 1, the format is: [(re0 + im0 j), (re1 + im1 j), ...].
Parameters:
W(Writer)
Args:
self(Self)writer(W)[mut]
__repr__¶
Returns a string representation of the ComplexSIMD instance for debugging. ComplexSIMD[dtype](re=<real SIMD>, im=<imag SIMD>).
Args:
self(Self)
Returns:
String
Raises
item¶
Returns the scalar value for the specified lane index and component.
Example:
from numojo.prelude import *
var c_simd = nm.ComplexSIMD[cf32, 2](SIMD[f32, 2](1, 2), SIMD[f32, 2](3, 4)) # [(1 + 3j), (2 + 4j)]
var re0 = c_simd.item["re"](0) # 1.0
var im1 = c_simd.item["im"](1) # 4.0
Parameters:
name(String): Name of the component ('re' or 'im').
Args:
self(Self)idx(Int): Lane index to retrieve.
Returns:
Scalar
Raises
- Error if the component name is invalid.
- Error if lane index is out of range for the SIMD width.
itemset¶
Sets the scalar value for the specified lane index and component.
Example:
from numojo.prelude import *
var c_simd = nm.ComplexSIMD[cf32, 2](SIMD[f32, 2](1, 2), SIMD[f32, 2](3, 4)) # [(1 + 3j), (2 + 4j)]
c_simd.itemset["re"](0, 5.0) # Now first complex number is (5 + 3j)
c_simd.itemset["im"](1, 6.0) # Now second complex number is (2 + 6j)
Parameters:
name(String): Name of the component ('re' or 'im').
Args:
self(Self)[mut]idx(Int): Lane index to set.val(Scalar): Scalar value to assign to the specified component.
Raises
- Error if the component name is invalid.
- Error if lane index is out of range for the SIMD width.
__abs__¶
Returns the magnitude (absolute value) of the complex number(s).
Args:
self(Self)
Returns:
SIMD
norm¶
Returns the squared magnitude (norm) of the complex number(s).
Args:
self(Self)
Returns:
SIMD
ImaginaryUnit¶
Memory convention: register_passable_trivial
Implements: AnyType, Boolable, Copyable, ImplicitlyCopyable, ImplicitlyDestructible, Movable, RegisterPassable, Stringable, TrivialRegisterPassable, Writable
Constant representing the imaginary unit complex number 0 + 1j.
The ImaginaryUnit struct provides a convenient way to work with the imaginary unit in complex arithmetic operations. It supports arithmetic operations with SIMD vectors, scalars, and other complex numbers, enabling Python-like syntax for complex number creation.
Examples:
from numojo.prelude import *
# Create complex numbers using the imaginary unit
var z1 = 3 + 4 * `1j` # 3 + 4j
var z2 = `1j` * 2 # 0 + 2j
var z3 = 5.0 + `1j` # 5 + 1j
# Powers of the imaginary unit
print(`1j` ** 0) # 1 + 0j
print(`1j` ** 1) # 0 + 1j
print(`1j` ** 2) # -1 + 0j
print(`1j` ** 3) # 0 - 1j
# SIMD complex vectors
var c4 = SIMD[f32, 4](1.0) + `1j` * SIMD[f32, 4](2.0) # ComplexSIMD[cf32, 4]
var c5 = SIMD[f64, 2](3.0, 4.0) + `1j` # ComplexSIMD[cf64, 2]
var d = SIMD[f32, 2](1) + SIMD[f32, 2](2) * `1j` # creates [( 1 + 2 j) (1 + 2 j)]
# Mathematical properties
var c6 = `1j` * `1j` # -1 (Scalar[f64])
var c7 = `1j` ** 3 # (0 - 1j) (ComplexScalar[cf64])
var c8 = (1 + `1j`) / `1j` # (1 - 1j) (ComplexScalar[cf64])
Aliases¶
__del__is_trivial¶
Value: True
__move_ctor_is_trivial¶
Value: True
__copy_ctor_is_trivial¶
Value: True
Methods¶
__init__¶
static
Constructor for ImaginaryUnit.
Creates an instance representing the imaginary unit 1j.
Returns:
Self
__bool__¶
Returns the boolean value of the imaginary unit.
Examples:
Args:
self(Self)
Returns:
Bool
__neg__¶
Returns the negation of the imaginary unit: -1j.
Examples:
Args:
self(Self)
Returns:
ComplexSIMD
__add__¶
Overload 1¶
__add__[dtype: DType, width: Int](self, other: SIMD[dtype, width]) -> ComplexSIMD[ComplexDType(dtype), width]
Returns the sum of the imaginary unit 1j and a SIMD vector.
Examples:
from numojo.prelude import *
var vec = SIMD[DType.float32, 4](1.0, 2.0, 3.0, 4.0)
var result = `1j` + vec # [1+1j, 2+1j, 3+1j, 4+1j]
Parameters:
dtype(DType)width(Int)
Args:
self(Self)other(SIMD): SIMD vector to add to the imaginary unit.
Returns:
ComplexSIMD
Overload 2¶
Returns the sum of the imaginary unit 1j and a scalar.
Examples:
Parameters:
dtype(DType)
Args:
self(Self)other(Scalar): Scalar to add to the imaginary unit.
Returns:
ComplexSIMD
Overload 3¶
Returns the sum of the imaginary unit 1j and an integer.
Examples:
Args:
self(Self)other(Int): Integer to add to the imaginary unit.
Returns:
ComplexSIMD
Overload 4¶
Returns the sum of the imaginary unit with itself: 1j + 1j = 2j.
Examples:
Args:
self(Self)other(Self): Another imaginary unit to add.
Returns:
ComplexSIMD
__sub__¶
Overload 1¶
__sub__[dtype: DType, width: Int](self, other: SIMD[dtype, width]) -> ComplexSIMD[ComplexDType(dtype), width]
Returns the difference of the imaginary unit and a SIMD vector.
Parameters:
dtype(DType)width(Int)
Args:
self(Self)other(SIMD)
Returns:
ComplexSIMD
Overload 2¶
Returns the difference of the imaginary unit and a scalar.
Parameters:
dtype(DType)
Args:
self(Self)other(Scalar)
Returns:
ComplexSIMD
Overload 3¶
Returns the difference of the imaginary unit and an integer.
Args:
self(Self)other(Int)
Returns:
ComplexSIMD
Overload 4¶
Returns the difference of the imaginary unit with itself: 1j - 1j = 0.
Examples:
Args:
self(Self)other(Self): Another imaginary unit to subtract.
Returns:
Float64
__mul__¶
Overload 1¶
__mul__[dtype: DType, width: Int](self, other: SIMD[dtype, width]) -> ComplexSIMD[ComplexDType(dtype), width]
Parameters:
dtype(DType)width(Int)
Args:
self(Self)other(SIMD)
Returns:
ComplexSIMD
Overload 2¶
Parameters:
dtype(DType)
Args:
self(Self)other(Scalar)
Returns:
ComplexSIMD
Overload 3¶
Args:
self(Self)other(Int)
Returns:
ComplexSIMD
Overload 4¶
Returns the product of the imaginary unit with itself: 1j * 1j = -1.
Examples:
Args:
self(Self)other(Self): Another imaginary unit to multiply with.
Returns:
Float64
__truediv__¶
Overload 1¶
__truediv__[dtype: DType, width: Int](self, other: SIMD[dtype, width]) -> ComplexSIMD[ComplexDType(dtype), width]
Returns the division of the imaginary unit by a SIMD vector.
Parameters:
dtype(DType)width(Int)
Args:
self(Self)other(SIMD)
Returns:
ComplexSIMD
Overload 2¶
Returns the division of the imaginary unit by a scalar.
Parameters:
dtype(DType)
Args:
self(Self)other(Scalar)
Returns:
ComplexSIMD
Overload 3¶
Returns the division of the imaginary unit by itself: 1j / 1j = 1.
Examples:
Args:
self(Self)other(Self): Another imaginary unit to divide by.
Returns:
Float64
__pow__¶
Returns the imaginary unit raised to an integer power.
The powers of 1j cycle with period 4: - 1j^0 = 1 - 1j^1 = 1j - 1j^2 = -1 - 1j^3 = -1j - 1j^4 = 1 (cycle repeats)
Examples:
from numojo.prelude import *
print(`1j` ** 0) # (1 + 0j)
print(`1j` ** 1) # (0 + 1j)
print(`1j` ** 2) # (-1 + 0j)
print(`1j` ** 3) # (0 - 1j)
print(`1j` ** 4) # (1 + 0j)
Args:
self(Self)exponent(Int): Integer exponent.
Returns:
ComplexSIMD
__radd__¶
Overload 1¶
__radd__[dtype: DType, width: Int](self, other: SIMD[dtype, width]) -> ComplexSIMD[ComplexDType(dtype), width]
Returns the sum of a SIMD vector and the imaginary unit.
Parameters:
dtype(DType)width(Int)
Args:
self(Self)other(SIMD)
Returns:
ComplexSIMD
Overload 2¶
Returns the sum of a scalar and the imaginary unit.
Parameters:
dtype(DType)
Args:
self(Self)other(Scalar)
Returns:
ComplexSIMD
Overload 3¶
Returns the sum of an integer and the imaginary unit.
Args:
self(Self)other(Int)
Returns:
ComplexSIMD
__rsub__¶
Overload 1¶
__rsub__[dtype: DType, width: Int](self, other: SIMD[dtype, width]) -> ComplexSIMD[ComplexDType(dtype), width]
Returns the difference of a SIMD vector and the imaginary unit.
Parameters:
dtype(DType)width(Int)
Args:
self(Self)other(SIMD)
Returns:
ComplexSIMD
Overload 2¶
Returns the difference of a scalar and the imaginary unit.
Parameters:
dtype(DType)
Args:
self(Self)other(Scalar)
Returns:
ComplexSIMD
Overload 3¶
Returns the difference of an integer and the imaginary unit.
Args:
self(Self)other(Int)
Returns:
ComplexSIMD
__rmul__¶
Overload 1¶
__rmul__[dtype: DType, width: Int](self, other: SIMD[dtype, width]) -> ComplexSIMD[ComplexDType(dtype), width]
Parameters:
dtype(DType)width(Int)
Args:
self(Self)other(SIMD)
Returns:
ComplexSIMD
Overload 2¶
Parameters:
dtype(DType)
Args:
self(Self)other(Scalar)
Returns:
ComplexSIMD
Overload 3¶
Args:
self(Self)other(Int)
Returns:
ComplexSIMD
__rtruediv__¶
Overload 1¶
__rtruediv__[dtype: DType, width: Int](self, other: SIMD[dtype, width]) -> ComplexSIMD[ComplexDType(dtype), width]
Returns the division of a SIMD vector by the imaginary unit.
Parameters:
dtype(DType)width(Int)
Args:
self(Self)other(SIMD): SIMD vector to be divided by the imaginary unit.
Returns:
ComplexSIMD
Overload 2¶
Returns the division of a scalar by the imaginary unit.
Parameters:
dtype(DType)
Args:
self(Self)other(Scalar): Scalar to be divided by the imaginary unit.
Returns:
ComplexSIMD
Overload 3¶
Returns the division of an integer by the imaginary unit.
Args:
self(Self)other(Int): Integer to be divided by the imaginary unit.
Returns:
ComplexSIMD
conj¶
Returns the complex conjugate of the imaginary unit.
Examples:
Args:
self(Self)
Returns:
ComplexSIMD
write_to¶
Writes the string representation of the imaginary unit to a writer.
Parameters:
W(Writer)
Args:
self(Self)writer(W)[mut]: Writer instance to write the string representation to.