# Numeric¶

This module provides simple numeric routines in Lua.

halmd.numeric.sum(t)

Compute the sum of the indexed elements of a table.

Parameters: t (table) – input table sum over all indexed elements in t
halmd.numeric.prod(t)

Compute the product of the indexed elements of a table.

Parameters: t (table) – input table product over all indexed elements in t
halmd.numeric.find_comp(t, comp)

Find the last value of a table that satisfies comp(a,b)

Parameters: t (table) – input table comp – callable that takes two elements of t and returns true or false last element in t that satisfied comp(a,b)
halmd.numeric.max(t)

Find the maximum value in a table

Parameters: t (table) – input table maximum value in t
halmd.numeric.min(t)

Find the minimum value in a table

Parameters: t (table) – input table minmum value in t
halmd.numeric.scalar_vector(size, value)

Create vector of given size with scalar value

Parameters: size (number) – number of elements value – value for each element of the vector vector of length with each element set to value
halmd.numeric.scalar_matrix(rows, columns, value)

Create matrix of given size with scalar value

Parameters: rows (number) – number of rows columns (number) – number of columns value – value for each element of the matrix matrix of dimension with each element set to value
halmd.numeric.trans(m)

Calculate transpose of matrix

Parameters: m (matrix) – input matrix transpose of m
halmd.numeric.diag(m)

Return diagonal elements of n×n matrix

Parameters: m (matrix) – input square matrix table of diagonal elements of m
halmd.numeric.offset_to_multi_index(offset, dims)

Convert one-dimensional offset to multi-dimensional index

Assumes contiguous storage of the array data in row-major order.

Parameters: offset (number) – 1-based one-dimensional offset dims (table) – dimensions (shape) of multi-dimensional array 1-based multi-dimensional index of array element at offset
halmd.numeric.multi_index_to_offset(index, dims)

Convert multi-dimensional index to one-dimensional offset

Assumes contiguous storage of the array data in row-major order.

Parameters: index (table) – 1-based multi-dimensional index dims (table) – dimensions (shape) of multi-dimensional array 1-based offset of array element at index