Class FloatMatrix<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>,M extends FloatMatrix<U,S,V,M>>
java.lang.Object
org.djunits.value.IndexedValue<U,S,M,DM>
org.djunits.value.base.Matrix<U,S,V,FloatVectorData,M,FloatMatrixData>
org.djunits.value.vfloat.matrix.base.FloatMatrix<U,S,V,M>
- Type Parameters:
U- the unitS- the scalar with unit UV- the vector type belonging to the matrix typeM- the generic matrix type
- All Implemented Interfaces:
Serializable,Cloneable,Value<U,M>
- Direct Known Subclasses:
FloatMatrixAbs,FloatMatrixRel
public abstract class FloatMatrix<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>,M extends FloatMatrix<U,S,V,M>>
extends Matrix<U,S,V,FloatVectorData,M,FloatMatrixData>
FloatMatrix utility methods, e.g., for creating FloatMatrixs from different types of data.
Copyright (c) 2015-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.
- Author:
- Alexander Verbraeck, Peter Knoppers
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FloatMatrixDataThe stored data as an object, can be sparse or dense. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Mabs()Return a new Scalar/Vector/Matrix with absolute value(s).final Massign(FloatFunction floatFunction) Execute a function on a cell by cell basis.final Mceil()Return a new Scalar/Vector/Matrix with the nearest integer value(s) above the current value(s).protected final voidcheckColumnIndex(int col) Check that provided column index is valid.protected final voidcheckIndex(int row, int col) Check that provided row and column indices are valid.protected final voidcheckRowIndex(int row) Check that provided row index is valid.protected final voidCheck that the matrix is square.intcols()Retrieve the number of columns of the matrix.final floatCompute the determinant of the matrix, based on the SI values.booleanfinal Mfloor()Return a new Scalar/Vector/Matrix with the nearest integer value(s) below the current value(s).get(int row, int column) Retrieve a value from the matrix.getColumn(int column) Retrieve a column from the matrix as a vector.S[]getColumnScalars(int col) Retrieve a column from the matrix as an array of scalars.float[]getColumnSI(int column) Retrieve a column from the matrix as an array of float.protected final FloatMatrixDatagetData()Retrieve the data object.Retrieve the main diagonal of the matrix as a vector.S[]Retrieve the main diagonal of the matrix as an array of scalars.float[]Retrieve the main diagonal of the matrix as an array of float.floatgetInUnit(int row, int column) Retrieve the value stored at a specified row and column in the original unit.floatRetrieve the value stored at a specified row and column converted into a specified unit.getRow(int row) Retrieve a row from the matrix as a vector.S[]getRowScalars(int row) Retrieve a row from the matrix as an array of scalars.float[]getRowSI(int row) Retrieve a row from the matrix as an array of float.S[][]Return the vector as a 2D-array of scalars.floatgetSI(int row, int column) Retrieve the value stored at a specified row and column in the standard SI unit.final float[][]Create a dense float[][] array filled with the values in the original unit.final float[][]getValuesInUnit(U targetUnit) Create a dense float[][] array filled with the values converted into a specified unit.final float[][]Create a dense float[][] array filled with the values in the standard SI unit.inthashCode()abstract MinstantiateMatrix(FloatMatrixData fmd, U displayUnit) Instantiate a new matrix of the class of this matrix.abstract SinstantiateScalarSI(float valueSI, U displayUnit) Instantiate a new scalar for the class of this matrix.abstract VinstantiateVector(FloatVectorData fvd, U displayUnit) Instantiate a new vector of the class of this matrix.final Mneg()Return a new Scalar/Vector/Matrix with negated value(s).final Mrint()Return a new Scalar/Vector/Matrix with the nearest integer value(s).introws()Retrieve the number of rows of the matrix.voidSet the scalar value at the specified position.protected voidsetData(FloatMatrixData data) Set the data object.voidsetInUnit(int row, int column, float valueInUnit) Set the value, specified in the (current) display unit, at the specified position.voidSet the value, specified in thevalueUnit, at the specified position.voidsetSI(int row, int column, float valueSI) Set the value, specified in the standard SI unit, at the specified position.toDense()Create and return a dense version of this internal storage.toSparse()Create and return a sparse version of this internal storage.toString()Concise description of this value.toString(boolean verbose, boolean withUnit) Somewhat verbose description of this value with optional type and unit information.Somewhat verbose description of this value with the values expressed in the specified unit.Somewhat verbose description of this value with the values expressed in the specified unit.Methods inherited from class org.djunits.value.base.Matrix
getVectorClassMethods inherited from class org.djunits.value.IndexedValue
cardinality, checkCopyOnWrite, clone, getDisplayUnit, getScalarClass, getStorageType, immutable, isCopyOnWrite, isDense, isMutable, isSparse, mutable, setCopyOnWrite, setDisplayUnit, setMutableMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djunits.value.Value
isAbsolute, isRelative
-
Field Details
-
data
The stored data as an object, can be sparse or dense.
-
-
Constructor Details
-
FloatMatrix
Construct a new FloatMatrix.- Parameters:
data- an internal data objectunit- the unit
-
-
Method Details
-
instantiateMatrix
Instantiate a new matrix of the class of this matrix. This can be used instead of the FloatMatrix.instiantiate() methods in case another matrix of this class is known. The method is faster than FloatMatrix.instantiate, and it will also work if the matrix is user-defined.- Parameters:
fmd- the data used to instantiate the matrixdisplayUnit- the display unit of the matrix- Returns:
- a matrix of the correct type
-
instantiateVector
Instantiate a new vector of the class of this matrix. This can be used instead of the FloatVector.instiantiate() methods in case another matrix of this class is known. The method is faster than FloatVector.instantiate, and it will also work if the matrix and/or vector are user-defined.- Parameters:
fvd- the data used to instantiate the vectordisplayUnit- the display unit of the vector- Returns:
- a vector of the correct type
-
instantiateScalarSI
Instantiate a new scalar for the class of this matrix. This can be used instead of the FloatScalar.instiantiate() methods in case a matrix of this class is known. The method is faster than FloatScalar.instantiate, and it will also work if the matrix and/or scalar are user-defined.- Parameters:
valueSI- the SI value of the scalardisplayUnit- the unit in which the value will be displayed- Returns:
- a scalar of the correct type, belonging to the matrix type
-
getData
Description copied from class:IndexedValueRetrieve the data object. Method can only be used within package and by subclasses.- Specified by:
getDatain classIndexedValue<U extends Unit<U>,S extends FloatScalar<U, S>, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Returns:
- the internal data
-
setData
Description copied from class:IndexedValueSet the data object. Method can only be used within package and by subclasses.- Specified by:
setDatain classIndexedValue<U extends Unit<U>,S extends FloatScalar<U, S>, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Parameters:
data- the internal data
-
getSI
Retrieve the value stored at a specified row and column in the standard SI unit.- Parameters:
row- row of the value to retrievecolumn- column of the value to retrieve- Returns:
- value at position row, column in the standard SI unit
- Throws:
IndexOutOfBoundsException- when row or column out of range (row < 0 or row >= rows() or column < 0 or column >= columns())
-
getInUnit
Retrieve the value stored at a specified row and column in the original unit.- Parameters:
row- row of the value to retrievecolumn- column of the value to retrieve- Returns:
- value at position row, column in the original unit
- Throws:
IndexOutOfBoundsException- when row or column out of range (row < 0 or row >= rows() or column < 0 or column >= columns())
-
getInUnit
Retrieve the value stored at a specified row and column converted into a specified unit.- Parameters:
row- row of the value to retrievecolumn- column of the value to retrievetargetUnit- the unit for the result- Returns:
- value at position row, column converted into the specified unit
- Throws:
IndexOutOfBoundsException- when row or column out of range (row < 0 or row >= rows() or column < 0 or column >= columns())
-
setSI
Set the value, specified in the standard SI unit, at the specified position.- Parameters:
row- row of the value to setcolumn- column of the value to setvalueSI- the value, specified in the standard SI unit- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
setInUnit
Set the value, specified in the (current) display unit, at the specified position.- Parameters:
row- row of the value to setcolumn- column of the value to setvalueInUnit- the value, specified in the (current) display unit- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
setInUnit
public void setInUnit(int row, int column, float valueInUnit, U valueUnit) throws IndexOutOfBoundsException Set the value, specified in thevalueUnit, at the specified position.- Parameters:
row- row of the value to setcolumn- column of the value to setvalueInUnit- the value, specified in the (current) display unitvalueUnit- the unit in which thevalueInUnitis expressed- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
set
Set the scalar value at the specified position.- Parameters:
row- row of the value to setcolumn- column of the value to setvalue- the value to set- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
getRowSI
Retrieve a row from the matrix as an array of float.- Parameters:
row- row of the values to retrieve- Returns:
- the row as a float array
- Throws:
IndexOutOfBoundsException- in case row is out of bounds
-
getColumnSI
Retrieve a column from the matrix as an array of float.- Parameters:
column- column of the values to retrieve- Returns:
- the column as a float array
- Throws:
IndexOutOfBoundsException- in case column is out of bounds
-
getDiagonalSI
Retrieve the main diagonal of the matrix as an array of float.- Returns:
- the main diagonal as a float array
- Throws:
ValueRuntimeException- in case the matrix is not square
-
getValuesSI
public final float[][] getValuesSI()Create a dense float[][] array filled with the values in the standard SI unit.- Returns:
- array of values in the standard SI unit
-
getValuesInUnit
public final float[][] getValuesInUnit()Create a dense float[][] array filled with the values in the original unit.- Returns:
- the values in the original unit
-
getValuesInUnit
Create a dense float[][] array filled with the values converted into a specified unit.- Parameters:
targetUnit- the unit into which the values are converted for use- Returns:
- the values converted into the specified unit
-
rows
public int rows()Description copied from class:MatrixRetrieve the number of rows of the matrix.- Specified by:
rowsin classMatrix<U extends Unit<U>,S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Returns:
- the number of rows of the matrix
-
cols
public int cols()Description copied from class:MatrixRetrieve the number of columns of the matrix.- Specified by:
colsin classMatrix<U extends Unit<U>,S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Returns:
- the number of columns of the matrix
-
getScalars
Description copied from class:MatrixReturn the vector as a 2D-array of scalars.- Specified by:
getScalarsin classMatrix<U extends Unit<U>,S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Returns:
- the vector as a 2D-array of scalars
-
get
Description copied from class:MatrixRetrieve a value from the matrix.- Specified by:
getin classMatrix<U extends Unit<U>,S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Parameters:
row- row of the value to retrievecolumn- column of the value to retrieve- Returns:
- the value as a Scalar
- Throws:
IndexOutOfBoundsException- in case row or column is out of bounds
-
getRow
Description copied from class:MatrixRetrieve a row from the matrix as a vector.- Specified by:
getRowin classMatrix<U extends Unit<U>,S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Parameters:
row- row of the values to retrieve- Returns:
- the row as a Vector
- Throws:
IndexOutOfBoundsException- in case row is out of bounds
-
getColumn
Description copied from class:MatrixRetrieve a column from the matrix as a vector.- Specified by:
getColumnin classMatrix<U extends Unit<U>,S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Parameters:
column- column of the values to retrieve- Returns:
- the column as a Vector
- Throws:
IndexOutOfBoundsException- in case column is out of bounds
-
getDiagonal
Description copied from class:MatrixRetrieve the main diagonal of the matrix as a vector.- Specified by:
getDiagonalin classMatrix<U extends Unit<U>,S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Returns:
- the main diagonal as a Vector
- Throws:
ValueRuntimeException- in case the matrix is not square
-
getRowScalars
Description copied from class:MatrixRetrieve a row from the matrix as an array of scalars.- Specified by:
getRowScalarsin classMatrix<U extends Unit<U>,S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Parameters:
row- row of the values to retrieve- Returns:
- the row as a Scalar array
- Throws:
IndexOutOfBoundsException- in case row is out of bounds
-
getColumnScalars
Description copied from class:MatrixRetrieve a column from the matrix as an array of scalars.- Specified by:
getColumnScalarsin classMatrix<U extends Unit<U>,S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Parameters:
col- column of the values to retrieve- Returns:
- the column as a Scalar array
- Throws:
IndexOutOfBoundsException- in case column is out of bounds
-
getDiagonalScalars
Description copied from class:MatrixRetrieve the main diagonal of the matrix as an array of scalars.- Specified by:
getDiagonalScalarsin classMatrix<U extends Unit<U>,S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Returns:
- the main diagonal as a Scalar array
- Throws:
ValueRuntimeException- in case the matrix is not square
-
toSparse
Description copied from class:IndexedValueCreate and return a sparse version of this internal storage. When the data was already sparse, the current version is returned and no copy will be made of the data.- Specified by:
toSparsein classIndexedValue<U extends Unit<U>,S extends FloatScalar<U, S>, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Returns:
- a sparse version of this internal storage
-
toDense
Description copied from class:IndexedValueCreate and return a dense version of this internal storage. When the data was already dense, the current version is returned and no copy will be made of the data.- Specified by:
toDensein classIndexedValue<U extends Unit<U>,S extends FloatScalar<U, S>, M extends FloatMatrix<U, S, V, M>, FloatMatrixData> - Returns:
- a dense version of this internal storage
-
assign
Execute a function on a cell by cell basis. Note: May be expensive when used on sparse data.- Parameters:
floatFunction- the function to apply- Returns:
- this updated matrix
-
abs
Description copied from interface:ValueReturn a new Scalar/Vector/Matrix with absolute value(s).- Returns:
- a new R with absolute value(s)
-
ceil
Description copied from interface:ValueReturn a new Scalar/Vector/Matrix with the nearest integer value(s) above the current value(s).- Returns:
- a new R with absolute value(s)
-
floor
Description copied from interface:ValueReturn a new Scalar/Vector/Matrix with the nearest integer value(s) below the current value(s).- Returns:
- a new R with absolute value(s)
-
neg
Description copied from interface:ValueReturn a new Scalar/Vector/Matrix with negated value(s).- Returns:
- a new R with negated value(s)
-
rint
Description copied from interface:ValueReturn a new Scalar/Vector/Matrix with the nearest integer value(s). When the value is exactly in the middle between two integer values, the even one is returned.- Returns:
- a new R with absolute value(s)
-
toString
Description copied from interface:ValueConcise description of this value. -
toString
Description copied from interface:ValueSomewhat verbose description of this value with the values expressed in the specified unit.- Parameters:
displayUnit- the unit into which the values are converted for display- Returns:
- printable string with the value contents expressed in the specified unit
-
toString
Description copied from interface:ValueSomewhat verbose description of this value with optional type and unit information.- Parameters:
verbose- if true; include type info; if false; exclude type infowithUnit- if true; include the unit; of false; exclude the unit- Returns:
- printable string with the value contents
-
toString
Description copied from interface:ValueSomewhat verbose description of this value with the values expressed in the specified unit.- Parameters:
displayUnit- the unit into which the values are converted for displayverbose- if true; include type info; if false; exclude type infowithUnit- if true; include the unit; of false; exclude the unit- Returns:
- printable string with the value contents
-
checkIndex
Check that provided row and column indices are valid.- Parameters:
row- the row value to checkcol- the column value to check- Throws:
IndexOutOfBoundsException- when row or column is invalid
-
checkRowIndex
Check that provided row index is valid.- Parameters:
row- the row value to check- Throws:
IndexOutOfBoundsException- when row is invalid
-
checkColumnIndex
Check that provided column index is valid.- Parameters:
col- the column value to check- Throws:
IndexOutOfBoundsException- when row is invalid
-
checkSquare
Check that the matrix is square.- Throws:
ValueRuntimeException- when matrix is not square
-
determinantSI
Compute the determinant of the matrix, based on the SI values.- Returns:
- the determinant of the matrix
- Throws:
ValueRuntimeException- when matrix is neither sparse, nor dense, or not square
-
hashCode
public int hashCode() -
equals
-