public class DMatrixRMaj extends DMatrix1Row
DMatrixRMaj is a row matrix with real elements that are 64-bit floats. A matrix is the fundamental data structure in linear algebra. Unlike a sparse matrix, there is no compression in a row matrix and every element is stored in memory. This allows for fast reads and writes to the matrix.
The matrix is stored internally in a row-major 1D array format:
data[ y*numCols + x ] = data[y][x]
For example:
data =
a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9] a[10] a[11] a[12] a[13] a[14] a[15]
Constructor and Description |
---|
DMatrixRMaj()
Default constructor in which nothing is configured.
|
DMatrixRMaj(DMatrix mat)
Creates a new DMatrixRMaj which contains the same information as the provided Matrix64F.
|
DMatrixRMaj(DMatrixRMaj orig)
Creates a new matrix which is equivalent to the provided matrix.
|
DMatrixRMaj(double[][] data)
Creates a matrix with the values and shape defined by the 2D array 'data'.
|
DMatrixRMaj(int length)
This declares an array that can store a matrix up to the specified length.
|
DMatrixRMaj(int numRows,
int numCols)
Creates a new Matrix with the specified shape whose elements initially
have the value of zero.
|
DMatrixRMaj(int numRows,
int numCols,
boolean rowMajor,
double... data)
Creates a new matrix which has the same value as the matrix encoded in the
provided array.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int row,
int col,
double value)
Adds 'value' to the specified element in the matrix.
aij = aij + value |
DMatrixRMaj |
copy()
Creates and returns a matrix which is idential to this one.
|
<T extends Matrix> |
createLike()
Creates a new matrix with the same shape as this matrix
|
double |
get(int row,
int col)
Returns the value of the specified matrix element.
|
int |
getIndex(int row,
int col)
Returns the internal array index for the specified row and column.
|
int |
getNumElements()
Returns the number of elements in this matrix, which is equal to
the number of rows times the number of columns.
|
MatrixType |
getType()
Returns the type of matrix
|
boolean |
isInBounds(int row,
int col)
Determines if the specified element is inside the bounds of the Matrix.
|
void |
print()
Prints the value of this matrix to the screen.
|
void |
print(java.lang.String format)
Prints the value of this matrix to the screen using the same format as
PrintStream.printf(java.lang.String, java.lang.Object...) . |
void |
printJava(java.lang.String format) |
void |
reshape(int numRows,
int numCols,
boolean saveValues)
Changes the number of rows and columns in the matrix, allowing its size to grow or shrink.
|
void |
set(int numRows,
int numCols,
boolean rowMajor,
double... data)
Sets this matrix equal to the matrix encoded in the array.
|
void |
set(int row,
int col,
double value)
Assigns the element in the Matrix to the specified value.
|
void |
set(Matrix original)
Sets this matrix to be identical to the 'original' matrix passed in.
|
java.lang.String |
toString()
Converts the array into a string format for display purposes.
|
double |
unsafe_get(int row,
int col)
Same as
DMatrix.get(int, int) but does not perform bounds check on input parameters. |
void |
unsafe_set(int row,
int col,
double value)
Same as
DMatrix.set(int, int, double) but does not perform bounds check on input parameters. |
static DMatrixRMaj |
wrap(int numRows,
int numCols,
double[] data)
Creates a new DMatrixRMaj around the provided data.
|
void |
zero()
Sets all elements equal to zero.
|
div, get, getData, getNumCols, getNumRows, iterator, minus, plus, reshape, set, set, setData, setNumCols, setNumRows, times
public DMatrixRMaj(int numRows, int numCols, boolean rowMajor, double... data)
Creates a new matrix which has the same value as the matrix encoded in the provided array. The input matrix's format can either be row-major or column-major.
Note that 'data' is a variable argument type, so either 1D arrays or a set of numbers can be
passed in:
DenseMatrix a = new DenseMatrix(2,2,true,new double[]{1,2,3,4});
DenseMatrix b = new DenseMatrix(2,2,true,1,2,3,4);
Both are equivalent.
numRows
- The number of rows.numCols
- The number of columns.rowMajor
- If the array is encoded in a row-major or a column-major format.data
- The formatted 1D array. Not modified.public DMatrixRMaj(double[][] data)
Creates a matrix with the values and shape defined by the 2D array 'data'.
It is assumed that 'data' has a row-major formatting:
data[ row ][ column ]
data
- 2D array representation of the matrix. Not modified.public DMatrixRMaj(int numRows, int numCols)
numRows
- The number of rows in the matrix.numCols
- The number of columns in the matrix.public DMatrixRMaj(DMatrixRMaj orig)
orig
- The matrix which is to be copied. This is not modified or saved.public DMatrixRMaj(int length)
length
- The size of the matrice's data array.public DMatrixRMaj()
public DMatrixRMaj(DMatrix mat)
mat
- Matrix whose values will be copied. Not modified.public static DMatrixRMaj wrap(int numRows, int numCols, double[] data)
numRows
- Number of rows in the matrix.numCols
- Number of columns in the matrix.data
- Data that is being wrapped. Referenced Saved.public void reshape(int numRows, int numCols, boolean saveValues)
DMatrixD1
Changes the number of rows and columns in the matrix, allowing its size to grow or shrink. If the saveValues flag is set to true, then the previous values will be maintained, but reassigned to new elements in a row-major ordering. If saveValues is false values will only be maintained when the requested size is less than or equal to the internal array size. The primary use for this function is to encourage data reuse and avoid unnecessarily declaring and initialization of new memory.
Examples:
[ 1 2 ; 3 4 ] → reshape( 2 , 3 , true ) = [ 1 2 3 ; 4 0 0 ]
[ 1 2 ; 3 4 ] → reshape( 1 , 2 , true ) = [ 1 2 ]
[ 1 2 ; 3 4 ] → reshape( 1 , 2 , false ) = [ 1 2 ]
[ 1 2 ; 3 4 ] → reshape( 2 , 3 , false ) = [ 0 0 0 ; 0 0 0 ]
public void set(int row, int col, double value)
Assigns the element in the Matrix to the specified value. Performs a bounds check to make sure
the requested element is part of the matrix.
aij = value
row
- The row of the element.col
- The column of the element.value
- The element's new value.public void unsafe_set(int row, int col, double value)
DMatrix
DMatrix.set(int, int, double)
but does not perform bounds check on input parameters. This results in about a 25%
speed increase but potentially sacrifices stability and makes it more difficult to track down simple errors.
It is not recommended that this function be used, except in highly optimized code where the bounds are
implicitly being checked.row
- Matrix element's row index..col
- Matrix element's column index.value
- The element's new value.public void add(int row, int col, double value)
Adds 'value' to the specified element in the matrix.
aij = aij + value
row
- The row of the element.col
- The column of the element.value
- The value that is added to the elementpublic double get(int row, int col)
row
- The row of the element.col
- The column of the element.public double unsafe_get(int row, int col)
DMatrix
DMatrix.get(int, int)
but does not perform bounds check on input parameters. This results in about a 25%
speed increase but potentially sacrifices stability and makes it more difficult to track down simple errors.
It is not recommended that this function be used, except in highly optimized code where the bounds are
implicitly being checked.row
- Matrix element's row index..col
- Matrix element's column index.public int getIndex(int row, int col)
DMatrixD1
public boolean isInBounds(int row, int col)
row
- The element's row.col
- The element's column.public int getNumElements()
public void set(int numRows, int numCols, boolean rowMajor, double... data)
numRows
- The number of rows.numCols
- The number of columns.rowMajor
- If the array is encoded in a row-major or a column-major format.data
- The formatted 1D array. Not modified.public void zero()
public DMatrixRMaj copy()
public void set(Matrix original)
Matrix
public void print()
UtilEjml
public void printJava(java.lang.String format)
public void print(java.lang.String format)
Prints the value of this matrix to the screen using the same format as PrintStream.printf(java.lang.String, java.lang.Object...)
.
format
- The format which each element is printed uses.public java.lang.String toString()
Converts the array into a string format for display purposes.
The conversion is done using MatrixIO.print(java.io.PrintStream, DMatrix)
.
toString
in class java.lang.Object
public <T extends Matrix> T createLike()
Matrix
public MatrixType getType()
Matrix