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
Returns: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
Returns: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
Returns:

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
Returns:maximum value in t
halmd.numeric.min(t)

Find the minimum value in a table

Parameters:t (table) – input table
Returns: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
Returns:

vector of length \text{size} 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
Returns:

matrix of dimension \text{rows} \times \text{columns} with each element set to value

halmd.numeric.trans(m)

Calculate transpose of matrix

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

Return diagonal elements of n×n matrix

Parameters:m (matrix) – input square matrix
Returns: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
Returns:

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
Returns:

1-based offset of array element at index