Skip to main content

Complex

Struct Complex 

Source
#[repr(C)]
pub struct Complex<F> { pub re: F, pub im: F, }
Expand description

A complex number with real and imaginary parts of type F.

It orders lexicographically (by the real part, then the imaginary part), as lax.max, lax.min, and lax.sort compare complex numbers.

Fields§

§re: F

The real part.

§im: F

The imaginary part.

Implementations§

Source§

impl<F> Complex<F>

Source

pub const fn new(re: F, im: F) -> Complex<F>

Creates a complex number from its real and imaginary parts.

Source§

impl Complex<f32>

Source

pub fn conj(self) -> Complex<f32>

The complex conjugate.

Source

pub fn div_xla(self, o: Complex<f32>) -> Complex<f32>

x / y by Smith’s algorithm, with XLA’s handling of zero and infinite operands when the quotient would be NaN.

Source

pub fn abs(self) -> f32

|x|, computed as JAX lowers it (lax.hypot of the real and imaginary parts, scaled by a power of two against overflow and underflow).

Source

pub fn arg(self) -> f32

The argument (atan2(im, re)).

Source

pub fn sign(self) -> Complex<f32>

x / |x|, or x where x is zero.

Source

pub fn exp(self) -> Complex<f32>

e^x = e^a (cos b + i sin b) (the imaginary part of a real argument is kept, as in XLA).

Source

pub fn expm1(self) -> Complex<f32>

e^x - 1.

Source

pub fn log(self) -> Complex<f32>

log|x| + i arg(x).

Source

pub fn log1p(self) -> Complex<f32>

log(1 + x).

Source

pub fn sqrt(self) -> Complex<f32>

The principal square root.

Source

pub fn rsqrt(self) -> Complex<f32>

1 / sqrt(x).

Source

pub fn sin(self) -> Complex<f32>

The sine, as JAX’s _sin_complex computes it.

Source

pub fn cos(self) -> Complex<f32>

The cosine, as JAX’s _cos_complex computes it.

Source

pub fn tan(self) -> Complex<f32>

The tangent: tan(x) = -i tanh(i x).

Source

pub fn tanh(self) -> Complex<f32>

The hyperbolic tangent.

Source

pub fn logistic(self) -> Complex<f32>

1 / (1 + e^-x), as XLA expands logistic.

Source

pub fn pow(self, y: Complex<f32>) -> Complex<f32>

x^y: e^(c log|x| - d arg x) (cos q + i sin q) with q = c arg x + d log|x| for y = c + di, with the special cases of XLA’s CPU implementation: x^0 is 1, a positive real x to a real y is real, 1^y is 1, and 0^y is 0 for real y > 0.

Source

pub fn max(self, o: Complex<f32>) -> Complex<f32>

The maximum, comparing lexicographically as JAX lowers max of complex numbers (y unless x is greater).

Source

pub fn min(self, o: Complex<f32>) -> Complex<f32>

The minimum, comparing lexicographically as JAX lowers min of complex numbers (y unless x is less).

Source

pub fn is_finite(self) -> bool

Whether both parts are finite.

Source§

impl Complex<f64>

Source

pub fn conj(self) -> Complex<f64>

The complex conjugate.

Source

pub fn div_xla(self, o: Complex<f64>) -> Complex<f64>

x / y by Smith’s algorithm, with XLA’s handling of zero and infinite operands when the quotient would be NaN.

Source

pub fn abs(self) -> f64

|x|, computed as JAX lowers it (lax.hypot of the real and imaginary parts, scaled by a power of two against overflow and underflow).

Source

pub fn arg(self) -> f64

The argument (atan2(im, re)).

Source

pub fn sign(self) -> Complex<f64>

x / |x|, or x where x is zero.

Source

pub fn exp(self) -> Complex<f64>

e^x = e^a (cos b + i sin b) (the imaginary part of a real argument is kept, as in XLA).

Source

pub fn expm1(self) -> Complex<f64>

e^x - 1.

Source

pub fn log(self) -> Complex<f64>

log|x| + i arg(x).

Source

pub fn log1p(self) -> Complex<f64>

log(1 + x).

Source

pub fn sqrt(self) -> Complex<f64>

The principal square root.

Source

pub fn rsqrt(self) -> Complex<f64>

1 / sqrt(x).

Source

pub fn sin(self) -> Complex<f64>

The sine, as JAX’s _sin_complex computes it.

Source

pub fn cos(self) -> Complex<f64>

The cosine, as JAX’s _cos_complex computes it.

Source

pub fn tan(self) -> Complex<f64>

The tangent: tan(x) = -i tanh(i x).

Source

pub fn tanh(self) -> Complex<f64>

The hyperbolic tangent.

Source

pub fn logistic(self) -> Complex<f64>

1 / (1 + e^-x), as XLA expands logistic.

Source

pub fn pow(self, y: Complex<f64>) -> Complex<f64>

x^y: e^(c log|x| - d arg x) (cos q + i sin q) with q = c arg x + d log|x| for y = c + di, with the special cases of XLA’s CPU implementation: x^0 is 1, a positive real x to a real y is real, 1^y is 1, and 0^y is 0 for real y > 0.

Source

pub fn max(self, o: Complex<f64>) -> Complex<f64>

The maximum, comparing lexicographically as JAX lowers max of complex numbers (y unless x is greater).

Source

pub fn min(self, o: Complex<f64>) -> Complex<f64>

The minimum, comparing lexicographically as JAX lowers min of complex numbers (y unless x is less).

Source

pub fn is_finite(self) -> bool

Whether both parts are finite.

Trait Implementations§

Source§

impl Add for Complex<f32>

Source§

fn add(self, o: Complex<f32>) -> Complex<f32>

x + y.

Source§

type Output = Complex<f32>

The resulting type after applying the + operator.
Source§

impl Add for Complex<f64>

Source§

fn add(self, o: Complex<f64>) -> Complex<f64>

x + y.

Source§

type Output = Complex<f64>

The resulting type after applying the + operator.
Source§

impl BufferElement for Complex<f32>

Source§

fn wrap(v: Vec<Complex<f32>>) -> Buffer

Wraps a vector.
Source§

fn view(b: &Buffer) -> Option<&[Complex<f32>]>

Views a buffer’s elements, if they have this type.
Source§

impl BufferElement for Complex<f64>

Source§

fn wrap(v: Vec<Complex<f64>>) -> Buffer

Wraps a vector.
Source§

fn view(b: &Buffer) -> Option<&[Complex<f64>]>

Views a buffer’s elements, if they have this type.
Source§

impl<F> Clone for Complex<F>
where F: Clone,

Source§

fn clone(&self) -> Complex<F>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F> Copy for Complex<F>
where F: Copy,

Source§

impl<F> Debug for Complex<F>
where F: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<F> Default for Complex<F>
where F: Default,

Source§

fn default() -> Complex<F>

Returns the “default value” for a type. Read more
Source§

impl Div for Complex<f32>

Source§

fn div(self, o: Complex<f32>) -> Complex<f32>

x / y (see Complex::div_xla).

Source§

type Output = Complex<f32>

The resulting type after applying the / operator.
Source§

impl Div for Complex<f64>

Source§

fn div(self, o: Complex<f64>) -> Complex<f64>

x / y (see Complex::div_xla).

Source§

type Output = Complex<f64>

The resulting type after applying the / operator.
Source§

impl Element for Complex<f32>

Source§

fn to_bits(self) -> u64

The bits of the real part in the low half and those of the imaginary part in the high half (c128 has more bits than fit, and panics).

Source§

const DTYPE: DType = DType::C64

The element type.
Source§

type Real = f32

The type of the real and imaginary parts of a complex type, or the type itself for other types (the type of abs).
Source§

fn re(self) -> f32

The real part (the value itself for other types than complex).
Source§

fn im(self) -> f32

The imaginary part (zero for other types than complex).
Source§

fn from_parts(re: f32, im: f32) -> Complex<f32>

The complex number with the given parts (for other types than complex, the real part; the imaginary part is ignored).
Source§

fn to_value(self) -> Value

Widens the value without loss.
Source§

fn from_value(v: Value) -> Complex<f32>

Converts a value, with the semantics of XLA’s convert (see cast).
Source§

fn write_bytes(self, out: &mut Vec<u8>)

Writes the native-endian bytes of the value.
Source§

fn read_bytes(bytes: &[u8]) -> Complex<f32>

Reads a value from native-endian bytes of the right length.
Source§

fn from_bits(bits: u64) -> Complex<f32>

The value of a bit pattern in the low bits (the rest is ignored).
Source§

impl Element for Complex<f64>

Source§

fn to_bits(self) -> u64

The bits of the real part in the low half and those of the imaginary part in the high half (c128 has more bits than fit, and panics).

Source§

const DTYPE: DType = DType::C128

The element type.
Source§

type Real = f64

The type of the real and imaginary parts of a complex type, or the type itself for other types (the type of abs).
Source§

fn re(self) -> f64

The real part (the value itself for other types than complex).
Source§

fn im(self) -> f64

The imaginary part (zero for other types than complex).
Source§

fn from_parts(re: f64, im: f64) -> Complex<f64>

The complex number with the given parts (for other types than complex, the real part; the imaginary part is ignored).
Source§

fn to_value(self) -> Value

Widens the value without loss.
Source§

fn from_value(v: Value) -> Complex<f64>

Converts a value, with the semantics of XLA’s convert (see cast).
Source§

fn write_bytes(self, out: &mut Vec<u8>)

Writes the native-endian bytes of the value.
Source§

fn read_bytes(bytes: &[u8]) -> Complex<f64>

Reads a value from native-endian bytes of the right length.
Source§

fn from_bits(bits: u64) -> Complex<f64>

The value of a bit pattern in the low bits (the rest is ignored).
Source§

impl FfiElement for Complex<f32>

Source§

const DTYPE: FfiDataType = FfiDataType::C64

The FFI type of the elements.
Source§

impl FfiElement for Complex<f64>

Source§

const DTYPE: FfiDataType = FfiDataType::C128

The FFI type of the elements.
Source§

impl LinalgScalar for Complex<f32>

Source§

const IS_COMPLEX: bool = true

Whether the type is complex.
Source§

const ZERO: Complex<f32>

Zero.
Source§

const ONE: Complex<f32>

One.
Source§

const NAN: Complex<f32>

NaN (in both parts for complex types).
Source§

type LinalgReal = f32

The real type of the absolute values (Self for real types; the element type’s Real, whose re, im, and from_parts the algorithms use).
Source§

fn conj(self) -> Complex<f32>

The complex conjugate (the value itself for real types).
Source§

fn abs(self) -> f32

The absolute value (the modulus for complex types).
Source§

fn abs1(self) -> f32

|re| + |im|, by which BLAS’s izamax compares complex values (the absolute value for real types).
Source§

fn abs2(self) -> f32

|x|^2.
Source§

fn scale(self, r: f32) -> Complex<f32>

self * r for a real r.
Source§

fn is_finite(self) -> bool

Whether the value is finite (in both parts).
Source§

fn csqrt(self) -> Complex<f32>

The principal square root (NaN for negative real numbers).
Source§

fn from_real(r: Self::LinalgReal) -> Self

The value of a real number.
Source§

impl LinalgScalar for Complex<f64>

Source§

const IS_COMPLEX: bool = true

Whether the type is complex.
Source§

const ZERO: Complex<f64>

Zero.
Source§

const ONE: Complex<f64>

One.
Source§

const NAN: Complex<f64>

NaN (in both parts for complex types).
Source§

type LinalgReal = f64

The real type of the absolute values (Self for real types; the element type’s Real, whose re, im, and from_parts the algorithms use).
Source§

fn conj(self) -> Complex<f64>

The complex conjugate (the value itself for real types).
Source§

fn abs(self) -> f64

The absolute value (the modulus for complex types).
Source§

fn abs1(self) -> f64

|re| + |im|, by which BLAS’s izamax compares complex values (the absolute value for real types).
Source§

fn abs2(self) -> f64

|x|^2.
Source§

fn scale(self, r: f64) -> Complex<f64>

self * r for a real r.
Source§

fn is_finite(self) -> bool

Whether the value is finite (in both parts).
Source§

fn csqrt(self) -> Complex<f64>

The principal square root (NaN for negative real numbers).
Source§

fn from_real(r: Self::LinalgReal) -> Self

The value of a real number.
Source§

impl Mul for Complex<f32>

Source§

fn mul(self, o: Complex<f32>) -> Complex<f32>

x * y, with the multiplications and additions fused as XLA does on CPU.

Source§

type Output = Complex<f32>

The resulting type after applying the * operator.
Source§

impl Mul for Complex<f64>

Source§

fn mul(self, o: Complex<f64>) -> Complex<f64>

x * y, with the multiplications and additions fused as XLA does on CPU.

Source§

type Output = Complex<f64>

The resulting type after applying the * operator.
Source§

impl Neg for Complex<f32>

Source§

fn neg(self) -> Complex<f32>

-x.

Source§

type Output = Complex<f32>

The resulting type after applying the - operator.
Source§

impl Neg for Complex<f64>

Source§

fn neg(self) -> Complex<f64>

-x.

Source§

type Output = Complex<f64>

The resulting type after applying the - operator.
Source§

impl Ops for Complex<f32>

Source§

fn unary(op: UnaryOp, x: Complex<f32>) -> Complex<f32>

Applies a unary operation.
Source§

fn binary(op: BinaryOp, x: Complex<f32>, y: Complex<f32>) -> Complex<f32>

Applies a binary operation.
Source§

fn is_finite(x: Complex<f32>) -> bool

Returns whether the value is neither infinite nor NaN (always true for integers and booleans).
Source§

fn lowest() -> Complex<f32>

The smallest value (negative infinity for floats): the identity of max.
Source§

fn highest() -> Complex<f32>

The largest value (positive infinity for floats): the identity of min.
Source§

fn ternary(op: TernaryOp, x: Self, y: Self, z: Self) -> Self

Applies a ternary operation (only floats support them).
Source§

impl Ops for Complex<f64>

Source§

fn unary(op: UnaryOp, x: Complex<f64>) -> Complex<f64>

Applies a unary operation.
Source§

fn binary(op: BinaryOp, x: Complex<f64>, y: Complex<f64>) -> Complex<f64>

Applies a binary operation.
Source§

fn is_finite(x: Complex<f64>) -> bool

Returns whether the value is neither infinite nor NaN (always true for integers and booleans).
Source§

fn lowest() -> Complex<f64>

The smallest value (negative infinity for floats): the identity of max.
Source§

fn highest() -> Complex<f64>

The largest value (positive infinity for floats): the identity of min.
Source§

fn ternary(op: TernaryOp, x: Self, y: Self, z: Self) -> Self

Applies a ternary operation (only floats support them).
Source§

impl<F> PartialEq for Complex<F>
where F: PartialEq,

Source§

fn eq(&self, other: &Complex<F>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<F> PartialOrd for Complex<F>
where F: PartialOrd,

Source§

fn partial_cmp(&self, other: &Complex<F>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<F> StructuralPartialEq for Complex<F>
where F: PartialEq,

Source§

impl Sub for Complex<f32>

Source§

fn sub(self, o: Complex<f32>) -> Complex<f32>

x - y.

Source§

type Output = Complex<f32>

The resulting type after applying the - operator.
Source§

impl Sub for Complex<f64>

Source§

fn sub(self, o: Complex<f64>) -> Complex<f64>

x - y.

Source§

type Output = Complex<f64>

The resulting type after applying the - operator.

Auto Trait Implementations§

§

impl<F> Freeze for Complex<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for Complex<F>
where F: RefUnwindSafe,

§

impl<F> Send for Complex<F>
where F: Send,

§

impl<F> Sync for Complex<F>
where F: Sync,

§

impl<F> Unpin for Complex<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for Complex<F>
where F: UnsafeUnpin,

§

impl<F> UnwindSafe for Complex<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<B, T> ArrayLike<B, T> for T
where B: Backend, T: Element,

Source§

fn into_array(self) -> Array<B, T>

Converts to an array.
Source§

fn as_scalar(&self) -> Option<Scalar<B, T>>

Source§

fn with_array<R>(self, f: impl FnOnce(&Array<B, T>) -> R) -> R

Calls f with the array, without copying a borrowed array.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.