A simple linear algebra library using flat-arrays
Create a matrix with a given size, filled with a default value.
repeat 2 3 0 ~= [ [ 0, 0, 0 ], [ 0, 0, 0 ] ]Createsa matrix with a given size, with the elements at index (i, j) initialized to the result of f (i, j).
initialize 3
3
(\( i, j ) ->
if i == j then
1
else
0
)
== identity 3Create a matrix from a list given the desired size.
If the list has a length inferior to n * m, returns Nothing.
fromList 2 2 [ 1, 1, 1, 1, 1 ] == Just <| repeat 2 2 1
fromList 3 3 [ 0, 1, 2 ] == NothingCreate a matrix from a list of lists.
If any inner list is shorter than the first, returns Nothing.
Otherwise, the length of the first list determines the width of the matrix.
fromLists [] == Just empty
fromLists [ [] ] == Just empty
fromLists [ [ 1, 2, 3 ], [ 1, 2 ] ] == Nothing
fromLists [ [ 1, 0 ], [ 0, 1 ] ] == Just <| identity 2Return Just the element at the index or Nothing if the index is out of bounds.
Apply a function between pairwise elements of two matrices.
If the matrices are of differents sizes, returns Nothing.
Perform the standard matrix multiplication.
If the dimensions of the matrices are incompatible, returns Nothing.
Convert the matrix to a flat list.
toList (identity 3) == [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ]Convert the matrix to a list of lists.
toLists (identity 3) = [ [1,0,0], [0,1,0], [0,0,1] ]
Representation of a matrix. You can create matrices of any type but arithmetic operations in Matrix.Operations requires the matrices to have numeric types.