input M x N matrix
If true the first min(M,N) columns of u and the first min(M,N) rows of vt are returned in the ndslices u and vt.
import mir.ndslice; auto a = [ 7.52, -1.10, -7.95, 1.08, -0.76, 0.62, 9.34, -7.10, 5.13, 6.62, -5.66, 0.87, -4.75, 8.52, 5.75, 5.30, 1.33, 4.91, -5.49, -3.52, -2.40, -6.77, 2.34, 3.95] .sliced(6, 4); auto r = a.svd; auto sigma = slice!double(a.shape, 0); sigma.diagonal[] = r.sigma; auto m = r.u.mtimes(sigma).mtimes(r.vt); import mir.algorithm.iteration: equal; import mir.math.common: approxEqual; assert(equal!((a, b) => a.approxEqual(b, 1e-8, 1e-8))(a, m));
import std.typecons: Yes; import mir.ndslice; auto a = [ 7.52, -1.10, -7.95, 1.08, -0.76, 0.62, 9.34, -7.10, 5.13, 6.62, -5.66, 0.87, -4.75, 8.52, 5.75, 5.30, 1.33, 4.91, -5.49, -3.52, -2.40, -6.77, 2.34, 3.95] .sliced(6, 4); auto r = a.svd(Yes.slim); assert(r.u.shape == [6, 4]); assert(r.vt.shape == [4, 4]);
Computes the singular value decomposition.