Matricies
Library for performing operations on matrices.
- namespace Matricies
class Matrix[link]
Represents an n by m matrix of floats.
new Matrix(rows, cols)[link]
Creates a new matrix
Arguments
| Name | Type | Description |
|---|---|---|
| rows | integer | Number of rows |
| cols | integer | Number of columns |
function addMatrix(other, output)[link]
Adds another matrix to this matrix and writes it to the optional output matrix
Arguments
| Name | Type | Optional | Description |
|---|---|---|---|
| other | Matrix | The matrix to add to this matrix. |
|
| output | Matrix | Optional | The matrix to write the result to. If this is not provided, the new values will be written to the original Matrix. |
Return Value
| Type | Description |
|---|---|
| Matrix | Returns a reference to the original matrix so that chaining can be used. |
function copyFrom(other)[link]
Copies the values of one matrix into another.
Arguments
| Name | Type | Description |
|---|---|---|
| other | Matrix | The matrix to copy values from. Must be the same size. |
Return Value
| Type | Description |
|---|---|
| Matrix | Returns a reference to the original matrix so that chaining can be used. |
function getValue(row, col)[link]
Gets the value at the given column and row
Arguments
| Name | Type | Description |
|---|---|---|
| row | integer | row |
| col | integer | column |
Return Value
| Type | Description |
|---|---|
| float | Float located at that coordinate |
function multiplyByMatrix(other, output)[link]
Multiplies another matrix to this matrix and writes it to the optional output matrix. Dimensions must be correct.
Arguments
| Name | Type | Optional | Description |
|---|---|---|---|
| other | Matrix | The matrix to multiply this matrix by. |
|
| output | Matrix | Optional | The matrix to write the result to. If this is not provided, the new values will be written to the original Matrix ONLY if the matrix is square. Otherwise, an error will be thrown. |
Return Value
| Type | Description |
|---|---|
| Matrix | Returns a reference to the original matrix so that chaining can be used. |
function multiplyByScalar(value)[link]
Multiplies all values in the matrix by a scalar
Arguments
| Name | Type | Description |
|---|---|---|
| value | float | The scalar value to multiply by. |
Return Value
| Type | Description |
|---|---|
| Matrix | Returns a reference to the original matrix so that chaining can be used. |
function newIdentityMatrix(n)[link]
Generates a new n by n identity matrix.
Arguments
| Name | Type | Description |
|---|---|---|
| n | integer | The size of the matrix (it's a square). |
Return Value
| Type | Description |
|---|---|
| Matrix | A new identity matrix instance |
function setValue(row, col, value)[link]
Sets a value at the given column and row
Arguments
| Name | Type | Description |
|---|---|---|
| row | integer | row |
| col | integer | column |
| value | float | The value to set |
Return Value
| Type | Description |
|---|---|
| Matrix | Returns a reference to the original matrix so that chaining can be used. |
function toVector(output)[link]
Flattens the matrix into a single dimensional list. Values are written starting from the top left corner and go left-to-right first, then row-by-row down.
Arguments
| Name | Type | Description |
|---|---|---|
| output | List of floats | A list to write to. Values are written starting from position 0. If the list is not long enough, values will be added. If the list is longer than the number of elements in the matrix, the remaining values are left alone. |
Return Value
| Type | Description |
|---|---|
| List of floats | Returns the list. |