Skip to content

Commit

Permalink
fix compilation on macos with latest clang 15 and LAPACK from brew
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Jul 26, 2024
1 parent 7fd1d43 commit 702b287
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 1 addition & 2 deletions la/matrix_ops.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions vlas/lapack_common.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions vlas/lapack_macos.c.v
Original file line number Diff line number Diff line change
@@ -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]) }
}

0 comments on commit 702b287

Please sign in to comment.