himamo v0.1.0 Himamo.Matrix

Defines a two- or three-dimensional matrix.

Examples

iex> matrix = Himamo.Matrix.new({2, 3})
...> matrix = Himamo.Matrix.put(matrix, {1, 0}, 0.1)
...> Himamo.Matrix.get(matrix, {1, 0})
0.1

Implements the Collectable protocol.

Examples

iex> matrix = [{{0, 1}, 0.1}] |> Enum.into(Himamo.Matrix.new({2, 2}))
...> Himamo.Matrix.get(matrix, {0, 1})
0.1

Summary

Functions

Returns entry at position

Creates a Matrix

Updates entry at position

Types

entry :: term
index :: non_neg_integer
t :: %Himamo.Matrix{map: map, size: tuple}

Functions

get(matrix, position)

Specs

get(t, position) :: entry

Returns entry at position.

position is a tuple of indices.

Raises KeyError when accessing a position that was not previously set.

new(size)

Specs

new(tuple) :: t

Creates a Matrix.

The size argument is a tuple that specifies the dimensions. For example, new({5, 3}) creates a 5×3 two-dimensional matrix and new({7, 5, 4}) creates a 7×5×4 three-dimensional matrix.

put(matrix, position, entry)

Specs

put(t, position, entry) :: t

Updates entry at position.

position is a tuple of indices.

Raises ArgumentError when updating a position that is out of bounds of the matrix.