Package org.djunits.value.base
Class Matrix<U extends Unit<U>,S extends Scalar<U,S>,V extends Vector<U,S,V,DV>,DV extends Storage<DV>,M extends Matrix<U,S,V,DV,M,DM>,DM extends Storage<DM>>
java.lang.Object
org.djunits.value.IndexedValue<U,S,M,DM>
org.djunits.value.base.Matrix<U,S,V,DV,M,DM>
- Type Parameters:
U
- the unitS
- the scalar type belonging to the matrix typeV
- the corresponding vector typeM
- the matrix type with the given unitDV
- the data storage type of the VectorDM
- the data storage type of the Matrix
- All Implemented Interfaces:
Serializable
,Cloneable
,Value<U,
M>
- Direct Known Subclasses:
DoubleMatrix
,FloatMatrix
public abstract class Matrix<U extends Unit<U>,S extends Scalar<U,S>,V extends Vector<U,S,V,DV>,DV extends Storage<DV>,M extends Matrix<U,S,V,DV,M,DM>,DM extends Storage<DM>>
extends IndexedValue<U,S,M,DM>
Matrix to distinguish a matrix from scalars and matrixs. A possible way to implement this interface is:
BSD-style license. See DJUNITS License.
class LengthMatrix implements Matrix<LengthUnit, Length, LengthMatrix>Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.
- Author:
- Alexander Verbraeck
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract int
cols()
Retrieve the number of columns of the matrix.abstract S
get
(int row, int column) Retrieve a value from the matrix.abstract V
getColumn
(int column) Retrieve a column from the matrix as a vector.abstract S[]
getColumnScalars
(int column) Retrieve a column from the matrix as an array of scalars.abstract V
Retrieve the main diagonal of the matrix as a vector.abstract S[]
Retrieve the main diagonal of the matrix as an array of scalars.abstract V
getRow
(int row) Retrieve a row from the matrix as a vector.abstract S[]
getRowScalars
(int row) Retrieve a row from the matrix as an array of scalars.abstract S[][]
Return the vector as a 2D-array of scalars.Return the class of the corresponding vector.abstract int
rows()
Retrieve the number of rows of the matrix.Methods inherited from class org.djunits.value.IndexedValue
cardinality, checkCopyOnWrite, clone, getData, getDisplayUnit, getScalarClass, getStorageType, immutable, isCopyOnWrite, isDense, isMutable, isSparse, mutable, setCopyOnWrite, setData, setDisplayUnit, setMutable, toDense, toSparse
-
Constructor Details
-
Matrix
Construct a new Matrix.- Parameters:
displayUnit
- U; the unit of the new AbstractValue
-
-
Method Details
-
rows
public abstract int rows()Retrieve the number of rows of the matrix.- Returns:
- int; the number of rows of the matrix
-
cols
public abstract int cols()Retrieve the number of columns of the matrix.- Returns:
- int; the number of columns of the matrix
-
getVectorClass
Return the class of the corresponding vector.- Returns:
- Class<V>; the class of the corresponding vector
-
get
Retrieve a value from the matrix.- Parameters:
row
- int; row of the value to retrievecolumn
- int; column of the value to retrieve- Returns:
- S; the value as a Scalar
- Throws:
IndexOutOfBoundsException
- in case row or column is out of bounds
-
getScalars
Return the vector as a 2D-array of scalars.- Returns:
- S[][]; the vector as a 2D-array of scalars
-
getRow
Retrieve a row from the matrix as a vector.- Parameters:
row
- int; row of the values to retrieve- Returns:
- V; the row as a Vector
- Throws:
IndexOutOfBoundsException
- in case row is out of bounds
-
getColumn
Retrieve a column from the matrix as a vector.- Parameters:
column
- int; column of the values to retrieve- Returns:
- V; the column as a Vector
- Throws:
IndexOutOfBoundsException
- in case column is out of bounds
-
getDiagonal
Retrieve the main diagonal of the matrix as a vector.- 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.- Parameters:
row
- int; row of the values to retrieve- Returns:
- S[]; the row as a Scalar array
- Throws:
IndexOutOfBoundsException
- in case row is out of bounds
-
getColumnScalars
Retrieve a column from the matrix as an array of scalars.- Parameters:
column
- int; column of the values to retrieve- Returns:
- S[]; the column as a Scalar array
- Throws:
IndexOutOfBoundsException
- in case column is out of bounds
-
getDiagonalScalars
Retrieve the main diagonal of the matrix as an array of scalars.- Returns:
- V; the main diagonal as a Scalar array
- Throws:
ValueRuntimeException
- in case the matrix is not square
-