Module vector

Types

RowVector[N] = object
  data*: ref array[N, float]
  when true: p
  

A row vector

Example: [1.0, 2.0, 3.0]

  Source Edit
ColVector[N] = object
  data*: ref array[N, float]
  when true: p
  

A column vector

Example:

[1.0|
|2.0|
|3.0]

  Source Edit
Vector[N] = RowVector[N] | ColVector[N]
A generic vector   Source Edit

Procs

proc rowVec[N: static[int]](arr: Array[N]): RowVector[N]
Create a new row vector, takes an array of floats   Source Edit
proc colVec[N: static[int]](arr: Array[N]): ColVector[N]
Create a new row vector, takes an array of floats   Source Edit
proc toRow[N: static[int]](arr: Array[N]): RowVector[N] {.
inline
.}
Create a new row vector, takes an array of floats   Source Edit
proc toCol[N: static[int]](arr: Array[N]): ColVector[N] {.
inline
.}
Create a new row vector, takes an array of floats   Source Edit
proc len[N: static[int]](v: Vector[N]): int
The length of the vector. Read only.   Source Edit
proc `[]`[N: static[int]](v: Vector[N]; i: int): float {.
inline
.}
  Source Edit
proc `[]=`[N: static[int]](v: Vector[N]; i: int; val: float) {.
inline
.}
  Source Edit
proc eq[N: static[int]](v, w: Vector[N]; epsilon: float = Epsilon): bool
Equal up to epsilon   Source Edit
proc `==`[N: static[int]](v, w: Vector[N]; epsilon = Epsilon): bool {.
inline
.}
  Source Edit
proc `===`[N: static[int]](v, w: Vector[N]): bool
Exact equality.   Source Edit
proc `$`[N: static[int]](v: ColVector[N]): string
  Source Edit
proc `$`[N: static[int]](v: RowVector[N]): string
  Source Edit
proc low(v: ColVector): int
  Source Edit
proc high(v: ColVector): int
  Source Edit
proc low(v: RowVector): int
  Source Edit
proc high(v: RowVector): int
  Source Edit
proc t[N: static[int]](v: ColVector[N]): RowVector[N]
Transpose the vector ( col -> row )   Source Edit
proc t[N: static[int]](v: RowVector[N]): ColVector[N]
Transpose the vector ( row -> col )   Source Edit
proc pnorm[N: static[int]](v: Vector[N]; p: Natural = 1): float
P norm: |v| = p-root(sum ( |x_i|^p) )   Source Edit
proc enorm[N: static[int]](v: Vector[N]): float
Euclidean norm: |v| = sqrt(sum ( |x_i|^2) )   Source Edit
proc norm[N: static[int]](v: Vector[N]): float
Infinite norm: |v| = max_i of |x_i|   Source Edit
proc dot[N: static[int]](v, w: Vector[N]): float
Vector dot product. Can use openblas.   Source Edit
proc dot[N: static[int]](v: RowVector[N]; w: ColVector[N]): float
Vector dot product. Can use openblas.   Source Edit
proc `*`[N: static[int]](v, w: Vector[N]): float {.
inline
.}
shorthand for dot   Source Edit
proc `*`[N: static[int]](v: RowVector[N]; w: ColVector[N]): float
shorthand for dot   Source Edit
proc add[N: static[int]](v, w: Vector[N]): Vector[N]
  Source Edit
proc `+`[N: static[int]](v: Vector[N]; w: Vector[N]): auto {.
inline
.}
shorthand to add   Source Edit
proc sub[N: static[int]](v, w: Vector[N]): Vector[N]
Subtract two vectors.   Source Edit
proc `-`[N: static[int]](v: Vector[N]; w: Vector[N]): auto {.
inline
.}
shorthand to sub   Source Edit
proc `*`[N: static[int]](a: float64; v: Vector[N]): Vector[N]
scalar times vector. Can use openblas   Source Edit
proc `.*`[N: static[int]](v, w: Vector[N]): Vector[N]
Elementwise vector product.   Source Edit
proc `/`[N: static[int]](v: Vector[N]; val: float): Vector[N]
Vector divided by val   Source Edit
proc `./`[N: static[int]](v, w: Vector[N]): Vector[N]
Vector elementwise division   Source Edit
proc rowones(N: static[int]): RowVector[N]
Construct a vector of N 1s   Source Edit
proc rowzeros(N: static[int]): RowVector[N]
Construct a vector of N 0s   Source Edit

Iterators

iterator items[N: static[int]](a: Vector[N]): float {.
inline
.}
iterates over each item of a.   Source Edit
iterator mitems[N: static[int]](a: var Vector[N]): var float {.
inline
.}
iterates over each item of a, yielding a mutable value   Source Edit
iterator pairs[N: static[int]](a: Vector[N]): tuple[key: int, val: float] {.
inline
.}
iterates over each item of a. Yields (index, a[index]) pairs.   Source Edit
iterator mpairs[N: static[int]](a: var Vector[N]): tuple[key: int, val: var float] {.
inline
.}
iterates over each item of a. Yields (index, a[index]) pairs. a[index] can be modified.   Source Edit