Class AbstractFloatMatrix<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
java.lang.Object
org.djunits.value.AbstractValue<U,T>
org.djunits.value.AbstractIndexedValue<U,S,M,FloatMatrixData>
org.djunits.value.vfloat.matrix.base.AbstractFloatMatrix<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
,Matrix<U,S,V,M>
,ValueFunctions<U,M>
,IndexedValue<U,S,M>
,Value<U,M>
,FloatMatrixInterface<U,S,V,M>
- Direct Known Subclasses:
AbstractFloatMatrixAbs
,AbstractFloatMatrixRel
public abstract class AbstractFloatMatrix<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>> extends AbstractIndexedValue<U,S,M,FloatMatrixData> implements FloatMatrixInterface<U,S,V,M>
The most basic abstract class for the FloatMatrix.
Copyright (c) 2013-2019 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, Wouter Schakel
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.djunits.value.base.Matrix
Matrix.Abs<AU extends AbsoluteLinearUnit<AU,RU>,A extends Scalar<AU,A>,AV extends Vector.Abs<AU,A,AV,RU,R,RV>,AM extends Matrix.Abs<AU,A,AV,AM,RU,R,RV,RM>,RU extends Unit<RU>,R extends Scalar<RU,R>,RV extends Vector.RelWithAbs<AU,A,AV,RU,R,RV>,RM extends Matrix.RelWithAbs<AU,A,AV,AM,RU,R,RV,RM>>, Matrix.Rel<U extends Unit<U>,S extends Scalar<U,S>,V extends Vector<U,S,V>,RM extends Matrix.Rel<U,S,V,RM>>, Matrix.RelWithAbs<AU extends AbsoluteLinearUnit<AU,RU>,A extends Scalar<AU,A>,AV extends Vector.Abs<AU,A,AV,RU,R,RV>,AM extends Matrix.Abs<AU,A,AV,AM,RU,R,RV,RM>,RU extends Unit<RU>,R extends Scalar<RU,R>,RV extends Vector.RelWithAbs<AU,A,AV,RU,R,RV>,RM extends Matrix.RelWithAbs<AU,A,AV,AM,RU,R,RV,RM>>
-
Field Summary
Fields Modifier and Type Field Description protected FloatMatrixData
data
The stored data as an object, can be sparse or dense. -
Constructor Summary
Constructors Constructor Description AbstractFloatMatrix(FloatMatrixData data, U unit)
Construct a new FloatMatrix. -
Method Summary
Modifier and Type Method Description M
abs()
Return a new Scalar/Vector/Matrix with absolute value(s).M
assign(FloatFunction floatFunction)
Execute a function on a cell by cell basis.M
ceil()
Return a new Scalar/Vector/Matrix with the nearest integer value(s) above the current value(s).protected void
checkColumnIndex(int col)
Check that provided column index is valid.protected void
checkIndex(int row, int col)
Check that provided row and column indices are valid.protected void
checkRowIndex(int row)
Check that provided row index is valid.protected void
checkSquare()
Check that the matrix is square.int
cols()
Retrieve the number of columns of the matrix.float
determinant()
Compute the determinant of the matrix.boolean
equals(Object obj)
M
floor()
Return a new Scalar/Vector/Matrix with the nearest integer value(s) below the current value(s).S
get(int row, int column)
Retrieve a value from the matrix.V
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 FloatMatrixData
getData()
Retrieve the data object.V
getDiagonal()
Retrieve the main diagonal of the matrix as a vector.S[]
getDiagonalScalars()
Retrieve the main diagonal of the matrix as an array of scalars.float[]
getDiagonalSI()
Retrieve the main diagonal of the matrix as an array of float.float
getInUnit(int row, int column)
Retrieve the value stored at a specified row and column in the original unit.float
getInUnit(int row, int column, U targetUnit)
Retrieve the value stored at a specified row and column converted into a specified unit.V
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[][]
getScalars()
Return the vector as a 2D-array of scalars.float
getSI(int row, int column)
Retrieve the value stored at a specified row and column in the standard SI unit.float[][]
getValuesInUnit()
Create a dense float[][] array filled with the values in the original unit.float[][]
getValuesInUnit(U targetUnit)
Create a dense float[][] array filled with the values converted into a specified unit.float[][]
getValuesSI()
Create a dense float[][] array filled with the values in the standard SI unit.int
hashCode()
M
neg()
Return a new Scalar/Vector/Matrix with negated value(s).M
rint()
Return a new Scalar/Vector/Matrix with the nearest integer value(s).int
rows()
Retrieve the number of rows of the matrix.void
set(int row, int column, S value)
Set the scalar value at the specified position.protected void
setData(FloatMatrixData data)
Set the data object.void
setInUnit(int row, int column, float valueInUnit)
Set the value, specified in the (current) display unit, at the specified position.void
setInUnit(int row, int column, float valueInUnit, U valueUnit)
Set the value, specified in thevalueUnit
, at the specified position.void
setSI(int row, int column, float valueSI)
Set the value, specified in the standard SI unit, at the specified position.M
toDense()
Create and return a dense version of this internal storage.M
toSparse()
Create and return a sparse version of this internal storage.String
toString()
Concise description of this value.String
toString(boolean verbose, boolean withUnit)
Somewhat verbose description of this value with optional type and unit information.String
toString(U displayUnit)
Somewhat verbose description of this value with the values expressed in the specified unit.String
toString(U displayUnit, boolean verbose, boolean withUnit)
Somewhat verbose description of this value with the values expressed in the specified unit.Methods inherited from class org.djunits.value.AbstractIndexedValue
cardinality, checkCopyOnWrite, clone, getStorageType, immutable, isCopyOnWrite, isDense, isMutable, isSparse, mutable, setCopyOnWrite, setMutable
Methods inherited from class org.djunits.value.AbstractValue
getDisplayUnit, isAbsolute, isRelative, setDisplayUnit
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.djunits.value.vfloat.matrix.base.FloatMatrixInterface
instantiateMatrix, instantiateScalarSI, instantiateVector
Methods inherited from interface org.djunits.value.IndexedValue
cardinality, getScalarClass, getStorageType, immutable, isDense, isMutable, isSparse, mutable
Methods inherited from interface org.djunits.value.Value
getDisplayUnit, isAbsolute, isRelative, setDisplayUnit
-
Field Details
-
data
The stored data as an object, can be sparse or dense.
-
-
Constructor Details
-
AbstractFloatMatrix
AbstractFloatMatrix(FloatMatrixData data, U unit)Construct a new FloatMatrix.- Parameters:
data
- FloatMatrixData; an internal data objectunit
- U; the unit
-
-
Method Details
-
getData
Retrieve the data object. Method can only be used within package and by subclasses.- Specified by:
getData
in classAbstractIndexedValue<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,M extends AbstractFloatMatrix<U,S,V,M>,FloatMatrixData>
- Returns:
- D; the internal data
-
setData
Set the data object. Method can only be used within package and by subclasses.- Specified by:
setData
in classAbstractIndexedValue<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,M extends AbstractFloatMatrix<U,S,V,M>,FloatMatrixData>
- Parameters:
data
- D; the internal data
-
getSI
Retrieve the value stored at a specified row and column in the standard SI unit.- Specified by:
getSI
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the value to retrievecolumn
- int; column of the value to retrieve- Returns:
- float; value at position row, column in the standard SI unit
- Throws:
ValueRuntimeException
- 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.- Specified by:
getInUnit
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the value to retrievecolumn
- int; column of the value to retrieve- Returns:
- float; value at position row, column in the original unit
- Throws:
ValueRuntimeException
- 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.- Specified by:
getInUnit
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the value to retrievecolumn
- int; column of the value to retrievetargetUnit
- U; the unit for the result- Returns:
- float; value at position row, column converted into the specified unit
- Throws:
ValueRuntimeException
- 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.- Specified by:
setSI
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the value to setcolumn
- int; column of the value to setvalueSI
- float; the value, specified in the standard SI unit- Throws:
ValueRuntimeException
- when index out of range (index < 0 or index >= size())
-
setInUnit
Set the value, specified in the (current) display unit, at the specified position.- Specified by:
setInUnit
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the value to setcolumn
- int; column of the value to setvalueInUnit
- float; the value, specified in the (current) display unit- Throws:
ValueRuntimeException
- when index out of range (index < 0 or index >= size())
-
setInUnit
public void setInUnit(int row, int column, float valueInUnit, U valueUnit) throws ValueRuntimeExceptionSet the value, specified in thevalueUnit
, at the specified position.- Specified by:
setInUnit
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the value to setcolumn
- int; column of the value to setvalueInUnit
- float; the value, specified in the (current) display unitvalueUnit
- U; the unit in which thevalueInUnit
is expressed- Throws:
ValueRuntimeException
- when index out of range (index < 0 or index >= size())
-
set
Set the scalar value at the specified position.- Specified by:
set
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the value to setcolumn
- int; column of the value to setvalue
- S; the value to set- Throws:
ValueRuntimeException
- when index out of range (index < 0 or index >= size())
-
getRowSI
Retrieve a row from the matrix as an array of float.- Specified by:
getRowSI
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the values to retrieve- Returns:
- S[]; the row as a float array
- Throws:
ValueRuntimeException
- in case row is out of bounds
-
getColumnSI
Retrieve a column from the matrix as an array of float.- Specified by:
getColumnSI
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
column
- int; column of the values to retrieve- Returns:
- S[]; the column as a float array
- Throws:
ValueRuntimeException
- in case column is out of bounds
-
getDiagonalSI
Retrieve the main diagonal of the matrix as an array of float.- Specified by:
getDiagonalSI
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Returns:
- V; 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.- Specified by:
getValuesSI
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Returns:
- float[][]; 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.- Specified by:
getValuesInUnit
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Returns:
- float[][]; the values in the original unit
-
getValuesInUnit
Create a dense float[][] array filled with the values converted into a specified unit.- Specified by:
getValuesInUnit
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
targetUnit
- U; the unit into which the values are converted for use- Returns:
- float[][]; the values converted into the specified unit
-
rows
public int rows()Retrieve the number of rows of the matrix. -
cols
public int cols()Retrieve the number of columns of the matrix. -
getScalars
Return the vector as a 2D-array of scalars.- Specified by:
getScalars
in interfaceMatrix<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Returns:
- S[][]; the vector as a 2D-array of scalars
-
get
Retrieve a value from the matrix.- Specified by:
get
in interfaceMatrix<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the value to retrievecolumn
- int; column of the value to retrieve- Returns:
- S; the value as a Scalar
- Throws:
ValueRuntimeException
- in case row or column is out of bounds
-
getRow
Retrieve a row from the matrix as a vector.- Specified by:
getRow
in interfaceMatrix<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the values to retrieve- Returns:
- V; the row as a Vector
- Throws:
ValueRuntimeException
- in case row is out of bounds
-
getColumn
Retrieve a column from the matrix as a vector.- Specified by:
getColumn
in interfaceMatrix<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
column
- int; column of the values to retrieve- Returns:
- V; the column as a Vector
- Throws:
ValueRuntimeException
- in case column is out of bounds
-
getDiagonal
Retrieve the main diagonal of the matrix as a vector.- Specified by:
getDiagonal
in interfaceMatrix<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Returns:
- V; the main diagonal as a Vector
- Throws:
ValueRuntimeException
- in case the matrix is not square
-
getRowScalars
Retrieve a row from the matrix as an array of scalars.- Specified by:
getRowScalars
in interfaceMatrix<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
row
- int; row of the values to retrieve- Returns:
- S[]; the row as a Scalar array
- Throws:
ValueRuntimeException
- in case row is out of bounds
-
getColumnScalars
Retrieve a column from the matrix as an array of scalars.- Specified by:
getColumnScalars
in interfaceMatrix<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
col
- int; column of the values to retrieve- Returns:
- S[]; the column as a Scalar array
- Throws:
ValueRuntimeException
- in case column is out of bounds
-
getDiagonalScalars
Retrieve the main diagonal of the matrix as an array of scalars.- Specified by:
getDiagonalScalars
in interfaceMatrix<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Returns:
- V; the main diagonal as a Scalar array
- Throws:
ValueRuntimeException
- in case the matrix is not square
-
toSparse
Create 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:
toSparse
in interfaceIndexedValue<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>>
- Returns:
- T; a sparse version of this internal storage
-
toDense
Create 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:
toDense
in interfaceIndexedValue<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>>
- Returns:
- T; 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.- Specified by:
assign
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Parameters:
floatFunction
- FloatFunction; the function to apply- Returns:
- M; this updated matrix
-
abs
Return a new Scalar/Vector/Matrix with absolute value(s).- Specified by:
abs
in interfaceValueFunctions<U extends Unit<U>,S extends AbstractFloatScalar<U,S>>
- Returns:
- R; a new R with absolute value(s)
-
ceil
Return a new Scalar/Vector/Matrix with the nearest integer value(s) above the current value(s).- Specified by:
ceil
in interfaceValueFunctions<U extends Unit<U>,S extends AbstractFloatScalar<U,S>>
- Returns:
- R; a new R with absolute value(s)
-
floor
Return a new Scalar/Vector/Matrix with the nearest integer value(s) below the current value(s).- Specified by:
floor
in interfaceValueFunctions<U extends Unit<U>,S extends AbstractFloatScalar<U,S>>
- Returns:
- R; a new R with absolute value(s)
-
neg
Return a new Scalar/Vector/Matrix with negated value(s).- Specified by:
neg
in interfaceValueFunctions<U extends Unit<U>,S extends AbstractFloatScalar<U,S>>
- Returns:
- R; a new R with negated value(s)
-
rint
Return 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.- Specified by:
rint
in interfaceValueFunctions<U extends Unit<U>,S extends AbstractFloatScalar<U,S>>
- Returns:
- R; a new R with absolute value(s)
-
toString
Concise description of this value. -
toString
Somewhat verbose description of this value with the values expressed in the specified unit. -
toString
Somewhat verbose description of this value with optional type and unit information.- Specified by:
toString
in interfaceValue<U extends Unit<U>,S extends AbstractFloatScalar<U,S>>
- Parameters:
verbose
- boolean; if true; include type info; if false; exclude type infowithUnit
- boolean; if true; include the unit; of false; exclude the unit- Returns:
- String; printable string with the value contents
-
toString
Somewhat verbose description of this value with the values expressed in the specified unit.- Specified by:
toString
in interfaceValue<U extends Unit<U>,S extends AbstractFloatScalar<U,S>>
- Parameters:
displayUnit
- U; the unit into which the values are converted for displayverbose
- boolean; if true; include type info; if false; exclude type infowithUnit
- boolean; if true; include the unit; of false; exclude the unit- Returns:
- String; printable string with the value contents
-
checkIndex
Check that provided row and column indices are valid.- Parameters:
row
- int; the row value to checkcol
- int; the column value to check- Throws:
ValueRuntimeException
- when row or column is invalid
-
checkRowIndex
Check that provided row index is valid.- Parameters:
row
- int; the row value to check- Throws:
ValueRuntimeException
- when row is invalid
-
checkColumnIndex
Check that provided column index is valid.- Parameters:
col
- int; the column value to check- Throws:
ValueRuntimeException
- when row is invalid
-
checkSquare
Check that the matrix is square.- Throws:
ValueRuntimeException
- when matrix is not square
-
determinant
Compute the determinant of the matrix.- Specified by:
determinant
in interfaceFloatMatrixInterface<U extends Unit<U>,S extends AbstractFloatScalar<U,S>,V extends AbstractFloatVector<U,S,V>,M extends AbstractFloatMatrix<U,S,V,M>>
- Returns:
- float; the determinant of the matrix
- Throws:
ValueRuntimeException
- when matrix is neither sparse, nor dense, or not square
-
hashCode
public int hashCode() -
equals
-