Skip to content

Commit

Permalink
ADD: Add complex feature & complex module (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Axect committed Apr 18, 2024
1 parent 0f0868e commit bfcebe1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ lapack = { version = "0.19", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
json = { version = "0.12", optional = true }
arrow2 = { version = "0.18", features = ["io_parquet", "io_parquet_compression"], optional = true }
num-complex = { version = "0.4", optional = true }

[package.metadata.docs.rs]
rustdoc-args = [ "--html-in-header", "katex-header.html", "--cfg", "docsrs"]
Expand All @@ -48,3 +49,4 @@ O3 = ["blas", "lapack"]
plot = ["pyo3"]
nc = ["netcdf"]
parquet = ["arrow2"]
complex = ["num-complex", "matrixmultiply/cgemm"]
14 changes: 7 additions & 7 deletions src/structure/complex.rs → src/complex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ pub type C64 = Complex<f64>;
impl Vector for Complex<f64> {
type Scalar = Self;

fn add_vec<'a, 'b>(&'a self, rhs: &'b Self) -> Self {
fn add_vec(&self, rhs: &Self) -> Self {
self + rhs
}

fn sub_vec<'a, 'b>(&'a self, rhs: &'b Self) -> Self {
fn sub_vec(&self, rhs: &Self) -> Self {
self - rhs
}

Expand Down Expand Up @@ -70,15 +70,15 @@ impl FPVector for Vec<Complex<f64>> {
fn filter<F>(&self, f: F) -> Self
where
F: Fn(Self::Scalar) -> bool {
self.into_iter().filter(|&x| f(*x)).map(|&t| t).collect()
self.iter().filter(|&x| f(*x)).cloned().collect()
}

fn take(&self, n: usize) -> Self {
self.iter().take(n).map(|&x| x).collect()
self.iter().take(n).cloned().collect()
}

fn skip(&self, n: usize) -> Self {
self.iter().skip(n).map(|&x| x).collect()
self.iter().skip(n).cloned().collect()
}

fn sum(&self) -> Self::Scalar {
Expand All @@ -93,11 +93,11 @@ impl FPVector for Vec<Complex<f64>> {
impl Vector for Vec<Complex<f64>> {
type Scalar = Complex<f64>;

fn add_vec<'a, 'b>(&'a self, rhs: &'b Self) -> Self {
fn add_vec(&self, rhs: &Self) -> Self {
self.zip_with(|x, y| x + y, rhs)
}

fn sub_vec<'a, 'b>(&'a self, rhs: &'b Self) -> Self {
fn sub_vec(&self, rhs: &Self) -> Self {
self.zip_with(|x, y| x - y, rhs)
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,6 @@ pub mod statistics;
pub mod structure;
pub mod traits;
pub mod util;

#[cfg(feature = "complex")]
pub mod complex;

0 comments on commit bfcebe1

Please sign in to comment.