trace

Function trace 

Source
pub fn trace<T, L>(a: &DSlice<T, 2, L>) -> T
where T: ComplexFloat + Add<Output = T> + Copy, L: Layout,
Expand description

Computes the trace of a square matrix (sum of diagonal elements).

ยงExamples

use mdarray::tensor;
use mdarray_linalg::trace;

let a = tensor![[1., 2., 3.],
                [4., 5., 6.],
                [7., 8., 9.]];

let tr = trace(&a);
assert_eq!(tr, 15.0);