ExMatrix
ExMatrix is an Elixir library implementing a parallel matrix multiplication algorithm and other utilitiy functions for working with matrices.
Multiplying matrices
iex> x = [[2,3], [3,5]]
[[2,3], [3,5]]
iex> y = [[1,2], [5,-1]]
[[1,2], [5,-1]]
iex> ExMatrix.pmultiply(x, y)
[[17, 1], [28, 1]]
iex> ExMatrix.multiply(x, y)
[[17, 1], [28, 1]]
Summary↑
add(matrix_a, matrix_b) | Adds two matrices of the same dimensions, returning a new matrix of the same dimensions. If two non-matching matrices are provided an ArgumentError will be raised |
add_rows(row_a, row_b) | Adds two rows together to return a new row |
dot_product(row_a, row_b) | Calculates the dot-product for two rows of numbers |
multiply(matrix_a, matrix_b) | Perform a sequential multiplication of the two matrices, |
new_matrix(rows, cols) | Creates a new matrix that has |
pmultiply(matrix_a, matrix_b) | Perform a parallel multiplication of the two matrices, |
random_cells(rows, cols, max) | |
size(matrix) | Returns the size of the matrix as {rows, columns} |
subtract(matrix_a, matrix_b) | Subtracts two matrices of the same dimensions, returning a new matrix of the same dimensions. If two non-matching matrices are provided an ArgumentError will be raised |
subtract_rows(row_a, row_b) | Subtracts two rows to return a new row |
transpose(cells) | Transposes the provided |
Functions
Specs:
- add([[number]], [[number]]) :: [[number]]
Adds two matrices of the same dimensions, returning a new matrix of the same dimensions. If two non-matching matrices are provided an ArgumentError will be raised.
Specs:
- add_rows([number], [number]) :: [number]
Adds two rows together to return a new row
Specs:
- dot_product([number], [number]) :: number
Calculates the dot-product for two rows of numbers
Specs:
- multiply([[number]], [[number]]) :: [[number]]
Perform a sequential multiplication of the two matrices, matrix_a
and matrix_b
.
Specs:
- new_matrix(number, number) :: [[number]]
Creates a new matrix that has rows
number of rows and cols
columns. All cells are initially set to zero.
Example
iex> ExMatrix.new_matrix(4, 5)
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
Specs:
- pmultiply([[number]], [[number]]) :: [[number]]
Perform a parallel multiplication of the two matrices, matrix_a
and matrix_b
.
Specs:
- random_cells(integer, integer, integer) :: [[number]]
Specs:
- size([[number]]) :: {number, number}
Returns the size of the matrix as {rows, columns}.
Specs:
- subtract([[number]], [[number]]) :: [[number]]
Subtracts two matrices of the same dimensions, returning a new matrix of the same dimensions. If two non-matching matrices are provided an ArgumentError will be raised.
Specs:
- subtract_rows([number], [number]) :: [number]
Subtracts two rows to return a new row
Specs:
- transpose([[number]]) :: [[number]]
Transposes the provided matrix
so that a 3, 2 matrix would become a 2, 3 matrix. Once transposed the first row in the transposed matrix is actually the first column in the pre-transposed matrix.
Example
iex> ExMatrix.transpose([[2, 4],[5, 6]])
[[2, 5], [4, 6]]