Skip to content

Commit

Permalink
rebase on main, use &char only in C functions, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Oct 22, 2023
1 parent 562bcb5 commit 345ee81
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
18 changes: 4 additions & 14 deletions vlas/conversions.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions vlas/lapack_common.v
Original file line number Diff line number Diff line change
Expand Up @@ -189,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]) }
}
8 changes: 5 additions & 3 deletions vlas/lapack_default.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module vlas

import vsl.vlas.internal.vblas

fn C.LAPACKE_dlange(matrix_layout vblas.MemoryLayout, norm byte, m int, n int, a &f64, lda int, work &f64) f64
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 byte, 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]) }
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])
}
}
6 changes: 3 additions & 3 deletions vlas/lapack_macos.c.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module vlas

fn C.LAPACKE_dlange(norm byte, m int, n int, a &f64, lda int, work &f64) f64
fn C.LAPACKE_dlange(norm &char, m int, n int, a &f64, lda int, work &f64) f64

pub fn dlange(norm byte, m int, n int, a []f64, lda int, work []f64) f64 {
return unsafe { C.LAPACKE_dlange(norm, m, n, &a[0], lda, &work[0]) }
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]) }
}

0 comments on commit 345ee81

Please sign in to comment.