org.djunits.value.vdouble.matrix

## Class DoubleMatrixData

• Direct Known Subclasses:
DoubleMatrixDataDense, DoubleMatrixDataSparse

```abstract class DoubleMatrixData
extends Object```
Stores the data for a DoubleMatrix and carries out basic operations.

Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

\$LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) \$, @version \$Revision: 1147 \$, by \$Author: averbraeck \$, initial version Oct 3, 2015
Author:
Alexander Verbraeck, Peter Knoppers
• ### Field Summary

Fields
Modifier and Type Field and Description
`protected int` `cols`
the number of columns of the matrix.
`protected double[]` `matrixSI`
the internal storage of the Matrix; can be sparse or dense.
`protected int` `rows`
the number of rows of the matrix.
• ### Constructor Summary

Constructors
Constructor and Description
`DoubleMatrixData(StorageType storageType)`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`int` `cardinality()`
`int` `cols()`
`abstract DoubleMatrixData` `copy()`
`void` `decrementBy(double valueSI)`
Subtract a number from this matrix on a cell-by-cell basis.
`abstract void` `decrementBy(DoubleMatrixData right)`
Subtract a matrix from this matrix on a cell-by-cell basis.
`DoubleMatrixData` `divide(DoubleMatrixData right)`
Divide two matrices on a cell-by-cell basis.
`void` `divideBy(double valueSI)`
Divide the values of this matrix by a number on a cell-by-cell basis.
`abstract void` `divideBy(DoubleMatrixData right)`
Divide the values of a matrix by the values of another matrix on a cell-by-cell basis.
`boolean` `equals(Object obj)`
`abstract double[][]` `getDenseMatrixSI()`
`abstract double` ```getSI(int row, int col)```
`StorageType` `getStorageType()`
Return the StorageType (DENSE, SPARSE, etc.) for the stored Matrix.
`int` `hashCode()`
`void` `incrementBy(double valueSI)`
Add a number to this matrix on a cell-by-cell basis.
`abstract void` `incrementBy(DoubleMatrixData right)`
Add a matrix to this matrix on a cell-by-cell basis.
`static DoubleMatrixData` ```instantiate(double[][] values, Scale scale, StorageType storageType)```
Instantiate a DoubleMatrixData with the right data type.
`static DoubleMatrixData` ```instantiate(DoubleScalarInterface[][] values, StorageType storageType)```
Instantiate a DoubleMatrixData with the right data type.
`boolean` `isDense()`
`boolean` `isSparse()`
`DoubleMatrixData` `minus(DoubleMatrixData right)`
Subtract two matrices on a cell-by-cell basis.
`void` `multiplyBy(double valueSI)`
Multiply the values of this matrix with a number on a cell-by-cell basis.
`abstract void` `multiplyBy(DoubleMatrixData right)`
Multiply a matrix with the values of another matrix on a cell-by-cell basis.
`DoubleMatrixData` `plus(DoubleMatrixData right)`
Add two matrices on a cell-by-cell basis.
`int` `rows()`
`abstract void` ```setSI(int row, int col, double valueSI)```
Sets a value at the [row, col] point in the matrix.
`DoubleMatrixData` `times(DoubleMatrixData right)`
Multiply two matrix on a cell-by-cell basis.
`DoubleMatrixDataDense` `toDense()`
`DoubleMatrixDataSparse` `toSparse()`
`String` `toString()`
`double` `zSum()`
• ### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### matrixSI

`protected double[] matrixSI`
the internal storage of the Matrix; can be sparse or dense.
• #### rows

`protected int rows`
the number of rows of the matrix.
• #### cols

`protected int cols`
the number of columns of the matrix.
• ### Constructor Detail

• #### DoubleMatrixData

`DoubleMatrixData(StorageType storageType)`
Parameters:
`storageType` - the data type.
• ### Method Detail

• #### instantiate

```public static DoubleMatrixData instantiate(double[][] values,
Scale scale,
StorageType storageType)
throws ValueException```
Instantiate a DoubleMatrixData with the right data type.
Parameters:
`values` - the (SI) values to store
`scale` - the scale of the unit to use for conversion to SI
`storageType` - the data type to use
Returns:
the DoubleMatrixData with the right data type
Throws:
`ValueException` - when values are null, or storageType is null
• #### instantiate

```public static DoubleMatrixData instantiate(DoubleScalarInterface[][] values,
StorageType storageType)
throws ValueException```
Instantiate a DoubleMatrixData with the right data type.
Parameters:
`values` - the values to store
`storageType` - the data type to use
Returns:
the DoubleMatrixData with the right data type
Throws:
`ValueException` - when values is null, or storageType is null
• #### getStorageType

`public final StorageType getStorageType()`
Return the StorageType (DENSE, SPARSE, etc.) for the stored Matrix.
Returns:
the StorageType (DENSE, SPARSE, etc.) for the stored Matrix
• #### rows

`public int rows()`
Returns:
the number of rows of the matrix
• #### cols

`public int cols()`
Returns:
the number of columns of the matrix
• #### isSparse

`public boolean isSparse()`
Returns:
whether data type is sparse.
• #### toSparse

`public DoubleMatrixDataSparse toSparse()`
Returns:
the sparse transformation of this data
• #### isDense

`public boolean isDense()`
Returns:
whether data type is dense.
• #### toDense

`public DoubleMatrixDataDense toDense()`
Returns:
the dense transformation of this data
• #### getSI

```public abstract double getSI(int row,
int col)```
Parameters:
`row` - the row number to get the value for
`col` - the column number to get the value for
Returns:
the value at the [row, col] point
• #### setSI

```public abstract void setSI(int row,
int col,
double valueSI)```
Sets a value at the [row, col] point in the matrix.
Parameters:
`row` - the row number to set the value for
`col` - the column number to set the value for
`valueSI` - the value at the index
• #### cardinality

`public final int cardinality()`
Returns:
the number of non-zero cells.
• #### zSum

`public final double zSum()`
Returns:
the sum of the values of all cells.
• #### copy

`public abstract DoubleMatrixData copy()`
Returns:
a deep copy of the data.
• #### getDenseMatrixSI

`public abstract double[][] getDenseMatrixSI()`
Returns:
a safe dense copy of matrixSI as a matrix
• #### plus

```public DoubleMatrixData plus(DoubleMatrixData right)
throws ValueException```
Add two matrices on a cell-by-cell basis. If both matrices are sparse, a sparse matrix is returned, otherwise a dense matrix is returned.
Parameters:
`right` - the other data object to add
Returns:
the sum of this data object and the other data object
Throws:
`ValueException` - if matrices have different lengths
• #### incrementBy

```public abstract void incrementBy(DoubleMatrixData right)
throws ValueException```
Add a matrix to this matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.
Parameters:
`right` - the other data object to add
Throws:
`ValueException` - if matrices have different lengths
• #### incrementBy

`public void incrementBy(double valueSI)`
Add a number to this matrix on a cell-by-cell basis.
Parameters:
`valueSI` - the value to add
• #### minus

```public DoubleMatrixData minus(DoubleMatrixData right)
throws ValueException```
Subtract two matrices on a cell-by-cell basis. If both matrices are sparse, a sparse matrix is returned, otherwise a dense matrix is returned.
Parameters:
`right` - the other data object to subtract
Returns:
the sum of this data object and the other data object
Throws:
`ValueException` - if matrices have different lengths
• #### decrementBy

```public abstract void decrementBy(DoubleMatrixData right)
throws ValueException```
Subtract a matrix from this matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.
Parameters:
`right` - the other data object to subtract
Throws:
`ValueException` - if matrices have different lengths
• #### decrementBy

`public void decrementBy(double valueSI)`
Subtract a number from this matrix on a cell-by-cell basis.
Parameters:
`valueSI` - the value to subtract
• #### times

```public DoubleMatrixData times(DoubleMatrixData right)
throws ValueException```
Multiply two matrix on a cell-by-cell basis. If both matrices are dense, a dense matrix is returned, otherwise a sparse matrix is returned.
Parameters:
`right` - the other data object to multiply with
Returns:
the sum of this data object and the other data object
Throws:
`ValueException` - if matrices have different lengths
• #### multiplyBy

```public abstract void multiplyBy(DoubleMatrixData right)
throws ValueException```
Multiply a matrix with the values of another matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.
Parameters:
`right` - the other data object to multiply with
Throws:
`ValueException` - if matrices have different lengths
• #### multiplyBy

`public void multiplyBy(double valueSI)`
Multiply the values of this matrix with a number on a cell-by-cell basis.
Parameters:
`valueSI` - the value to multiply with
• #### divide

```public DoubleMatrixData divide(DoubleMatrixData right)
throws ValueException```
Divide two matrices on a cell-by-cell basis. If both matrices are dense, a dense matrix is returned, otherwise a sparse matrix is returned.
Parameters:
`right` - the other data object to divide by
Returns:
the sum of this data object and the other data object
Throws:
`ValueException` - if matrices have different lengths
• #### divideBy

```public abstract void divideBy(DoubleMatrixData right)
throws ValueException```
Divide the values of a matrix by the values of another matrix on a cell-by-cell basis. The type of matrix (sparse, dense) stays the same.
Parameters:
`right` - the other data object to divide by
Throws:
`ValueException` - if matrices have different lengths
• #### divideBy

`public void divideBy(double valueSI)`
Divide the values of this matrix by a number on a cell-by-cell basis.
Parameters:
`valueSI` - the value to multiply with
• #### hashCode

`public int hashCode()`
Overrides:
`hashCode` in class `Object`
• #### equals

`public boolean equals(Object obj)`
Overrides:
`equals` in class `Object`
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`

Copyright © 2015–2018 Delft University of Technology. All rights reserved.