-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
base: main
Are you sure you want to change the base?
Changes from 40 commits
6f4fe35
d667c95
10eea19
5bd805c
f33a31b
3a0af32
11ed075
c3d1e2e
ea376ac
c7356d7
0832f6d
ae0628b
2a2e7d8
e82bda8
88776da
b84f2ba
ab34e62
14d3f67
02da167
b2f481c
e43bfa5
bfa6907
961475e
f6cb782
569a96b
d8a4fc2
c66401f
d399e1a
1d5e441
9f46519
d376d36
99a3a2b
5f9a1fe
e83de29
b06e436
36ae80e
63adcf6
8afd14a
3af89bf
d9fd254
79d8a8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# The V Basic Linear Algebra System | ||
|
||
This package implements Basic Linear Algebra System (BLAS) routines in V. | ||
|
||
| Backend | Description | Status | Compilation Flags | | ||
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------ | ------------------- | | ||
| BLAS | Pure V implementation | Stable | `NONE` | | ||
| OpenBLAS | OpenBLAS is an optimized BLAS library based on <https://github.com/xianyi/OpenBLAS>. Check the section [OpenBLAS Backend](#openblas-backend) for more information. | Stable | `-d vsl_blas_cblas` | | ||
|
||
Therefore, its routines are a little more _lower level_ than the ones in the package `vsl.la`. | ||
|
||
## OpenBLAS Backend | ||
|
||
We provide a backend for the OpenBLAS library. This backend is probably | ||
the fastest one for all platforms | ||
but it requires the installation of the OpenBLAS library. | ||
|
||
Use the compilation flag `-d vsl_blas_cblas` to use the OpenBLAS backend | ||
instead of the pure V implementation | ||
and make sure that the OpenBLAS library is installed in your system. | ||
|
||
Check the section below for more information about installing the OpenBLAS library. | ||
|
||
<details> | ||
<summary>Install dependencies</summary> | ||
|
||
### Homebrew (macOS) | ||
|
||
```sh | ||
brew install openblas | ||
``` | ||
|
||
### Debian/Ubuntu GNU Linux | ||
|
||
`libopenblas-dev` is not needed when using the pure V backend. | ||
|
||
```sh | ||
sudo apt-get install -y --no-install-recommends \ | ||
gcc \ | ||
gfortran \ | ||
libopenblas-dev | ||
``` | ||
|
||
### Arch Linux/Manjaro GNU Linux | ||
|
||
The best way of installing OpenBlas is using | ||
[lapack-openblas](https://aur.archlinux.org/packages/lapack-openblas/). | ||
|
||
```sh | ||
yay -S lapack-openblas | ||
``` | ||
|
||
or | ||
|
||
```sh | ||
git clone https://aur.archlinux.org/lapack-openblas.git /tmp/lapack-openblas | ||
cd /tmp/lapack-openblas | ||
makepkg -si | ||
``` | ||
|
||
</details> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module blas64 | ||
|
||
// MemoryLayout is used to specify the memory layout of a matrix. | ||
pub enum MemoryLayout { | ||
row_major = 101 | ||
col_major = 102 | ||
} | ||
|
||
// Transpose is used to specify the transposition of a matrix. | ||
pub enum Transpose { | ||
no_trans = 111 | ||
trans = 112 | ||
conj_trans = 113 | ||
conj_no_trans = 114 | ||
} | ||
|
||
// Uplo is used to specify whether the upper or lower triangle of a matrix is | ||
pub enum Uplo { | ||
upper = 121 | ||
lower = 122 | ||
all = 99 | ||
} | ||
|
||
// Diagonal is used to specify whether the diagonal of a matrix is unit or non-unit. | ||
pub enum Diagonal { | ||
non_unit = 131 | ||
unit = 132 | ||
} | ||
|
||
// Side is used to specify whether a matrix is on the left or right side in a matrix-matrix multiplication. | ||
pub enum Side { | ||
left = 141 | ||
right = 142 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module blas | ||
module blas64 | ||
|
||
import vsl.float.float64 | ||
import math | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module blas | ||
module blas64 | ||
|
||
fn test_dgemv_no_trans_1() { | ||
expected := [0.0, 0, 0, 0, 0] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module blas | ||
module blas64 | ||
|
||
import vsl.float.float64 | ||
import math | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module blas | ||
module blas64 | ||
|
||
import vsl.float.float64 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module blas | ||
module blas64 | ||
|
||
import math | ||
import vsl.float.float64 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module blas | ||
module blas64 | ||
|
||
import vsl.float.float64 | ||
import math | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,26 +1,25 @@ | ||||||||||
module vlas | ||||||||||
module blas | ||||||||||
|
||||||||||
import strconv | ||||||||||
import math | ||||||||||
import math.complex | ||||||||||
import vsl.errors | ||||||||||
import vsl.vlas.internal.blas | ||||||||||
import vsl.blas.blas64 | ||||||||||
|
||||||||||
pub fn c_trans(trans bool) blas.Transpose { | ||||||||||
return if trans { .trans } else { .no_trans } | ||||||||||
} | ||||||||||
// MemoryLayout is used to specify the memory layout of a matrix. | ||||||||||
pub type MemoryLayout = blas64.MemoryLayout | ||||||||||
|
||||||||||
pub fn c_uplo(up bool) blas.Uplo { | ||||||||||
return if up { .upper } else { .lower } | ||||||||||
} | ||||||||||
// Transpose is used to specify the transposition of a matrix. | ||||||||||
pub type Transpose = blas64.Transpose | ||||||||||
|
||||||||||
fn l_uplo(up bool) u8 { | ||||||||||
return if up { `U` } else { `L` } | ||||||||||
} | ||||||||||
// Uplo is used to specify whether the upper or lower triangle of a matrix is | ||||||||||
pub type Uplo = blas64.Uplo | ||||||||||
|
||||||||||
fn job_vlr(do_calc bool) rune { | ||||||||||
return if do_calc { `V` } else { `N` } | ||||||||||
} | ||||||||||
// Diagonal is used to specify whether the diagonal of a matrix is unit or non-unit. | ||||||||||
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 | ||||||||||
|
||||||||||
Comment on lines
+21
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding examples for To enhance understanding, consider adding examples or more detailed explanations on how the Would you like me to add examples or detailed usage documentation for this type? Clarify documentation for The comment for - // Side is used to specify whether a matrix is on the left or right side in a matrix-matrix multiplication.
+ // Side specifies the side of the operand matrix in a matrix-matrix multiplication, determining if the matrix is multiplied from the left or the right. Committable suggestion
Suggested change
Tip Codebase Verification Ensure All Utility Functions Have Unit Tests The review comment suggests verifying that all utility functions in
Analysis chainReview of utility functions for matrix operations. The utility functions for converting and printing matrices are well-implemented. However, ensure that all functions are covered by unit tests to verify their correctness, especially with edge cases like zero-sized matrices. Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify unit tests cover all utility functions in `blas/conversions.v`.
# Test: Search for unit tests related to utility functions.
rg --type v $'fn test_'
Length of output: 50 Script: #!/bin/bash
# Description: Verify unit tests cover all utility functions in `blas/conversions.v`.
# Step 1: Find all `.v` files in the repository.
fd -e v -t f > v_files.txt
# Step 2: Search for test functions in the found `.v` files.
while read -r file; do
rg 'fn test_' "$file"
done < v_files.txt
Length of output: 20332 |
||||||||||
// slice_to_col_major converts nested slice into an array representing a col-major matrix | ||||||||||
// | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will revert this as soon as I finish testing