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 unit
S - the scalar type belonging to the matrix type
V - the corresponding vector type
M - the matrix type with the given unit
DV - the data storage type of the Vector
DM - 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:
 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 Details

    • Matrix

      public Matrix(U displayUnit)
      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

      public abstract Class<V> getVectorClass()
      Return the class of the corresponding vector.
      Returns:
      Class<V>; the class of the corresponding vector
    • get

      public abstract S get(int row, int column) throws ValueRuntimeException
      Retrieve a value from the matrix.
      Parameters:
      row - int; row of the value to retrieve
      column - 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
    • getScalars

      public abstract S[][] getScalars()
      Return the vector as a 2D-array of scalars.
      Returns:
      S[][]; the vector as a 2D-array of scalars
    • getRow

      public abstract V getRow(int row) throws ValueRuntimeException
      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:
      ValueRuntimeException - in case row is out of bounds
    • getColumn

      public abstract V getColumn(int column) throws ValueRuntimeException
      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:
      ValueRuntimeException - in case column is out of bounds
    • getDiagonal

      public abstract V getDiagonal() throws ValueRuntimeException
      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

      public abstract S[] getRowScalars(int row) throws ValueRuntimeException
      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:
      ValueRuntimeException - in case row is out of bounds
    • getColumnScalars

      public abstract S[] getColumnScalars(int column) throws ValueRuntimeException
      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:
      ValueRuntimeException - in case column is out of bounds
    • getDiagonalScalars

      public abstract S[] getDiagonalScalars() throws ValueRuntimeException
      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