ndarray-linalg icon indicating copy to clipboard operation
ndarray-linalg copied to clipboard

MagnitudeCorrection trait should be public

Open relf opened this issue 3 years ago • 0 comments

I tried to use TruncatedSvd with a generic Float type but it can not compile as it has to use the MagnitudeCorrection trait which is not exported from ndarray-linalg::lobpcg module. My test program here:

use ndarray::{arr1, arr2, Array1, Array2, ScalarOperand};
use ndarray_linalg::{close_l2, Lapack, TruncatedOrder, TruncatedSvd};  // should use MagnitudeCorrection as well
use num_traits::Float;

fn test_truncated_svd<F: Float + Lapack + ScalarOperand + Default>(  // should add MagnitudeCorrection trait bound
    a: Array2<F>,
) -> Array1<F> {
    let res = TruncatedSvd::new(a, TruncatedOrder::Largest)
        .precision(1e-5)
        .maxiter(10)
        .decompose(2)
        .unwrap();

    let (_, sigma, _) = res.values_vectors();
    sigma
}

fn main() {
    let a = arr2(&[[3., 2., 2.], [2., 3., -2.]]);

    let sigma = test_truncated_svd(a);

    close_l2(&sigma, &arr1(&[5.0, 3.0]), 1e-5);
}

relf avatar Apr 07 '21 06:04 relf