-
Notifications
You must be signed in to change notification settings - Fork 1
DenseMatrix
Johnnoe edited this page Aug 27, 2023
·
2 revisions
A Dense Matrix class that internally represents values as a contiguous array.
When a method fails, it will return null.
Method | Description |
---|---|
Static Methods | |
static DenseMatrix from_packed_array(from, rows, columns) | From is a PackedFloat64Array containing the data in row-major order. Rows and columns specify the dimensions of the matrix to be created. |
static DenseMatrix identity(size) | Creates a square identity matrix of the given size. |
static DenseMatrix zero(size) | Creates a square zero matrix of the given size. |
Data Manipulation | |
void set_dimensions(rows, columns) | Enlarges or shrinks the matrix to the dimensions. This method will truncate or zero pad if there is existing data. |
Vector2i get_dimensions() | Returns a Vector2i(), with x = rows, y = columns of the matrix |
void set_element(row, column, value) | Sets the cell in the matrix to the specified value. |
float get_element(row, column) | Returns the value of the cell. |
DenseMatrix tranposed() | Returns a transposed version of the matrix. |
DenseMatrix clone() | Returns an identical copy of the matrix. |
PackedFloat64Array to_packed_array() | Returns the matrix elements as a packed array, in row-major order. |
SparseMatrix to_sparse(zero_threshold) | Returns a SparseMatrix with equivalent non-zeros. Any value less than or equal to zero_threshold are treated as zeros of the SparseMatrix. |
Algebra Methods | |
DenseMatrix multiply_dense(other) | Multiplies the two dense matrices together, returning the result, with other on the RHS of the multiplication. |
DenseMatrix multiply_sparse(other) | Multiplies the dense matrix with a sparse matrix, returning a dense result. |
VectorN multiply_vector(vector) | Does a vector multiplication, with the vector treated as a column vector on the RHS. |
DenseMatrix add_dense(other) | Adds two DenseMatrix's, and returns the result. |
DenseMatrix subtract_dense(other) | Subtracts two DenseMatrix's, and returns the result. |
DenseMatrix add_sparse(other) | Adds the DenseMatrix to the SparseMatrix other, and returns a DenseMatrix. |
DenseMatrix subtract_sparse(other) | Subtracts the SparseMatrix from the DenseMatrix, returning a DenseMatrix. |
void multiply_scalar_in_place(scalar) | Multiplies all values of the matrix by the scalar. This updates the DenseMatrix in-place. |
void add_sparse_in_place(other) | Add the SparseMatrix (other) to the DenseMatrix, in place. |
void subtract_sparse_in_place(other) | Subtracts the SparseMatrix (other) from the DenseMatrix, in place. |
void add_dense_in_place(other) | Add the DenseMatrix (other) to the DenseMatrix, in place. |
void subtract_dense_in_place(other) | Subtracts the DenseMatrix (other) from the DenseMatrix, in place. |
DenseMatrix solve(B) | If "A" is the matrix object, then this method solves the matrix equation Ax=B, where 'B' is the parameter, and 'x' is the return value. This is solved using Gaussian Elimination. To solve for a vector instead of a matrix, do solve(vector.column_vector()) , to convert the vector to the appropriate column matrix. |
VectorN solve_iterative_cg(B, initial_guess, max_iterations) | This performs an iterative solve using the Conjugate Gradient Method, starting from the initial_guess . This method is guaranteed to converge on Positive-Definite matrices, but may converge otherwise as well. If initial_guess is null, a zero vector is chosen by default. If max_iterations is negative, then it will be ignored. |
DenseMatrix inverse() | Performs an inverse, and returns it. This is equivalent to matrix.solve(DenseMatrix.identity(matrix.get_dimensions().x)) . |
double norm_squared() | Returns the Frobenius norm squared (equal to summing all values squared). |
double norm() | Returns the Frobenius norm (equal to the square root of summing all values squared). |