From d2be745d65a5e9a92fdd1a6a020c0621bda59198 Mon Sep 17 00:00:00 2001 From: AmanBoronbaev <149809343+AmanBoronbaev@users.noreply.github.com> Date: Wed, 2 Dec 2026 22:02:23 +0300 Subject: [PATCH] Show how to take the exponential of complex array elements --- Cargo.toml | 1 + src/numeric/impl_float_maths.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8cd9c33ce..9691a06c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,6 +52,7 @@ serde = { version = "1.0", optional = true, default-features = false, features = rawpointer = { version = "0.2" } [dev-dependencies] +num-complex = { workspace = true, features = ["std"] } defmac = "0.2" quickcheck = { workspace = true } approx = { workspace = true, default-features = true } diff --git a/src/numeric/impl_float_maths.rs b/src/numeric/impl_float_maths.rs index edcc03c01..8453faefd 100644 --- a/src/numeric/impl_float_maths.rs +++ b/src/numeric/impl_float_maths.rs @@ -100,7 +100,21 @@ where fn recip /// Square root of each element. fn sqrt - /// `e^x` of each element (exponential function). + /// `e^x` of each real floating-point element. + /// + /// With `num-complex`'s default features, apply the scalar exponential to + /// complex elements using [`mapv`](Self::mapv). + /// + /// ``` + /// use ndarray::array; + /// use num_complex::Complex64; + /// use std::f64::consts::FRAC_PI_2; + /// + /// let z = array![Complex64::new(0.0, 0.0), Complex64::new(0.0, FRAC_PI_2)]; + /// let result = z.mapv(Complex64::exp); + /// assert_eq!(result[0], Complex64::new(1.0, 0.0)); + /// assert!((result[1] - Complex64::i()).norm() < 1e-12); + /// ``` fn exp /// `2^x` of each element. fn exp2