Skip to content

Commit fc54bbc

Browse files
committed
Add inner product
1 parent b5598ec commit fc54bbc

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/inner.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::types::*;
2+
use ndarray::*;
3+
4+
pub trait Inner<S: Data> {
5+
/// Inner product `(self.conjugate, rhs)`
6+
fn inner(&self, rhs: &ArrayBase<S, Ix1>) -> S::Elem;
7+
}
8+
9+
impl<A, S1, S2> Inner<S1> for ArrayBase<S2, Ix1>
10+
where
11+
A: Scalar,
12+
S1: Data<Elem = A>,
13+
S2: Data<Elem = A>,
14+
{
15+
fn inner(&self, rhs: &ArrayBase<S1, Ix1>) -> A {
16+
Zip::from(self)
17+
.and(rhs)
18+
.fold_while(A::zero(), |acc, s, r| FoldWhile::Continue(acc + s.conj() * *r))
19+
.into_inner()
20+
}
21+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub mod diagonal;
4343
pub mod eigh;
4444
pub mod error;
4545
pub mod generate;
46+
pub mod inner;
4647
pub mod lapack;
4748
pub mod layout;
4849
pub mod norm;

0 commit comments

Comments
 (0)