From 702b287d5b3ea78e9591088ea839e03cda25f05a Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 26 Jul 2024 10:12:23 +0300 Subject: [PATCH] fix compilation on macos with latest clang 15 and LAPACK from brew --- la/matrix_ops.v | 3 +-- vlas/lapack_common.v | 12 ++++++++---- vlas/lapack_macos.c.v | 12 ++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/la/matrix_ops.v b/la/matrix_ops.v index 9e8cfa1f8..a541ed011 100644 --- a/la/matrix_ops.v +++ b/la/matrix_ops.v @@ -90,8 +90,7 @@ pub fn matrix_svd(mut s []f64, mut u Matrix[f64], mut vt Matrix[f64], mut a Matr if copy_a { acpy = a.clone() } - vlas.dgesvd(&char('A'.str), &char('A'.str), a.m, a.n, acpy.data, 1, s, u.data, a.m, - vt.data, a.n, superb) + vlas.dgesvd(`A`, `A`, a.m, a.n, acpy.data, 1, s, u.data, a.m, vt.data, a.n, superb) } // matrix_inv computes the inverse of a general matrix (square or not). It also computes the diff --git a/vlas/lapack_common.v b/vlas/lapack_common.v index 8a30e8f5e..578c34c93 100644 --- a/vlas/lapack_common.v +++ b/vlas/lapack_common.v @@ -74,9 +74,13 @@ pub fn dgesv(n int, nrhs int, mut a []f64, lda int, ipiv []int, mut b []f64, ldb // Note that the routine returns V**T, not V. // // NOTE: matrix 'a' will be modified -pub fn dgesvd(jobu &char, jobvt &char, m int, n int, a []f64, lda int, s []f64, u []f64, ldu int, vt []f64, ldvt int, superb []f64) { - info := C.LAPACKE_dgesvd(.row_major, jobu, jobvt, m, n, &a[0], lda, &s[0], &u[0], - ldu, &vt[0], ldvt, &superb[0]) +pub fn dgesvd(jobu rune, jobvt rune, m int, n int, a []f64, lda int, s []f64, u []f64, ldu int, vt []f64, ldvt int, superb []f64) { + // lapack_int LAPACKE_dgesvd( int matrix_order, char jobu, char jobvt, + // lapack_int m, lapack_int n, double* a, + // lapack_int lda, double* s, double* u, lapack_int ldu, + // double* vt, lapack_int ldvt, double* superb ); + info := C.LAPACKE_dgesvd(.row_major, char(jobu), char(jobvt), m, n, &a[0], lda, &s[0], + &u[0], ldu, &vt[0], ldvt, &superb[0]) if info != 0 { errors.vsl_panic('lapack failed', .efailed) } @@ -189,7 +193,7 @@ 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, &char(job_vlr(calc_vl).str().str), &char(job_vlr(calc_vr).str().str), + info := C.LAPACKE_dgeev(.row_major, char(job_vlr(calc_vl)), char(job_vlr(calc_vr)), n, &a[0], lda, &wr[0], &wi[0], &vvl, ldvl, &vvr, ldvr) if info != 0 { errors.vsl_panic('lapack failed', .efailed) diff --git a/vlas/lapack_macos.c.v b/vlas/lapack_macos.c.v index 2c0cbc7c3..1636cc01b 100644 --- a/vlas/lapack_macos.c.v +++ b/vlas/lapack_macos.c.v @@ -1,7 +1,15 @@ module vlas -fn C.LAPACKE_dlange(norm &char, m int, n int, a &f64, lda int, work &f64) f64 +import vsl.vlas.internal.blas + +// double LAPACKE_dlange( int matrix_order, char norm, lapack_int m, +// lapack_int n, const double* a, lapack_int lda ); + +// double LAPACKE_dlange_work( int matrix_order, char norm, lapack_int m, +// lapack_int n, const double* a, lapack_int lda, double* work ); + +fn C.LAPACKE_dlange_work(matrix_order blas.MemoryLayout, norm char, m int, n int, const_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]) } + return unsafe { C.LAPACKE_dlange_work(.row_major, char(norm), m, n, &a[0], lda, &work[0]) } }