Class DenseMatrix32F
- java.lang.Object
-
- org.ejml.data.D1Matrix32F
-
- org.ejml.data.DenseMatrix32F
-
- All Implemented Interfaces:
- java.io.Serializable, Matrix, RealMatrix32F, ReshapeMatrix
public class DenseMatrix32F extends D1Matrix32F
DenseMatrix64F is a dense matrix with elements that are 32-bit floats. A matrix is the fundamental data structure in linear algebra. Unlike a sparse matrix, there is no compression in a dense 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]
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.ejml.data.D1Matrix32F
data, numCols, numRows
-
-
Constructor Summary
Constructors Constructor and Description DenseMatrix32F()Default constructor in which nothing is configured.DenseMatrix32F(DenseMatrix32F orig)Creates a new matrix which is equivalent to the provided matrix.DenseMatrix32F(float[][] data)Creates a matrix with the values and shape defined by the 2D array 'data'.DenseMatrix32F(int length)This declares an array that can store a matrix up to the specified length.DenseMatrix32F(int numRows, int numCols)Creates a new Matrix with the specified shape whose elements initially have the value of zero.DenseMatrix32F(int numRows, int numCols, boolean rowMajor, float... data)Creates a new matrix which has the same value as the matrix encoded in the provided array.DenseMatrix32F(RealMatrix32F mat)Creates a new DenseMatrix64F which contains the same information as the provided Matrix64F.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(int row, int col, float value)Adds 'value' to the specified element in the matrix.
aij = aij + valueDenseMatrix32Fcopy()Creates and returns a matrix which is idential to this one.floatget(int row, int col)Returns the value of the specified matrix element.intgetIndex(int row, int col)Returns the internal array index for the specified row and column.intgetNumElements()Returns the number of elements in this matrix, which is equal to the number of rows times the number of columns.booleanisInBounds(int row, int col)Determins if the specified element is inside the bounds of the Matrix.voidprint()Prints the value of this matrix to the screen.voidprint(java.lang.String format)Prints the value of this matrix to the screen using the same format as {@link java.io.PrintStream#printf).voidreshape(int numRows, int numCols, boolean saveValues)Changes the number of rows and columns in the matrix, allowing its size to grow or shrink.voidset(int numRows, int numCols, boolean rowMajor, float... data)Sets this matrix equal to the matrix encoded in the array.voidset(int row, int col, float value)Assigns the element in the Matrix to the specified value.voidset(Matrix original)Sets this matrix to be identical to the 'original' matrix passed in.java.lang.StringtoString()Converts the array into a string format for display purposes.floatunsafe_get(int row, int col)Same asRealMatrix32F.get(int, int)but does not perform bounds check on input parameters.voidunsafe_set(int row, int col, float value)Same asRealMatrix32F.set(int, int, float)but does not perform bounds check on input parameters.static DenseMatrix32Fwrap(int numRows, int numCols, float[] data)Creates a new DenseMatrix64F around the provided data.voidzero()Sets all elements equal to zero.-
Methods inherited from class org.ejml.data.D1Matrix32F
div, get, getData, getNumCols, getNumRows, iterator, minus, plus, reshape, set, set, setData, setNumCols, setNumRows, times
-
-
-
-
Constructor Detail
-
DenseMatrix32F
public DenseMatrix32F(int numRows, int numCols, boolean rowMajor, float... 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 float[]{1,2,3,4});
DenseMatrix b = new DenseMatrix(2,2,true,1,2,3,4);
Both are equivalent.- Parameters:
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.
-
DenseMatrix32F
public DenseMatrix32F(float[][] 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 ]- Parameters:
data- 2D array representation of the matrix. Not modified.
-
DenseMatrix32F
public DenseMatrix32F(int numRows, int numCols)Creates a new Matrix with the specified shape whose elements initially have the value of zero.- Parameters:
numRows- The number of rows in the matrix.numCols- The number of columns in the matrix.
-
DenseMatrix32F
public DenseMatrix32F(DenseMatrix32F orig)
Creates a new matrix which is equivalent to the provided matrix. Note that the length of the data will be determined by the shape of the matrix.- Parameters:
orig- The matrix which is to be copied. This is not modified or saved.
-
DenseMatrix32F
public DenseMatrix32F(int length)
This declares an array that can store a matrix up to the specified length. This is use full when a matrix's size will be growing and it is desirable to avoid reallocating memory.- Parameters:
length- The size of the matrice's data array.
-
DenseMatrix32F
public DenseMatrix32F()
Default constructor in which nothing is configured. THIS IS ONLY PUBLICLY ACCESSIBLE SO THAT THIS CLASS CAN BE A JAVA BEAN. DON'T USE IT UNLESS YOU REALLY KNOW WHAT YOU'RE DOING!
-
DenseMatrix32F
public DenseMatrix32F(RealMatrix32F mat)
Creates a new DenseMatrix64F which contains the same information as the provided Matrix64F.- Parameters:
mat- Matrix whose values will be copied. Not modified.
-
-
Method Detail
-
wrap
public static DenseMatrix32F wrap(int numRows, int numCols, float[] data)
Creates a new DenseMatrix64F around the provided data. The data must encode a row-major matrix. Any modification to the returned matrix will modify the provided data.- Parameters:
numRows- Number of rows in the matrix.numCols- Number of columns in the matrix.data- Data that is being wrapped. Referenced Saved.- Returns:
- A matrix which references the provided data internally.
-
reshape
public void reshape(int numRows, int numCols, boolean saveValues)Description copied from class:D1Matrix32FChanges 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 ]- Specified by:
reshapein classD1Matrix32F- Parameters:
numRows- The new number of rows in the matrix.numCols- The new number of columns in the matrix.saveValues- If true then the value of each element will be save using a row-major reordering. Typically this should be false.
-
set
public void set(int row, int col, float 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
- Parameters:
row- The row of the element.col- The column of the element.value- The element's new value.
-
unsafe_set
public void unsafe_set(int row, int col, float value)Description copied from interface:RealMatrix32FSame asRealMatrix32F.set(int, int, float)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.- Parameters:
row- Matrix element's row index..col- Matrix element's column index.value- The element's new value.
-
add
public void add(int row, int col, float value)Adds 'value' to the specified element in the matrix.
aij = aij + value
- Parameters:
row- The row of the element.col- The column of the element.value- The value that is added to the element
-
get
public float get(int row, int col)Returns the value of the specified matrix element. Performs a bounds check to make sure the requested element is part of the matrix.- Parameters:
row- The row of the element.col- The column of the element.- Returns:
- The value of the element.
-
unsafe_get
public float unsafe_get(int row, int col)Description copied from interface:RealMatrix32FSame asRealMatrix32F.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.- Parameters:
row- Matrix element's row index..col- Matrix element's column index.- Returns:
- The specified element's value.
-
getIndex
public int getIndex(int row, int col)Description copied from class:D1Matrix32FReturns the internal array index for the specified row and column.- Specified by:
getIndexin classD1Matrix32F- Parameters:
row- Row index.col- Column index.- Returns:
- Internal array index.
-
isInBounds
public boolean isInBounds(int row, int col)Determins if the specified element is inside the bounds of the Matrix.- Parameters:
row- The element's row.col- The elements' column.- Returns:
- True if it is inside the matrices bound, false otherwise.
-
getNumElements
public int getNumElements()
Returns the number of elements in this matrix, which is equal to the number of rows times the number of columns.- Returns:
- The number of elements in the matrix.
-
set
public void set(int numRows, int numCols, boolean rowMajor, float... data)Sets this matrix equal to the matrix encoded in the array.- Parameters:
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.
-
zero
public void zero()
Sets all elements equal to zero.
-
copy
public DenseMatrix32F copy()
Creates and returns a matrix which is idential to this one.- Returns:
- A new identical matrix.
-
set
public void set(Matrix original)
Description copied from interface:MatrixSets this matrix to be identical to the 'original' matrix passed in.
-
print
public void print()
Prints the value of this matrix to the screen. For more options seeUtilEjml
-
print
public void print(java.lang.String format)
Prints the value of this matrix to the screen using the same format as {@link java.io.PrintStream#printf).
- Parameters:
format- The format which each element is printed uses.
-
toString
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, org.ejml.data.RealMatrix64F).- Overrides:
toStringin classjava.lang.Object- Returns:
- String representation of the matrix.
-
-
DMelt 3.0 © DataMelt by jWork.ORG