linalg/vec
dynamic :float vector type (column vector)
lavec
(defstruct lavec [len : int data : (Vec float)])
a column vector of `len` float64 elements over a heap (Vec float).
la-vec-new
(la-vec-new [n : int] :)
create a zero-initialized vector of length n.
la-vec-new-zeroed
(la-vec-new-zeroed [n : int] :)
create a zero-initialized vector of length n.
la-vec-wrap
(la-vec-wrap [d : (Vec float)] :)
take ownership of a (Vec float) as a lavec.
la-vec-of
(la-vec-of [& xs])
build a lavec from a literal list of float elements.
la-vec-len
(la-vec-len [^borrow v : lavec] :)
number of elements.
la-vec-get
(la-vec-get [^borrow v : lavec i : int] :)
element at index i (bounds-checked by the backing Vec).
la-vec-set!
(la-vec-set! [^borrow v : lavec i : int x : float] :)
set element at index i.
la-vec-copy
(la-vec-copy [^borrow v : lavec] :)
deep copy.
la-vec-free
(la-vec-free [v : lavec] :)
free the vector and its backing buffer.
la-vec-add
(la-vec-add [^borrow a : lavec ^borrow b : lavec] :)
arithmetic
la-vec-sub
(la-vec-sub [^borrow a : lavec ^borrow b : lavec] :)
element-wise subtraction.
la-vec-scale
(la-vec-scale [^borrow v : lavec s : float] :)
scalar multiplication.
la-vec-dot
(la-vec-dot [^borrow a : lavec ^borrow b : lavec] :)
Note on float reductions: each reduction threads a `float` accumulator
la-vec-norm
(la-vec-norm [^borrow v : lavec] :)
Euclidean (L2) norm.
la-vec-norm-1
(la-vec-norm-1 [^borrow v : lavec] :)
L1 norm (sum of absolute values).
la-vec-norm-inf
(la-vec-norm-inf [^borrow v : lavec] :)
L-infinity norm (maximum absolute value).
la-vec-normalize
(la-vec-normalize [^borrow v : lavec] :)
unit vector (panics on a zero vector).
la-vec-approx-eq?
(la-vec-approx-eq? [^borrow a : lavec ^borrow b : lavec tol : float] :)
1 if all elements are within tol, else 0.
Internal definitions
__vzeros-- Private: build a zero-filled (Vec float) of length n.