Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor linear algebra module and remove unused code #195

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6f4fe35
Refactor linear algebra module and remove unused code
ulises-jeremias Jan 7, 2024
d667c95
Update installation instructions for LAPACK-OpenBLAS
ulises-jeremias Jan 7, 2024
10eea19
Update imports and function signatures in lapack and blas modules
ulises-jeremias Jan 7, 2024
5bd805c
Update import statements in lapack module
ulises-jeremias Jan 7, 2024
f33a31b
Update LAPACKE backend status in README.md
ulises-jeremias Jan 7, 2024
3a0af32
Refactor LAPACKE backend for improved performance
ulises-jeremias Jan 7, 2024
11ed075
Refactor README files for BLAS and LAPACK backends
ulises-jeremias Jan 7, 2024
c3d1e2e
Refactor conversion functions to be public
ulises-jeremias Jan 7, 2024
ea376ac
Merge branch 'main' of github.com:vlang/vsl into feature/new-lapack
ulises-jeremias Feb 4, 2024
c7356d7
Merge branch 'main' of github.com:vlang/vsl into feature/new-lapack
ulises-jeremias Feb 25, 2024
0832f6d
Refactor dgetrf function to use blocked algorithm
ulises-jeremias Mar 24, 2024
ae0628b
Merge branch 'main' of github.com:vlang/vsl into feature/new-lapack
ulises-jeremias Mar 24, 2024
2a2e7d8
Merge branch 'main' of github.com:vlang/vsl into feature/new-lapack
ulises-jeremias Apr 1, 2024
e82bda8
Merge branch 'main' of github.com:vlang/vsl into feature/new-lapack
ulises-jeremias Apr 27, 2024
88776da
Refactor dgetrf function to use blocked algorithm
ulises-jeremias Apr 28, 2024
b84f2ba
Refactor dgetrf function to use blocked algorithm and fix variable na…
ulises-jeremias Apr 28, 2024
ab34e62
Refactor LAPACK functions to use row-major memory layout
ulises-jeremias Apr 28, 2024
14d3f67
Refactor LAPACK module to use lapack64 module
ulises-jeremias Apr 28, 2024
02da167
Refactor dgetrs function to use f64 instead of float64 for array types
ulises-jeremias Apr 28, 2024
b2f481c
Merge branch 'main' of github.com:vlang/vsl into feature/new-lapack
ulises-jeremias Jun 17, 2024
e43bfa5
refactor: Update create_image_2d function to use local variable for f…
ulises-jeremias Jun 18, 2024
bfa6907
refactor: Replace constant lookup with a list of constants in ilaenv.v
ulises-jeremias Jun 18, 2024
961475e
refactor: Update create_image_2d function to use local variable for f…
ulises-jeremias Jun 18, 2024
f6cb782
refactor: Update execute tests step in ci.yml to use Pure C Backend w…
ulises-jeremias Jun 18, 2024
569a96b
refactor: Comment out test execution step in ci.yml
ulises-jeremias Jun 18, 2024
d8a4fc2
refactor: Update create_image_2d function to use local variable for f…
ulises-jeremias Jun 18, 2024
c66401f
refactor: Update gemv_test.v to use named arguments in dgemvcomp calls
ulises-jeremias Jun 18, 2024
d399e1a
refactor: Update gemv_test.v to use named arguments in dgemvcomp calls
ulises-jeremias Jun 18, 2024
1d5e441
refactor: Update gemv_test.v to use named arguments in dgemvcomp calls
ulises-jeremias Jun 18, 2024
9f46519
refactor: Update conversions.v, dgetf2.v, dsyev.v, and lapack_notd_vs…
ulises-jeremias Jun 22, 2024
d376d36
refactor: Update dlansy.v to use named constants for error messages
ulises-jeremias Jun 22, 2024
99a3a2b
refactor: Update dpotrf function in lapack_notd_vsl_lapack_lapacke.v …
ulises-jeremias Jun 22, 2024
5f9a1fe
refactor: Update conversions.v, dgetf2.v, dsyev.v, and lapack_notd_vs…
ulises-jeremias Jun 23, 2024
e83de29
refactor: Update LAPACK functions in lapack_notd_vsl_lapack_lapacke.v…
ulises-jeremias Jun 23, 2024
b06e436
refactor: Update ci.yml to execute tests using Pure V Backend
ulises-jeremias Jun 23, 2024
36ae80e
refactor: Update ci.yml to execute tests using Pure V Backend with CB…
ulises-jeremias Jun 23, 2024
63adcf6
refactor: Update ci.yml to execute tests using Pure V Backend with CB…
ulises-jeremias Jun 23, 2024
8afd14a
refactor: Update dpotrf function to use named constant for uplo param…
ulises-jeremias Jun 23, 2024
3af89bf
refactor: Update BLAS and LAPACK functions to use named constants and…
ulises-jeremias Jun 23, 2024
d9fd254
Merge branch 'main' of github.com:vlang/vsl into feature/new-lapack
ulises-jeremias Aug 3, 2024
79d8a8d
Merge branch 'main' of github.com:vlang/vsl into feature/new-lapack
ulises-jeremias Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: Update conversions.v, dgetf2.v, dsyev.v, and lapack_notd_vs…
…l_lapack_lapacke.v

- Add functions uplo_from_bool and uplo_to_bool to conversions.v
- Remove unused dlamch_s function from dgetf2.v
- Update dsyev.v to include additional error handling and scaling of matrix
- Update dpotrf function in lapack_notd_vsl_lapack_lapacke.v to use uplo_from_bool for uplo parameter
  • Loading branch information
ulises-jeremias committed Jun 22, 2024
commit 9f46519d6e0031e248977d5bd3bae10ad8b62285
10 changes: 10 additions & 0 deletions blas/conversions.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ pub type Diagonal = blas64.Diagonal
// Side is used to specify whether a matrix is on the left or right side in a matrix-matrix multiplication.
pub type Side = blas64.Side

// uplo_from_bool converts a boolean to Uplo.
pub fn uplo_from_bool(uplo bool) Uplo {
return if uplo { .upper } else { .lower }
}

// uplo_to_bool converts Uplo to a boolean.
pub fn uplo_to_bool(uplo Uplo) bool {
return uplo == .upper
}

// slice_to_col_major converts nested slice into an array representing a col-major matrix
//
// _**NOTE**: make sure to have at least 1x1 item_
Expand Down
8 changes: 1 addition & 7 deletions lapack/lapack64/dgetf2.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn dgetf2(m int, n int, mut a []f64, lda int, mut ipiv []int) {
panic(bad_len_ipiv)
}

sfmin := dlamch_s()
sfmin := dlamch_s

for j := 0; j < mn; j++ {
// Find a pivot and test for singularity.
Expand Down Expand Up @@ -58,9 +58,3 @@ pub fn dgetf2(m int, n int, mut a []f64, lda int, mut ipiv []int) {
}
}
}

fn dlamch_s() f64 {
// Returns the safe minimum value (sfmin).
// This value is used as a threshold for detecting small values in the matrix.
return math.ldexp(1.0, -1022) // Smallest positive normal number.
}
122 changes: 122 additions & 0 deletions lapack/lapack64/dlansy.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
module lapack64

import math
import vsl.blas

// dlansy returns the value of the specified norm of an n×n symmetric matrix.
// If norm == MatrixNorm.max_column_sum or norm == MatrixNorm.max_row_sum, work must have length
// at least n, otherwise work is unused.
pub fn dlansy(norm MatrixNorm, uplo blas.Uplo, n int, a []f64, lda int, mut work []f64) f64 {
if norm != .max_row_sum && norm != .max_column_sum && norm != .frobenius && norm != .max_abs {
panic(lapack64.bad_norm)
}
if uplo != .upper && uplo != .lower {
panic(lapack64.bad_uplo)
}
if n < 0 {
panic('lapack: n < 0')
}
if lda < math.max(1, n) {
panic(lapack64.bad_ld_a)
}

// Quick return if possible.
if n == 0 {
return 0.0
}

if a.len < (n-1) * lda + n {
panic(lapack64.short_a)
}
if (norm == .max_column_sum || norm == .max_row_sum) && work.len < n {
panic(lapack64.short_work)
}

match norm {
.max_abs {
if uplo == .upper {
mut max := 0.0
for i in 0 .. n {
for j in i .. n {
v := math.abs(a[i * lda + j])
if math.is_nan(v) {
return math.nan()
}
if v > max {
max = v
}
}
}
return max
}
mut max := 0.0
for i in 0 .. n {
for j in 0 .. i + 1 {
v := math.abs(a[i * lda + j])
if math.is_nan(v) {
return math.nan()
}
if v > max {
max = v
}
}
}
return max
}
.max_row_sum, .max_column_sum {
// A symmetric matrix has the same 1-norm and ∞-norm.
for i in 0 .. n {
work[i] = 0.0
}
if uplo == .upper {
for i in 0 .. n {
work[i] += math.abs(a[i * lda + i])
for j in i + 1 .. n {
v := math.abs(a[i * lda + j])
work[i] += v
work[j] += v
}
}
} else {
for i in 0 .. n {
for j in 0 .. i {
v := math.abs(a[i * lda + j])
work[i] += v
work[j] += v
}
work[i] += math.abs(a[i * lda + i])
}
}
mut max := 0.0
for i in 0 .. n {
v := work[i]
if math.is_nan(v) {
return math.nan()
}
if v > max {
max = v
}
}
return max
}
else {
// blas.frobenius:
mut scale := 0.0
mut sum := 1.0
// Sum off-diagonals.
if uplo == .upper {
for i in 0 .. n - 1 {
scale, sum = dlassq(n - i - 1, a[i * lda + i + 1..], 1, scale, sum)
}
} else {
for i in 1 .. n {
scale, sum = dlassq(i, a[i * lda..], 1, scale, sum)
}
}
sum *= 2.0
// Sum diagonal.
scale, sum = dlassq(n, a, lda + 1, scale, sum)
return scale * math.sqrt(sum)
}
}
}
120 changes: 120 additions & 0 deletions lapack/lapack64/dlassq.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
module lapack64

import math

// dlassq updates a sum of squares represented in scaled form. It returns
// the values scl and smsq such that
//
// scl^2*smsq = X[0]^2 + ... + X[n-1]^2 + scale^2*sumsq
//
// The value of sumsq is assumed to be non-negative.
pub fn dlassq(n int, x []f64, incx int, scale f64, sumsq f64) (f64, f64) {
if n < 0 {
panic('lapack: n < 0')
}
if incx <= 0 {
panic('lapack: increment not one or negative one')
}
if x.len < 1 + (n - 1) * incx {
panic('lapack: insufficient length of x')
}

if math.is_nan(scale) || math.is_nan(sumsq) {
return scale, sumsq
}

mut scl := scale
mut smsq := sumsq

if smsq == 0.0 {
scl = 1.0
}
if scl == 0.0 {
scl = 1.0
smsq = 0.0
}

if n == 0 {
return scl, smsq
}

// Compute the sum of squares in 3 accumulators:
// - abig: sum of squares scaled down to avoid overflow
// - asml: sum of squares scaled up to avoid underflow
// - amed: sum of squares that do not require scaling
// The thresholds and multipliers are:
// - values bigger than dtbig are scaled down by dsbig
// - values smaller than dtsml are scaled up by dssml
mut is_big := false
mut asml, mut amed, mut abig := 0.0, 0.0, 0.0
mut ix := 0
for _ in 0 .. n {
mut ax := math.abs(x[ix])
if ax > dtbig {
ax *= dsbig
abig += ax * ax
is_big = true
} else if ax < dtsml {
if !is_big {
ax *= dssml
asml += ax * ax
}
} else {
amed += ax * ax
}
ix += incx
}
// Put the existing sum of squares into one of the accumulators.
if smsq > 0.0 {
ax := scl * math.sqrt(smsq)
if ax > dtbig {
if scl > 1.0 {
scl *= dsbig
abig += scl * scl * smsq
} else {
// sumsq > dtbig^2 => (dsbig * (dsbig * sumsq)) is representable.
abig += scl * scl * dsbig * dsbig * smsq
}
} else if ax < dtsml {
if !is_big {
if scl < 1.0 {
scl *= dssml
asml += scl * scl * smsq
} else {
// sumsq < dtsml^2 => (dssml * (dssml * sumsq)) is representable.
asml += scl * scl * dssml * dssml * smsq
}
}
} else {
amed += scl * scl * smsq
}
}
// Combine abig and amed or amed and asml if more than one accumulator was used.
if abig > 0.0 {
// Combine abig and amed:
if amed > 0.0 || math.is_nan(amed) {
abig += amed * dsbig * dsbig
}
scl = 1.0 / dsbig
smsq = abig
} else if asml > 0.0 {
// Combine amed and asml:
if amed > 0.0 || math.is_nan(amed) {
amed = math.sqrt(amed)
asml = math.sqrt(asml) / dssml
mut ymin, mut ymax := asml, amed
if asml > amed {
ymin, ymax = amed, asml
}
scl = 1.0
smsq = ymax * ymax * (1.0 + (ymin / ymax) * (ymin / ymax))
} else {
scl = 1.0 / dssml
smsq = asml
}
} else {
scl = 1.0
smsq = amed
}
return scl, smsq
}
Loading
Loading