pub fn basic_trace<F>(a: &ArrayView2<'_, F>) -> LinalgResult<F>
Expand description
Compute the trace of a square matrix.
The trace is the sum of the diagonal elements.
§Arguments
a
- A square matrix
§Returns
- Trace of the matrix
§Examples
use scirs2_core::ndarray::array;
use scirs2_linalg::basic_trace;
let a = array![[1.0_f64, 2.0], [3.0, 4.0]];
let tr = basic_trace(&a.view()).unwrap();
assert!((tr - 5.0).abs() < 1e-10);