Package org.djunits.vecmat.table
Class QuantityTable<Q extends Quantity<Q>>
java.lang.Object
org.djunits.vecmat.def.VectorMatrix<Q,T,SI,H,TT>
org.djunits.vecmat.def.Table<Q,QuantityTable<Q>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q>>
org.djunits.vecmat.table.QuantityTable<Q>
- Type Parameters:
Q- the quantity type
- All Implemented Interfaces:
Serializable,Additive<QuantityTable<Q>>,Scalable<QuantityTable<Q>>,Value<QuantityTable<Q>,,Q> Hadamard<QuantityTable<?>,QuantityTable<SIQuantity>>
public class QuantityTable<Q extends Quantity<Q>>
extends Table<Q,QuantityTable<Q>,QuantityTable<SIQuantity>,QuantityTable<?>,QuantityTable<Q>>
QuantityTable is a two-dimensonal table with quantities. The QuantityTable allows for Hadamard (element-wise) operations, but
not for vector/matrix operations. A QuantityTable can be transformed to a MatrixNxM or vice versa.
Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
- Author:
- Alexander Verbraeck
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionQuantityTable(DataGridSi<?> dataGridSi, Unit<?, Q> displayUnit) Create a new NxM QuantityTable with a unit, based on a DataGrid storage object. -
Method Summary
Modifier and TypeMethodDescription<TQ extends Quantity<TQ>>
QuantityTable<TQ>Return the QuantityTable 'as' a QuantityTable with a known quantity, using a unit to express the result in.intcols()Return the number of columns.booleanformat()Concise description of this quantity table.format(TableFormat format) String representation of this quantity table after applying the format.String representation of this quantity table, expressed in the specified unit.double[]getColumnSi(int col) Return an array with SI-values for the given column (0-based) from the table or matrix.getColumnVector(int col) Return a quantity column (0-based) from the table or matrix.DataGridSi<?>Return the internal datagrid object, so we can retrieve data from it.double[]getRowSi(int row) Return an array with SI-values for the given row (0-based) from the table or matrix.getRowVector(int row) Return a quantity row (0-based) from the table or matrix.double[]Return a row-major array of SI-values for this matrix or vector.inthashCode()instantiateSi(double[] siNew) Return a new vector or matrix with the given SI or BASE values.instantiateSi(double[] siNew, SIUnit siUnit) Return a new vector or matrix in SI-units with the given SI or BASE values.mgetColumnVector(int mCol) Return a quantity column (1-based) from the table or matrix.mgetRowVector(int mRow) Return a quantity row (1-based) from the table or matrix.intReturn the number of non-zero entries in the vector, matrix or table.static <Q extends Quantity<Q>>
QuantityTable<Q>Create a new QuantityTable with a unit, based on a 2-dimensional grid with values in the given unit.static <Q extends Quantity<Q>>
QuantityTable<Q>Create a new QuantityTable with a unit, based on a row-major array with values in the given unit.static <Q extends Quantity<Q>>
QuantityTable<Q>of(Q[][] grid) Create a QuantityTable without needing generics, based on a 2-dimensional grid of quantities.static <Q extends Quantity<Q>>
QuantityTable<Q>of(Q[] data, int rows, int cols) Create a QuantityTable without needing generics, based on a row-major array of quantities.static <Q extends Quantity<Q>>
QuantityTable<Q>Create a new QuantityTable with a unit, based on a 2-dimensional grid with SI-values.static <Q extends Quantity<Q>>
QuantityTable<Q>Create a QuantityTable without needing generics, based on a row-major array with SI-values.introws()Return the number of rows.doublesi(int row, int col) Return the si-value at position (row, col), where both row and col are 0-based values.Return the transposed quantity table.double[]Return a row-major possibly UNSAFE array of SI-values for this matrix or vector.Methods inherited from class org.djunits.vecmat.def.Table
checkCol, checkRow, get, getColumnScalars, getRowScalars, getScalarArray, getScalarGrid, getSiGrid, mcheckCol, mcheckRow, mget, mgetColumnScalars, mgetColumnSi, mgetRowScalars, mgetRowSi, msiMethods inherited from class org.djunits.vecmat.def.VectorMatrix
abs, add, add, asMatrix1x1, asMatrix2x2, asMatrix3x3, asMatrixNxM, asMatrixNxN, asQuantityTable, asVector1, asVector2Col, asVector2Row, asVector3Col, asVector3Row, asVectorNCol, asVectorNRow, checkMultiply, checkMultiply, divideElements, divideEntries, getDisplayUnit, invertEntries, isRelative, max, mean, median, min, multiplyElements, multiplyEntries, multiplyEntries, negate, nnz, scaleBy, setDisplayUnit, subtract, subtract, sum, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djunits.vecmat.operations.Hadamard
divideEntriesMethods inherited from interface org.djunits.value.Value
isAbsolute, setDisplayUnit
-
Constructor Details
-
QuantityTable
Create a new NxM QuantityTable with a unit, based on a DataGrid storage object. This constructor assumes dataSi stores SI values. Note: NO safe copy is made.- Parameters:
dataGridSi- the data of the matrix, in SI unit.displayUnit- the display unit to use
-
-
Method Details
-
instantiateSi
Description copied from class:VectorMatrixReturn a new vector or matrix with the given SI or BASE values.- Specified by:
instantiateSiin classVectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Parameters:
siNew- the values for the new vector or matrix in row-major format- Returns:
- a new matrix with the provided SI or BASE values
-
instantiateSi
Description copied from class:VectorMatrixReturn a new vector or matrix in SI-units with the given SI or BASE values.- Specified by:
instantiateSiin classVectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Parameters:
siNew- the values for the new vector or matrix in row-major formatsiUnit- the new unit for the new vector or matrix- Returns:
- a new matrix with the provided SI or BASE values
-
getDataGrid
Return the internal datagrid object, so we can retrieve data from it.- Returns:
- the internal datagrid object
-
getSiArray
public double[] getSiArray()Description copied from class:VectorMatrixReturn a row-major array of SI-values for this matrix or vector. This is guaranteed to be a safe copy.- Specified by:
getSiArrayin classVectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Returns:
- the row-major array of SI-values (safe copy)
-
unsafeSiArray
public double[] unsafeSiArray()Description copied from class:VectorMatrixReturn a row-major possibly UNSAFE array of SI-values for this matrix or vector. The method might give access to the underlying data structure, so treat the data carefully.- Specified by:
unsafeSiArrayin classVectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Returns:
- the row-major array of SI-values (safe copy)
-
si
Description copied from class:TableReturn the si-value at position (row, col), where both row and col are 0-based values.- Specified by:
siin classTable<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Parameters:
row- the row (0-based)col- the column (0-based)- Returns:
- the si-value at position (row, col)
- Throws:
IndexOutOfBoundsException- when row or col < 0 or larger than number of rows/columns - 1.
-
getRowVector
Description copied from class:TableReturn a quantity row (0-based) from the table or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
getRowVectorin classTable<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Parameters:
row- the row number to retrieve (0-based)- Returns:
- a row vector with the data at the given row
-
mgetRowVector
Description copied from class:TableReturn a quantity row (1-based) from the table or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
mgetRowVectorin classTable<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Parameters:
mRow- the row number to retrieve (1-based)- Returns:
- a row vector with the data at the given row
-
getColumnVector
Description copied from class:TableReturn a quantity column (0-based) from the table or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
getColumnVectorin classTable<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Parameters:
col- the column number to retrieve (0-based)- Returns:
- a column vector with the data at the given column
-
mgetColumnVector
Description copied from class:TableReturn a quantity column (1-based) from the table or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
mgetColumnVectorin classTable<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Parameters:
mCol- the column number to retrieve (1-based)- Returns:
- a column vector with the data at the given column
-
getRowSi
public double[] getRowSi(int row) Description copied from class:TableReturn an array with SI-values for the given row (0-based) from the table or matrix.- Specified by:
getRowSiin classTable<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Parameters:
row- the row number to retrieve (0-based)- Returns:
- an array with SI-values with the data at the given row
-
getColumnSi
public double[] getColumnSi(int col) Description copied from class:TableReturn an array with SI-values for the given column (0-based) from the table or matrix.- Specified by:
getColumnSiin classTable<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Parameters:
col- the column number to retrieve (0-based)- Returns:
- an array with SI-values with the data at the given column
-
rows
public int rows()Description copied from class:VectorMatrixReturn the number of rows.- Specified by:
rowsin classVectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Returns:
- the number of rows
-
cols
public int cols()Description copied from class:VectorMatrixReturn the number of columns.- Specified by:
colsin classVectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Returns:
- the number of columns
-
nonZeroCount
public int nonZeroCount()Description copied from class:VectorMatrixReturn the number of non-zero entries in the vector, matrix or table. Note that NaN and Infinity count as a non-zero element. The value -0.0 counts as 0.0.- Specified by:
nonZeroCountin classVectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Returns:
- the number of non-zero entries in the vector, matrix or table
-
transpose
Return the transposed quantity table. A transposed quantity table has the same unit as the original one.- Specified by:
transposein classVectorMatrix<Q extends Quantity<Q>,QuantityTable<Q extends Quantity<Q>>, QuantityTable<SIQuantity>, QuantityTable<?>, QuantityTable<Q extends Quantity<Q>>> - Returns:
- the transposed quantity table
-
hashCode
public int hashCode() -
equals
-
of
public static <Q extends Quantity<Q>> QuantityTable<Q> of(double[] dataInUnit, int rows, int cols, Unit<?, Q> unit) Create a new QuantityTable with a unit, based on a row-major array with values in the given unit.- Type Parameters:
Q- the quantity type- Parameters:
dataInUnit- the table values {a11, a12, ..., A1M, ..., aN1, aN2, ..., aNM} expressed in the unitrows- the number of rowscols- the number of columnsunit- the unit of the data, also used as the display unit- Returns:
- a new QuantityTable with a unit
- Throws:
IllegalArgumentException- when dataInUnit does not contain a square number of values
-
ofSi
public static <Q extends Quantity<Q>> QuantityTable<Q> ofSi(double[] dataSi, int rows, int cols, Unit<?, Q> displayUnit) Create a QuantityTable without needing generics, based on a row-major array with SI-values.- Type Parameters:
Q- the quantity type- Parameters:
dataSi- the table values {a11, a12, ..., A1M, ..., aN1, aN2, ..., aNM} as an array using SI unitsrows- the number of rowscols- the number of columnsdisplayUnit- the display unit to use- Returns:
- a new QuantityTable with a unit
- Throws:
IllegalArgumentException- when dataSi does not contain a square number of values
-
of
Create a QuantityTable without needing generics, based on a row-major array of quantities. The unit is taken from the first quantity in the array.- Type Parameters:
Q- the quantity type- Parameters:
data- the table values {a11, a12, ..., A1M, ..., aN1, aN2, ..., aNM} expressed as an array of quantitiesrows- the number of rowscols- the number of columns- Returns:
- a new QuantityTable with a unit
- Throws:
IllegalArgumentException- when data does not contain a square number of quantities
-
ofSi
public static <Q extends Quantity<Q>> QuantityTable<Q> ofSi(double[][] gridSi, Unit<?, Q> displayUnit) Create a new QuantityTable with a unit, based on a 2-dimensional grid with SI-values.- Type Parameters:
Q- the quantity type- Parameters:
gridSi- the table values {{a11, a12, ..., A1M}, ..., {aN1, aN2, ..., aNM}} expressed in the SI or base unitdisplayUnit- the unit of the data, which will also be used as the display unit- Returns:
- a new QuantityTable with a unit
- Throws:
IllegalArgumentException- when dataInUnit does not contain a square number of values
-
of
Create a new QuantityTable with a unit, based on a 2-dimensional grid with values in the given unit.- Type Parameters:
Q- the quantity type- Parameters:
gridInUnit- the table values {{a11, a12, ..., A1M}, ..., {aN1, aN2, ..., aNM}} expressed in the unitunit- the unit of the values, also used as the display unit- Returns:
- a new QuantityTable with a unit
- Throws:
IllegalArgumentException- when dataInUnit does not contain a square number of values
-
of
Create a QuantityTable without needing generics, based on a 2-dimensional grid of quantities. The unit is taken from the first quantity in the grid.- Type Parameters:
Q- the quantity type- Parameters:
grid- the table values {{a11, a12, ..., A1M}, ..., {aN1, aN2, ..., aNM}} expressed as a 2-dimensional array of quantities- Returns:
- a new QuantityTable with a unit
- Throws:
IllegalArgumentException- when dataInUnit does not contain a square number of quantities
-
as
public <TQ extends Quantity<TQ>> QuantityTable<TQ> as(Unit<?, TQ> targetUnit) throws IllegalArgumentExceptionReturn the QuantityTable 'as' a QuantityTable with a known quantity, using a unit to express the result in. Throw a Runtime exception when the SI units of this vector and the target vector do not match.- Type Parameters:
TQ- target quantity type- Parameters:
targetUnit- the unit to convert the quantity table to- Returns:
- a quantity table typed in the target quantity table class
- Throws:
IllegalArgumentException- when the units do not match
-
format
Concise description of this quantity table.- Returns:
- a String with the quantity table, with the unit attached.
-
format
String representation of this quantity table after applying the format.- Parameters:
format- the format to apply for the quantity table- Returns:
- a String representation of this quantity table, formatted according to the given format
-
format
String representation of this quantity table, expressed in the specified unit.- Parameters:
targetUnit- the unit into which the values of the quantity table are converted for display- Returns:
- printable string with the quantity table's values expressed in the specified unit
-