tur/vec
src/linalg/vec.tur
dynamic :float vector type (column vector)
defstruct
vec
(defstruct vec [])
a 1-column mat; alias for column vectors.
defn
vec--alloc-data
(vec--alloc-data [n] :int)
Private helper: allocate float array
defn
vec--free-data
(vec--free-data [data] :void)
Private helper: free float array
defn
vec-new
(vec-new [n] :int)
create an uninitialized vector of length n
defn
vec-new-zeroed
(vec-new-zeroed [n] :int)
create a zero-initialized vector of length n
defn
vec-from-list
(vec-from-list [xs] :int)
create a vector from a cons list of floats
defn
vec-copy
(vec-copy [v] :int)
create a deep copy of a vector
defn
vec-free
(vec-free [v] :void)
free a vector
defn
vec-get
(vec-get [v i] :float)
get element at index i with bounds checking
defn
vec-set!
(vec-set! [v i x] :void)
set element at index i with bounds checking
defn
vec-len
(vec-len [v] :int)
get vector length
defn
vec-add
(vec-add [a b] :int)
Arithmetic operations
defn
vec-sub
(vec-sub [a b] :int)
element-wise vector subtraction
defn
vec-scale
(vec-scale [v s] :int)
scalar multiplication
defn
vec-dot
(vec-dot [a b] :float)
dot product
defn
vec-outer
(vec-outer [a b] :int)
outer product (returns a matrix)
defn
vec-norm
(vec-norm [v] :float)
Euclidean norm (L2 norm)
defn
vec-norm-1
(vec-norm-1 [v] :float)
L1 norm (sum of absolute values)
defn
vec-norm-inf
(vec-norm-inf [v] :float)
L-infinity norm (maximum absolute value)
defn
vec-normalize
(vec-normalize [v] :int)
normalize vector to unit length
defn
vec-approx-eq?
(vec-approx-eq? [a b tol] :int)
check if two vectors are approximately equal