Skip to content

Commit bd77688

Browse files
committed
Merge vector and util into norm submod
1 parent cd3023d commit bd77688

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

src/assert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use ndarray::*;
44

55
use super::types::*;
6-
use super::vector::*;
6+
use super::norm::*;
77

88
pub fn rclose<A, Tol>(test: A, truth: A, rtol: Tol) -> Result<Tol, Tol>
99
where A: Field + Absolute<Output = Tol>,

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ pub mod solve;
5757
pub mod cholesky;
5858
pub mod eigh;
5959

60-
pub mod vector;
6160
pub mod matrix;
6261
pub mod square;
6362
pub mod triangular;
6463

65-
pub mod util;
6664
pub mod generate;
6765
pub mod assert;
66+
pub mod norm;
67+
6868
pub mod prelude;

src/vector.rs renamed to src/norm.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Define trait for vectors
22
3+
use std::ops::*;
34
use ndarray::*;
5+
46
use super::types::*;
57

68
/// Define norm as a metric linear space (not as a matrix)
@@ -40,3 +42,23 @@ impl<A, S, D, T> Norm for ArrayBase<S, D>
4042
})
4143
}
4244
}
45+
46+
pub enum NormalizeAxis {
47+
Row = 0,
48+
Column = 1,
49+
}
50+
51+
/// normalize in L2 norm
52+
pub fn normalize<A, S, T>(mut m: ArrayBase<S, Ix2>, axis: NormalizeAxis) -> (ArrayBase<S, Ix2>, Vec<T>)
53+
where A: Field + Absolute<Output = T> + Div<T, Output = A>,
54+
S: DataMut<Elem = A>,
55+
T: RealField
56+
{
57+
let mut ms = Vec::new();
58+
for mut v in m.axis_iter_mut(Axis(axis as usize)) {
59+
let n = v.norm();
60+
ms.push(n);
61+
v.map_inplace(|x| *x = *x / n)
62+
}
63+
(m, ms)
64+
}

src/prelude.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
pub use vector::Norm;
21
pub use matrix::Matrix;
32
pub use square::SquareMatrix;
43
pub use triangular::*;
5-
pub use util::*;
4+
pub use norm::*;
65
pub use types::*;
76
pub use generate::*;
87
pub use assert::*;

src/util.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,3 @@ use std::ops::Div;
55

66
use super::types::*;
77
use super::vector::*;
8-
9-
pub enum NormalizeAxis {
10-
Row = 0,
11-
Column = 1,
12-
}
13-
14-
/// normalize in L2 norm
15-
pub fn normalize<A, S, T>(mut m: ArrayBase<S, Ix2>, axis: NormalizeAxis) -> (ArrayBase<S, Ix2>, Vec<T>)
16-
where A: Field + Absolute<Output = T> + Div<T, Output = A>,
17-
S: DataMut<Elem = A>,
18-
T: RealField
19-
{
20-
let mut ms = Vec::new();
21-
for mut v in m.axis_iter_mut(Axis(axis as usize)) {
22-
let n = v.norm();
23-
ms.push(n);
24-
v.map_inplace(|x| *x = *x / n)
25-
}
26-
(m, ms)
27-
}

0 commit comments

Comments
 (0)