public interface Matrix
| Modifier and Type | Interface and Description |
|---|---|
static class |
Matrix.Layout
Specifies the layout of the two-dimensional array representation of a matrix.
|
| Modifier and Type | Method and Description |
|---|---|
static MatrixBuilder |
builder(int m,
int n)
Create a new builder for an m by n matrix with all elements initially set to zero.
|
static Matrix |
create(double[]... matrixData)
Create a new matrix from the given two-dimensional array of data, assuming that the
data is laid out by row.
|
static Matrix |
create(int nrow,
int ncol,
double... data)
Create a new matrix with the supplied data and dimensions.
|
static Matrix |
create(Matrix.Layout layout,
double[]... matrixData)
Create a new matrix from the given two-dimensional array of data.
|
double[] |
data()
Obtain the array of data underlying this matrix in row-major order.
|
double[][] |
data2D()
Obtain the data in this matrix as a two-dimensional array.
|
double[][] |
data2D(Matrix.Layout layout)
Obtain the data in this matrix as a two-dimensional array.
|
double[] |
diagonal()
Retrieve the elements on the diagonal of this matrix.
|
static Matrix |
fill(int nrow,
int ncol,
double value)
Create a new matrix with the given dimensions filled with the supplied value.
|
double |
get(int i,
int j)
Get the element at row i, column j.
|
Vector |
getColumn(int j)
Get the jth column of the matrix.
|
Vector |
getRow(int i)
Get the ith row of the matrix.
|
static Matrix |
identity(int n)
Create a new identity matrix with the given dimension.
|
static MatrixBuilder |
identityBuilder(int n)
Create a new builder for a square matrix of size n with ones on the diagonal.
|
boolean |
isSquare()
Returns true if the matrix is square and false otherwise.
|
Matrix |
minus(Matrix other)
Subtract the given matrix from this matrix and return the resulting difference.
|
int |
ncol()
Retrieve the number of columns of this matrix.
|
int |
nrow()
Retrieve the number of rows of this matrix.
|
Matrix |
plus(Matrix other)
Add this matrix to the given matrix and return the resulting sum.
|
Matrix |
pushColumn(Vector newData)
Push the provided vector to the front of this matrix, shifting all other vectors to the right.
|
Matrix |
pushRow(Vector newData)
Push the provided vector to the top of this matrix, shifting all other vectors down.
|
Matrix |
scaledBy(double c)
Scale this matrix by the given value and return the scaled matrix.
|
Matrix |
times(Matrix other)
Multiply this matrix by the given matrix and return the resulting product.
|
Vector |
times(Vector vector)
Multiply this matrix by the given vector and return the resulting transformation.
|
Matrix |
transpose()
Transpose this matrix and return the resulting transposition.
|
static Matrix create(int nrow, int ncol, double... data)
nrow - the number of rows for the matrix.ncol - the number of columns for the matrix.data - the data in row-major order.IllegalArgumentException - if the length of the data array does not equal the given number of rows
multiplied by the given number of columns.static Matrix fill(int nrow, int ncol, double value)
nrow - the number of rows for the matrix.ncol - the number of columns for the matrix.value - the data point to fill the matrix with.static Matrix create(double[]... matrixData)
Matrix.Layout.BY_COLUMN as the second argument to this method.matrixData - the two-dimensional array of data constituting the matrix.static Matrix create(Matrix.Layout layout, double[]... matrixData)
layout - the layout of the elements in the matrix data.matrixData - the two-dimensional array of data constituting the matrix.static Matrix identity(int n)
n - the dimension of the identity matrix.double get(int i,
int j)
i - the element's row location.j - the element's column location.int nrow()
int ncol()
Matrix plus(Matrix other)
other - the matrix to add to this one.IllegalArgumentException - if the dimensions of this matrix do not
match the dimensions of the given matrix.Matrix times(Matrix other)
other - the matrix to multiply by.IllegalArgumentException - if the number of columns of this matrix does not
equal the number of rows of the given matrix.Vector times(Vector vector)
vector - the vector to multiply.IllegalArgumentException - if the number of columns of this matrix does not
equal the size of the given vector.Matrix scaledBy(double c)
c - the value to scale this matrix by.Matrix minus(Matrix other)
other - the matrix to subtract from this one.IllegalArgumentException - if the dimensions of this matrix do not
match the dimensions of the given matrix.boolean isSquare()
Matrix transpose()
Vector getRow(int i)
i - the row index, where indexing begins at 0.Vector getColumn(int j)
j - the column index, where indexing begins at 0.Matrix pushRow(Vector newData)
newData - the new vector of data.IllegalArgumentException - if size of the given vector does not equal the number of columns of this matrix.Matrix pushColumn(Vector newData)
newData - the new vector of data.IllegalArgumentException - if size of the given vector does not equal the number of rows of this matrix.double[] diagonal()
double[] data()
double[][] data2D(Matrix.Layout layout)
layout - the layout of the elements in the matrix data.double[][] data2D()
static MatrixBuilder identityBuilder(int n)
n - the dimension of the matrix.static MatrixBuilder builder(int m, int n)
m - the number of columns of the matrix.n - the the number of columns of the matrix.