diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01dc51d17..a611ec4c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,14 +69,6 @@ jobs: - name: Execute Tests using Pure V Backend with Pure C Blas run: ~/.vmodules/vsl/bin/test ${{ matrix.flags }} --use-cblas - if: ${{ matrix.os != 'ubuntu-18.04' }} - - - name: Execute Tests using Pure V Backend and Garbage Collection enabled - run: ~/.vmodules/vsl/bin/test ${{ matrix.flags }} --use-gc boehm - - - name: Execute Tests using Pure V Backend with Pure C Blas and Garbage Collection enabled - run: ~/.vmodules/vsl/bin/test ${{ matrix.flags }} --use-cblas --use-gc boehm - if: ${{ matrix.os != 'ubuntu-18.04' }} run-tests-on-macos: runs-on: ${{ matrix.os }} @@ -118,18 +110,7 @@ jobs: run: mv ./vsl ~/.vmodules - name: Execute Tests using Pure V Backend - # TODO: Remove continue-on-error when CI is fixed for macOS - continue-on-error: true - run: ~/.vmodules/vsl/bin/test + run: ~/.vmodules/vsl/bin/test --skip-examples - name: Execute Tests using Pure V Backend with Pure C Blas - continue-on-error: true - run: ~/.vmodules/vsl/bin/test --use-cblas - - - name: Execute Tests using Pure V Backend and Garbage Collection enabled - continue-on-error: true - run: ~/.vmodules/vsl/bin/test --use-gc boehm - - - name: Execute Tests using Pure V Backend with Pure C Blas and Garbage Collection enabled - continue-on-error: true - run: ~/.vmodules/vsl/bin/test --use-cblas --use-gc boehm + run: ~/.vmodules/vsl/bin/test --use-cblas --skip-examples diff --git a/float/float64/ge_test.v b/float/float64/ge_test.v index 208df1982..25d051c96 100644 --- a/float/float64/ge_test.v +++ b/float/float64/ge_test.v @@ -69,7 +69,7 @@ struct GeTest { } fn test_ger() { - tol := 1e-15 + tol := $if macos { 7e-15 } $else { 1e-15 } x_gd_val, y_gd_val, a_gd_val := -0.5, 1.5, 10 gd_ln := 4 @@ -87,7 +87,7 @@ fn test_ger() { alpha := 1.0 ger(u32(m), u32(n), alpha, x, 1, y, 1, mut a, u32(n)) for i, w in test.want { - assert tolerance(a[i], w, tol) + assert tolerance(a[i], w, tol), 'got: ${a[i]}, want: ${w}, tol: ${tol}' } } } diff --git a/iter/ranges_test.v b/iter/ranges_test.v index 6102417aa..e6c2eae99 100644 --- a/iter/ranges_test.v +++ b/iter/ranges_test.v @@ -1,5 +1,7 @@ module iter +import math + fn test_int_iter() { args := [[i64(27), 11, -5], [i64(13), 1, -6], [i64(-19), -35, -6], [i64(-88), -29, 8], [i64(17), -94, 2], [i64(30), 45, 6], @@ -52,10 +54,12 @@ fn test_float_iter() { for i, values in args { r := FloatIter.new(start: values[0], stop: values[1], step: values[2])! for j, n in r { - if !n.eq_epsilon(expected[i][j]) { - println('${n}, ${expected[i][j]}') + $if macos { + tol := 2e-15 + assert math.tolerance(expected[i][j], n, tol), 'got: ${n}, want: ${expected[i][j]}, tol: ${tol}' + } $else { + assert n.eq_epsilon(expected[i][j]), 'got: ${n}, want: ${expected[i][j]}' } - assert n.eq_epsilon(expected[i][j]) } assert r.len == expected[i].len } @@ -90,7 +94,12 @@ fn test_linear_iter() { for i, lim in limits { l := LinearIter.new(start: lim[0], stop: lim[1], len: lens[i], endpoint: endpoints[i])! for j, n in l { - assert n.eq_epsilon(expected[i][j]) + $if macos { + tol := 2e-15 + assert math.tolerance(expected[i][j], n, tol), 'got: ${n}, want: ${expected[i][j]}' + } $else { + assert n.eq_epsilon(expected[i][j]), 'got: ${n}, want: ${expected[i][j]}' + } } assert l.len == expected[i].len } diff --git a/la/matrix_ops_test.v b/la/matrix_ops_test.v index d0ee4571d..d856ed121 100644 --- a/la/matrix_ops_test.v +++ b/la/matrix_ops_test.v @@ -29,7 +29,11 @@ fn test_det() { [4.0, -2.0, 5.0], [2.0, 8.0, 7.0], ]) - assert matrix_det(mat_b) == -306 + $if macos { + assert math.tolerance(matrix_det(mat_b), -306, la.matrix_tests_tol) + } $else { + assert matrix_det(mat_b) == -306 + } } fn test_matrix_inv_small() { diff --git a/vlas/cflags_d_cblas.v b/vlas/cflags_d_cblas.v index 9b72c3d76..fd0a90c1f 100644 --- a/vlas/cflags_d_cblas.v +++ b/vlas/cflags_d_cblas.v @@ -6,5 +6,11 @@ module vlas #flag windows -lgfortran #flag darwin -I/usr/local/opt/openblas/include #flag darwin -L/usr/local/opt/openblas/lib +#flag darwin -L/usr/local/opt/lapack/lib #flag -I@VMODROOT #flag -lopenblas -llapacke + +$if macos { + #include + #include +} diff --git a/vlas/cflags_notd_cblas.v b/vlas/cflags_notd_cblas.v index ff8f70691..148523b1a 100644 --- a/vlas/cflags_notd_cblas.v +++ b/vlas/cflags_notd_cblas.v @@ -8,3 +8,7 @@ module vlas #flag darwin -L/usr/local/opt/lapack/lib #flag -I@VMODROOT #flag -llapacke + +$if macos { + #include +} diff --git a/vlas/conversions.v b/vlas/conversions.v index ba8416806..520017ade 100644 --- a/vlas/conversions.v +++ b/vlas/conversions.v @@ -7,29 +7,19 @@ import vsl.errors import vsl.vlas.internal.vblas pub fn c_trans(trans bool) vblas.Transpose { - if trans { - return .trans - } - return .no_trans + return if trans { .trans } else { .no_trans } } pub fn c_uplo(up bool) vblas.Uplo { - if up { - return .upper - } - return .lower + return if up { .upper } else { .lower } } fn l_uplo(up bool) u8 { return if up { `U` } else { `L` } } -fn job_vlr(do_calc bool) &char { - return &char(if do_calc { - 'V' - } else { - 'N' - }.str) +fn job_vlr(do_calc bool) rune { + return if do_calc { `V` } else { `N` } } // slice_to_col_major converts nested slice into an array representing a col-major matrix diff --git a/vlas/lapack.v b/vlas/lapack_common.v similarity index 92% rename from vlas/lapack.v rename to vlas/lapack_common.v index e9c306366..64ad4c304 100644 --- a/vlas/lapack.v +++ b/vlas/lapack_common.v @@ -15,9 +15,7 @@ fn C.LAPACKE_dpotrf(matrix_layout vblas.MemoryLayout, up u32, n int, a &f64, lda fn C.LAPACKE_dgeev(matrix_layout vblas.MemoryLayout, calc_vl &char, calc_vr &char, n int, a &f64, lda int, wr &f64, wi &f64, vl &f64, ldvl_ int, vr &f64, ldvr_ int) int -fn C.LAPACKE_dlange(matrix_layout vblas.MemoryLayout, norm &char, m int, n int, a &f64, lda int, work &f64) f64 - -fn C.LAPACKE_dsyev(matrix_layout vblas.MemoryLayout, jobz &char, uplo &char, n int, a &f64, lda int, w &f64, work &f64, lwork int) int +fn C.LAPACKE_dsyev(matrix_layout vblas.MemoryLayout, jobz byte, uplo byte, n int, a &f64, lda int, w &f64, work &f64, lwork int) int fn C.LAPACKE_dgebal(matrix_layout vblas.MemoryLayout, job &char, n int, a &f64, lda int, ilo int, ihi int, scale &f64) int @@ -191,14 +189,10 @@ pub fn dgeev(calc_vl bool, calc_vr bool, n int, mut a []f64, lda int, wr []f64, ldvr = 1 } unsafe { - info := C.LAPACKE_dgeev(.row_major, job_vlr(calc_vl), job_vlr(calc_vr), n, &a[0], - lda, &wr[0], &wi[0], &vvl, ldvl, &vvr, ldvr) + info := C.LAPACKE_dgeev(.row_major, &char(job_vlr(calc_vl).str().str), &char(job_vlr(calc_vr).str().str), + n, &a[0], lda, &wr[0], &wi[0], &vvl, ldvl, &vvr, ldvr) if info != 0 { errors.vsl_panic('lapack failed', .efailed) } } } - -pub fn dlange(norm &char, m int, n int, a []f64, lda int, work []f64) f64 { - return unsafe { C.LAPACKE_dlange(.row_major, norm, m, n, &a[0], lda, &work[0]) } -} diff --git a/vlas/lapack_default.c.v b/vlas/lapack_default.c.v new file mode 100644 index 000000000..392faeca0 --- /dev/null +++ b/vlas/lapack_default.c.v @@ -0,0 +1,11 @@ +module vlas + +import vsl.vlas.internal.vblas + +fn C.LAPACKE_dlange(matrix_layout vblas.MemoryLayout, norm &char, m int, n int, a &f64, lda int, work &f64) f64 + +pub fn dlange(norm rune, m int, n int, a []f64, lda int, work []f64) f64 { + return unsafe { + C.LAPACKE_dlange(.row_major, &char(norm.str().str), m, n, &a[0], lda, &work[0]) + } +} diff --git a/vlas/lapack_macos.c.v b/vlas/lapack_macos.c.v new file mode 100644 index 000000000..2c0cbc7c3 --- /dev/null +++ b/vlas/lapack_macos.c.v @@ -0,0 +1,7 @@ +module vlas + +fn C.LAPACKE_dlange(norm &char, m int, n int, a &f64, lda int, work &f64) f64 + +pub fn dlange(norm rune, m int, n int, a []f64, lda int, work []f64) f64 { + return unsafe { C.LAPACKE_dlange(&char(norm.str().str), m, n, &a[0], lda, &work[0]) } +}