File tree Expand file tree Collapse file tree 3 files changed +32
-7
lines changed Expand file tree Collapse file tree 3 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -60,5 +60,6 @@ pub mod triangular;
60
60
pub mod generate;
61
61
pub mod assert;
62
62
pub mod norm;
63
+ pub mod trace;
63
64
64
65
pub mod prelude;
Original file line number Diff line number Diff line change 1
1
2
- pub use types:: * ;
3
- pub use generate:: * ;
4
2
pub use assert:: * ;
3
+ pub use generate:: * ;
4
+ pub use types:: * ;
5
5
6
- pub use qr:: * ;
7
- pub use svd:: * ;
6
+ pub use cholesky:: * ;
7
+ pub use eigh:: * ;
8
+ pub use norm:: * ;
8
9
pub use opnorm:: * ;
10
+ pub use qr:: * ;
9
11
pub use solve:: * ;
10
- pub use eigh :: * ;
11
- pub use cholesky :: * ;
12
+ pub use svd :: * ;
13
+ pub use trace :: * ;
12
14
pub use triangular:: * ;
13
- pub use norm:: * ;
Original file line number Diff line number Diff line change
1
+
2
+ use ndarray:: * ;
3
+
4
+ use super :: types:: * ;
5
+ use super :: error:: * ;
6
+ use super :: layout:: * ;
7
+
8
+ pub trait Trace {
9
+ type Output ;
10
+ fn trace ( & self ) -> Result < Self :: Output > ;
11
+ }
12
+
13
+ impl < A , S > Trace for ArrayBase < S , Ix2 >
14
+ where A : Field ,
15
+ S : Data < Elem = A >
16
+ {
17
+ type Output = A ;
18
+
19
+ fn trace ( & self ) -> Result < Self :: Output > {
20
+ let ( n, _) = self . square_layout ( ) ?. size ( ) ;
21
+ Ok ( ( 0 ..n as usize ) . map ( |i| self [ ( i, i) ] ) . sum ( ) )
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments