1 package org.djunits.value.base; 2 3 import org.djunits.unit.Unit; 4 import org.djunits.value.IndexedValue; 5 import org.djunits.value.ValueRuntimeException; 6 import org.djunits.value.storage.Storage; 7 8 /** 9 * Matrix to distinguish a matrix from scalars and matrixs. A possible way to implement this interface is: 10 * 11 * <pre> 12 * class LengthMatrix implements Matrix<LengthUnit, Length, LengthMatrix> 13 * </pre> 14 * 15 * Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 16 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>. <br> 17 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a> 18 * @param <U> the unit 19 * @param <S> the scalar type belonging to the matrix type 20 * @param <V> the corresponding vector type 21 * @param <M> the matrix type with the given unit 22 * @param <DV> the data storage type of the Vector 23 * @param <DM> the data storage type of the Matrix 24 */ 25 public abstract class Matrix<U extends Unit<U>, S extends Scalar<U, S>, V extends Vector<U, S, V, DV>, DV extends Storage<DV>, 26 M extends Matrix<U, S, V, DV, M, DM>, DM extends Storage<DM>> extends IndexedValue<U, S, M, DM> 27 { 28 /** */ 29 private static final long serialVersionUID = 20230620L; 30 31 /** 32 * Construct a new Matrix. 33 * @param displayUnit U; the unit of the new AbstractValue 34 */ 35 public Matrix(final U displayUnit) 36 { 37 super(displayUnit); 38 } 39 40 /** 41 * Retrieve the number of rows of the matrix. 42 * @return int; the number of rows of the matrix 43 */ 44 public abstract int rows(); 45 46 /** 47 * Retrieve the number of columns of the matrix. 48 * @return int; the number of columns of the matrix 49 */ 50 public abstract int cols(); 51 52 /** 53 * Return the class of the corresponding vector. 54 * @return Class<V>; the class of the corresponding vector 55 */ 56 public abstract Class<V> getVectorClass(); 57 58 /** 59 * Retrieve a value from the matrix. 60 * @param row int; row of the value to retrieve 61 * @param column int; column of the value to retrieve 62 * @return S; the value as a Scalar 63 * @throws ValueRuntimeException in case row or column is out of bounds 64 */ 65 public abstract S get(int row, int column) throws ValueRuntimeException; 66 67 /** 68 * Return the vector as a 2D-array of scalars. 69 * @return S[][]; the vector as a 2D-array of scalars 70 */ 71 public abstract S[][] getScalars(); 72 73 /** 74 * Retrieve a row from the matrix as a vector. 75 * @param row int; row of the values to retrieve 76 * @return V; the row as a Vector 77 * @throws ValueRuntimeException in case row is out of bounds 78 */ 79 public abstract V getRow(int row) throws ValueRuntimeException; 80 81 /** 82 * Retrieve a column from the matrix as a vector. 83 * @param column int; column of the values to retrieve 84 * @return V; the column as a Vector 85 * @throws ValueRuntimeException in case column is out of bounds 86 */ 87 public abstract V getColumn(int column) throws ValueRuntimeException; 88 89 /** 90 * Retrieve the main diagonal of the matrix as a vector. 91 * @return V; the main diagonal as a Vector 92 * @throws ValueRuntimeException in case the matrix is not square 93 */ 94 public abstract V getDiagonal() throws ValueRuntimeException; 95 96 /** 97 * Retrieve a row from the matrix as an array of scalars. 98 * @param row int; row of the values to retrieve 99 * @return S[]; the row as a Scalar array 100 * @throws ValueRuntimeException in case row is out of bounds 101 */ 102 public abstract S[] getRowScalars(int row) throws ValueRuntimeException; 103 104 /** 105 * Retrieve a column from the matrix as an array of scalars. 106 * @param column int; column of the values to retrieve 107 * @return S[]; the column as a Scalar array 108 * @throws ValueRuntimeException in case column is out of bounds 109 */ 110 public abstract S[] getColumnScalars(int column) throws ValueRuntimeException; 111 112 /** 113 * Retrieve the main diagonal of the matrix as an array of scalars. 114 * @return V; the main diagonal as a Scalar array 115 * @throws ValueRuntimeException in case the matrix is not square 116 */ 117 public abstract S[] getDiagonalScalars() throws ValueRuntimeException; 118 119 }