Data and Math

vlinalg

Vectors and matrices as plain lists, with the linear algebra to match.

Released v1.0.0 · 2026-09-28
Import
use "stdlib/linalg.ven"

Vectors and matrices as plain lists: identity and zero matrices, transpose, addition, subtraction, scaling and more.

vlinalg.ven
print matrix_transpose([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
:: [[1.0, 4.0], [2.0, 5.0], [3.0, 6.0]]
Reference (22 functions)

API reference

matrix_zeros(rows, cols)

matrix_zeros(2, 3)

matrix_identity(n)

Builds the n by n identity matrix.

matrix_identity(3)

matrix_rows(m)

Gives back the number of rows in Matrix m.

matrix_rows([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])

matrix_cols(m)

Gives back the number of columns in Matrix m.

matrix_cols([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])

matrix_transpose(m)

Builds the transpose of Matrix m, swapping rows for columns.

matrix_transpose([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])

matrix_same_shape(a, b, who)

Raises unless Matrices a and b have identical row and column counts.

matrix_same_shape([[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]], "test")

matrix_add(a, b)

Adds Matrices a and b elementwise.

matrix_add([[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]])

matrix_subtract(a, b)

Subtracts Matrix b from Matrix a elementwise.

matrix_subtract([[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]])

matrix_scalar_multiply(m, scalar)

Multiplies every cell of Matrix m by scalar.

matrix_scalar_multiply([[1.0, 2.0], [3.0, 4.0]], 2.0)

matrix_flatten_row_major(m)

Row-major flattens a nested-List Matrix into a single flat List.

matrix_flatten_row_major([[1.0, 2.0], [3.0, 4.0]])

matrix_from_flat_row_major(flat, rows, cols)

Rebuilds a nested-List Matrix from a flat row-major List plus its shape.

matrix_from_flat_row_major([1.0, 2.0, 3.0, 4.0], 2, 2)

matrix_multiply(a, b)

Multiplies Matrix a by Matrix b (standard matrix product).

matrix_multiply([[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]])

matrix_trace(m)

Sums the diagonal entries of square Matrix m.

matrix_trace([[1.0, 2.0], [3.0, 4.0]])

matrix_copy(m)

Copies a Matrix, a fresh outer List and fresh row Lists.

matrix_copy([[1.0, 2.0], [3.0, 4.0]])

matrix_find_pivot_row(m, col, from_row)

Finds the row, at or below from_row, with the largest absolute value in column col.

matrix_find_pivot_row([[1.0, 2.0], [5.0, 3.0]], 0, 0)

matrix_swap_rows(m, i, j)

Swaps rows i and j of Matrix m in place.

matrix_swap_rows([[1.0, 2.0], [3.0, 4.0]], 0, 1)

matrix_determinant(m)

Computes the determinant of square Matrix m by Gaussian elimination.

matrix_determinant([[1.0, 2.0], [3.0, 4.0]])

matrix_inverse(m)

Computes the inverse of square Matrix m by Gauss-Jordan elimination.

matrix_inverse([[1.0, 2.0], [3.0, 4.0]])

matrix_solve_linear_system(a, b)

Solves the linear system a x = b for x by Gaussian elimination with back substitution.

matrix_solve_linear_system([[1.0, 2.0], [3.0, 4.0]], [5.0, 11.0])

vector_dot(a, b)

Computes the dot product of Vectors a and b.

vector_dot([1.0, 2.0, 3.0], [4.0, 5.0, 6.0])

vector_cross(a, b)

vector_cross([1.0, 0.0, 0.0], [0.0, 1.0, 0.0])

vector_norm(a)

vector_norm([3.0, 4.0])

Get notified when vlinalg changes

Get notified about

New versions and security advisories.

New and updated packages, once a day.

News on the math model built in Venutian.