Module matrix

A module for handling matrices.

Copyright © (C) 2018, Fred Youhanaie

Authors: Fred Youhanaie (fyrlang@anydata.co.uk).

Description

A module for handling matrices.

The array module is used internally to store the matrix data as an array of arrays. However, the internal representation may change in future and should not be relied upon.

The matrix indices start at 1, unlike the array module, which starts at zero. This is to be in line with the way matrices are used in maths and engineering applications.

This module has been written as an accompaniment to the mtxmkt module.

Data Types

matrix()

abstract datatype: matrix()

Function Index

default/1Return the default term for the missing values in the matrix.
default_count/1Count the number of element with default value.
foldl_rows/3Fold rows of a matrix, and return a list of terms.
from_list/2Return a matrix with its content replaced with the list of lists.
get/3The value at the given row and column is returned.
get_col_list/2Return the values of a column as a list.
get_row_list/2Returns the contents of a row.
map_matrix/2Apply a function against all elements of a matrix.
new/3Create a new matrix.
set/4Set the value at the given row and column.
set_col_list/3Return a matrix with the given column set to the list.
set_row_list/3Sets the contents of a row from a list of values.
size/1Returns the number of rows and columns of the matrix.
to_list/1Return the contents of the matrix as a list of lists.

Function Details

default/1

default(M::matrix()) -> term()

Return the default term for the missing values in the matrix.

default_count/1

default_count(M::matrix:matrix()) -> integer()

Count the number of element with default value.

foldl_rows/3

foldl_rows(Fun::function(), Acc0::term(), M::matrix:matrix()) -> list()

Fold rows of a matrix, and return a list of terms.

The same fold function will be applied to each row from left to right. The result is a list of values corresponding to the folded rows.

from_list/2

from_list(List::[list()], M::matrix()) -> matrix()

Return a matrix with its content replaced with the list of lists.

The List is in the form of a list of rows. If the outer list is longer than the number of rows, or the internal lists are longer than the number of columns, then the extra elements will be ignored.

for shorter lists, the missing values will take the default values of the matrix M.

An empty list, such as [] or [[],[]], has the same effect as new/3, where the resulting matrix will have the same size and default value as M.

get/3

get(Row::integer(), Col::integer(), M::matrix()) -> term() | outofbounds

The value at the given row and column is returned.

The row and column indices start at 1.

If either or both of row or column indices are outside the matrix range, the atom outofbounds will be returned.

get_col_list/2

get_col_list(Col::integer(), M::matrix()) -> list() | outofbounds

Return the values of a column as a list.

The column number starts at 1.

If the column number is outside the matrix range, the atom outofbounds will be returned.

get_row_list/2

get_row_list(Row::integer(), M::matrix()) -> list() | outofbounds

Returns the contents of a row.

The row index starts at 1.

If the row index is outside the matrix range, the atom outofbounds will be returned.

map_matrix/2

map_matrix(Fun::function(), M::matrix:matrix()) -> matrix:matrix()

Apply a function against all elements of a matrix

new/3

new(Nrows::integer(), Ncols::integer(), Default::term()) -> matrix()

Create a new matrix.

The matrix will have fixed size of Nrows rows and Ncols columns.

set/4

set(Row::integer(), Col::integer(), Value::term(), M::matrix()) -> matrix() | outofbounds

Set the value at the given row and column.

The row and column indices start at 1.

If either or both of row or column indices are out side the matrix range, the atom outofbounds will be returned.

set_col_list/3

set_col_list(Col::integer(), List::list(), M::matrix()) -> matrix() | outofbounds

Return a matrix with the given column set to the list.

The column number starts at 1.

If the column number is outside the matrix range, the atom outofbounds will be returned.

set_row_list/3

set_row_list(Row::integer(), List::list(), M::matrix()) -> matrix() | outofbounds

Sets the contents of a row from a list of values.

If the list is longer than the number of columns, the extra elements in the list will be ignored.

If the list is shorter than the number of columns, the missing elements will take the default value.

size/1

size(M::matrix()) -> {integer(), integer()}

Returns the number of rows and columns of the matrix.

The size is returned as a tuple {Nrows, Ncols}.

to_list/1

to_list(M::matrix()) -> [list()]

Return the contents of the matrix as a list of lists.


Generated by EDoc