Package-level declarations

The overall package for the main Matrix, MutableMatrix, SparseMatrix and MutableSparseMatrix classes as well as pseudo-constructor factory functions declared on the type companions.

For example, to create a Matrix, the following code can be used:

val matrix = Matrix(3, 4) { x, y -> x + y }
TypeExampleDescription
MatrixMatrix(orig)Create a copy of the parameter using the copyOf member function.
Matrix(3, 4, "Y")A matrix that is contains the given "initial" value. The implementation is immutable.
Matrix(3, 4) { x, y -> x * y }A simple array-like matrix that contains the values given by the function. The values are assigned at construction.
Matrix.fromFunction(2,5) { x, y -> x * y }A matrix backed directly by the function. The function is invoked on each read of the matrix.
MutableMatrixMutableMatrix(orig)Create a new mutable matrix that is initialized from the given matrix.
MutableMatrix(3, 4, "X")A simple array-like mutable matrix that contains the given initial value "X".
MutableMatrix(3, 4) { x, y -> x * y }A simple array-like mutable matrix that contains the values given by the function. The values are assigned at construction.
SparseMatrixSparseMatrix(orig)Create a copy of the parameter using the copyOf member function.
SparseMatrix(maxX, maxY, initValue) { x, y -> x + y % 2 == 0}Create a sparse matrix that has the given maximum X and Y values, is initialized with the parameter value, and uses the function to determine whether the cell exists.
SparseMatrix(maxX, maxY, validator) { x, y -> "($x, $y)" }Create a sparse matrix that has the given maximum X and Y values, has the given validator to determine sparseness and uses the given function to initialize the matrix (values set on construction).
SparseMatrix(maxX, maxY) { x, y -> if (x + y %3 == 0) sparse else value("($x, $y)")Create a sparse matrix with given maximum X and Y that is initialized using the given "constructor" function.
SparseMatrix.fromSparseValueMatrix(source)Create a sparse matrix from the given matrix with special SparseValue instances that indicate either a value or sparseness.
MutableSparseMatrixMutableSparseMatrix(orig)Create a mutable matrix initialised with the original sparse matrix
MutableSparseMatrix(maxX, maxY, initValue) { x, y -> x + y % 2 == 0}Create a sparse mutable matrix that has the given maximum X and Y values, is initialized with the parameter value, and uses the function to determine whether the cell exists.
MutableSparseMatrix(maxX, maxY, validator) { x, y -> "($x, $y)" }Create a sparse mutable matrix that has the given maximum X and Y values, has the given validator to determine sparseness and uses the given function to initialize the matrix (values set on construction).
MutableSparseMatrix(maxX, maxY) { x, y -> if (x + y %3 == 0) sparse else value("($x, $y)")Create a sparse mutable matrix with given maximum X and Y that is initialized using the given "constructor" function.
MutableSparseMatrix.fromSparseValueMatrix(source)Create a sparse mutable matrix from the given matrix with special SparseValue instances that indicate either a value or sparseness.

Types

Link copied to clipboard
class ArrayMatrix<T> : AbstractMatrix<T>

An implementation of a read-only matrix that is backed by an array.

Link copied to clipboard
class ArrayMutableMatrix<T> : AbstractMutableMatrix<T> , MutableMatrix<T>

Mutable matrix class backed by an array.

Link copied to clipboard
abstract class ArrayMutableMatrixBase<T> : AbstractMutableSparseMatrix<T>

Mutable matrix implementation based upon an array to store the data. It is the basis for implementing both ArrayMutableMatrix and ArrayMutableSparseMatrix.

Link copied to clipboard

Implementation of a MutableSparseMatrix based upon an array to store the data.

Link copied to clipboard
class ArraySparseMatrix<T> : AbstractSparseMatrix<T>

An implementation of a read-only sparse matrix that is backed by an array.

Link copied to clipboard

Implementation of a MutableSparseMatrix based upon an array to store data and validity. It uses the same array to record sparseness as well as data. It does not support changing validity of cells (at this point).

Link copied to clipboard
interface Matrix<out T> : SparseMatrix<T>

A matrix type (based upon SparseMatrix) but it has values at all coordinates.

Link copied to clipboard

An extension to Matrix that is mutable. This is effectively a 2D array.

Link copied to clipboard

A mutable version of SparseMatrix that adds a setter (set) to allow for changing the values in the matrix.

Link copied to clipboard
interface SparseMatrix<out T> : Iterable<T>

A 2-dimensional storage type/matrix that does not require values in all cells. This is a read-only type. The writable version is MutableSparseMatrix. The minimum coordinate is always

Functions

Link copied to clipboard
inline fun <T> MutableSparseMatrix<T>.fill(setter: (Int, Int) -> T)

Helper function to set values into a MutableSparseMatrix.

Link copied to clipboard
inline fun <T> Matrix<T>.forEach(action: (T) -> Unit)

Perform the action for each value in the matrix. This version uses the non-sparse nature of the matrix.

inline fun <T> SparseMatrix<T>.forEach(action: (T) -> Unit)

Perform the action for each value in the (sparse) matrix.

Link copied to clipboard
inline fun Matrix<*>.forEachIndex(action: (Int, Int) -> Unit)

Perform the action for each index in the matrix. This version uses the non-sparse nature of the matrix.

inline fun SparseMatrix<*>.forEachIndex(action: (Int, Int) -> Unit)

Perform the action for each index in the (sparse) matrix. This skips sparse indices.

Link copied to clipboard
inline fun <T, R> Matrix<T>.map(transform: (T) -> R): Matrix<R>

A map function that creates a new matrix with each cell mapped by transform.

inline fun <T, R> SparseMatrix<T>.map(transform: (T) -> R): SparseMatrix<R>

A map function that creates a new (sparse) matrix with each cell mapped by transform.