diff --git a/la/blas.v b/la/blas.v index 53514a776..bfc5c8f23 100644 --- a/la/blas.v +++ b/la/blas.v @@ -3,15 +3,6 @@ module la import vsl.vlas import math -// TODO: @ulises-jeremias to remove this once https://github.com/vlang/v/issues/14047 is finished -fn arr_to_f64arr[T](arr []T) []f64 { - mut ret := []f64{cap: arr.len} - for v in arr { - ret << f64(v) - } - return ret -} - /* * vector_rms_error returns the scaled root-mean-square of the difference between two vectors * with components normalised by a scaling factor @@ -47,7 +38,7 @@ pub fn vector_dot[T](u []T, v []T) T { } return res } - return vlas.ddot(u.len, arr_to_f64arr[T](u), 1, arr_to_f64arr[T](v), 1) + return vlas.ddot(u.len, u, 1, v, 1) } $else { mut res := T{} for i in 0 .. u.len { @@ -66,7 +57,7 @@ pub fn vector_add[T](alpha T, u []T, beta T, v []T) []T { cutoff := 150 if beta == 1 && n > cutoff { res = v.clone() - vlas.daxpy(n, alpha, arr_to_f64arr(u), 1, mut res, 1) + vlas.daxpy(n, alpha, u, 1, mut res, 1) return res } m := n % 4 @@ -136,8 +127,7 @@ pub fn matrix_vector_mul[T](alpha T, a &Matrix[T], u []T) []T { } return v } - vlas.dgemv(false, a.m, a.n, alpha, arr_to_f64arr[T](a.data), a.m, arr_to_f64arr[T](u), - 1, 0.0, mut v, v.len) + vlas.dgemv(false, a.m, a.n, alpha, a.data, a.n, u, 1, 0.0, mut v, 1) return v } $else { mut v := []T{len: a.m} @@ -167,8 +157,7 @@ pub fn matrix_tr_vector_mul[T](alpha T, a &Matrix[T], u []T) []T { } return v } - vlas.dgemv(true, a.m, a.n, alpha, arr_to_f64arr[T](a.data), a.n, arr_to_f64arr[T](u), - 1, 0.0, mut v, v.len) + vlas.dgemv(true, a.m, a.n, alpha, a.data, a.n, u, 1, 0.0, mut v, 1) return v } $else { mut v := []T{len: a.n} @@ -199,8 +188,7 @@ pub fn vector_vector_tr_mul[T](alpha T, u []T, v []T) &Matrix[T] { return m } mut a := []f64{len: u.len * v.len} - vlas.dger(m.m, m.n, alpha, arr_to_f64arr[T](u), 1, arr_to_f64arr[T](v), 1, mut - a, int(math.max(m.m, m.n))) + vlas.dger(m.m, m.n, alpha, u, 1, v, 1, mut a, math.max(m.m, m.n)) return Matrix.raw(u.len, v.len, a) } $else { mut m := Matrix.new[T](u.len, v.len) @@ -220,7 +208,7 @@ pub fn vector_vector_tr_mul[T](alpha T, u []T, v []T) &Matrix[T] { // pub fn matrix_vector_mul_add(alpha f64, a &Matrix[f64], u []f64) []f64 { mut v := []f64{len: a.m} - vlas.dgemv(false, a.m, a.n, alpha, a.data, a.m, u, 1, 1.0, mut v, v.len) + vlas.dgemv(false, a.m, a.n, alpha, a.data, a.m, u, 1, 1.0, mut v, 1) return v } @@ -260,7 +248,7 @@ pub fn matrix_tr_matrix_mul(mut c Matrix[f64], alpha f64, a &Matrix[f64], b &Mat } return } - vlas.dgemm(true, false, a.n, b.n, a.m, alpha, a.data, a.n, b.data, b.m, 0.0, mut c.data, + vlas.dgemm(true, false, a.n, b.n, a.m, alpha, a.data, a.m, b.data, b.m, 0.0, mut c.data, c.m) } diff --git a/ml/workspace_test.v b/ml/workspace_test.v index 5daa16ec0..fa71e2738 100644 --- a/ml/workspace_test.v +++ b/ml/workspace_test.v @@ -50,6 +50,7 @@ fn test_stat_01() { sample_01_check_sat(stat) s, t := stat.sum_vars() - assert s == [23.92] + assert s.len == 1 + assert float64.tolerance(s[0], 23.92, 3.56e-15) assert float64.tolerance(t, 1843.21, 1e-15) }