Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Hasnep/roc-linear-algebra
🔢 Linear algebra library for small vectors and matrices in Roc
https://github.com/Hasnep/roc-linear-algebra
linear-algebra matrices roc roc-lang
Last synced: 3 months ago
JSON representation
🔢 Linear algebra library for small vectors and matrices in Roc
- Host: GitHub
- URL: https://github.com/Hasnep/roc-linear-algebra
- Owner: Hasnep
- License: upl-1.0
- Created: 2024-06-30T13:50:23.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-02T14:06:46.000Z (4 months ago)
- Last Synced: 2024-07-09T15:42:41.639Z (4 months ago)
- Topics: linear-algebra, matrices, roc, roc-lang
- Language: Roc
- Homepage: https://hasnep.github.io/roc-linear-algebra
- Size: 64.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- roc-awesome - Hasnep/roc-linear-algebra
README
# Roc Linear Algebra
Linear algebra library for small vectors and matrices in Roc.
## Example
Import a matrix and vector type.
```roc
import linalg.Matrix4x4
import linalg.Vector4
```Vectors are just tuples.
```roc
vecA = (1, 2, 3, 4)
Stdout.line! "Vector a is $(Vector4.display vecA)."
vecB = (5, 6, 7, 8)
Stdout.line! "Vector b is $(Vector4.display vecB)."
``````text
Vector a is [1, 2, 3, 4].
Vector b is [5, 6, 7, 8].
```Vectors have various vector-y functions that work how you'd expect.
```roc
vecC = Vector4.add vecA vecB
Stdout.line! "The sum of a and b is $(Vector4.display vecC)."
aDotB = Vector4.dot vecA vecB
Stdout.line! "The dot product of a and b is $(Num.toStr aDotB)."
``````text
The sum of a and b is [6, 8, 10, 12].
The dot product of a and b is 70.
```Matrices are opaque types.
```roc
mat = Matrix4x4.fromDiagonal vecC
```Matrices also have matrix-y functions.
```roc
det = Matrix4x4.determinant mat
Stdout.line! "The determinant of the matrix is $(Num.toStr det)."
``````text
The determinant of the matrix is 5760.
```