Class DenseData
- java.lang.Object
-
- dev.nm.algebra.linear.matrix.doubles.matrixtype.dense.DenseData
-
- All Implemented Interfaces:
MatrixAccess,Table,DeepCopyable
public abstract class DenseData extends Object implements MatrixAccess, DeepCopyable
This implementation of the storage of a dense matrix stores the data of a 2D matrix as an 1D array. In general, computing index for adouble[]is faster than that for adouble[][]. Hence for most operations, e.g., element-by-element add, minus, this implementation has a better performance.
-
-
Field Summary
Fields Modifier and Type Field Description static intZERO_ENTRY
-
Constructor Summary
Constructors Constructor Description DenseData(double[] data, int nRows, int nCols)Construct a storage.DenseData(double[] data, int nRows, int nCols, DoubleArrayOperation operation)Construct a storage, and specify the implementations of the element-wise operations.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description DenseDataadd(DenseData that)Add up the elements inthisandthat, element-by-element.double[]asArray()Cast this data structure as adouble[].DenseDatadeepCopy()The implementation returns an instance created fromthisby the copy constructor of the class, or justthisif the instance itself is immutable.booleanequals(Object obj)doubleget(int i, int j)Get the matrix entry at [i,j].inthashCode()DenseDataminus(DenseData that)Subtract the elements inthisbythat, element-by-element.intnCols()Gets the number of columns.protected abstract DenseDatanewInstance(double[] data, int nRows, int nCols, DoubleArrayOperation operation)intnRows()Gets the number of rows.protected abstract intposition(int nRows, int nCols, int i, int j)DenseDatascaled(double c)Multiply the elements inthisby a scalar, element-by-element.voidset(int i, int j, double value)Set the matrix entry at [i,j] to a value.
-
-
-
Field Detail
-
ZERO_ENTRY
public static final int ZERO_ENTRY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DenseData
public DenseData(double[] data, int nRows, int nCols, DoubleArrayOperation operation)Construct a storage, and specify the implementations of the element-wise operations.- Parameters:
data- the datanRows- the number of rowsnCols- the number of columnsoperation- the implementations of the element-wise operations
-
DenseData
public DenseData(double[] data, int nRows, int nCols)Construct a storage.- Parameters:
data- the datanRows- the number of rowsnCols- the number of columns
-
-
Method Detail
-
position
protected abstract int position(int nRows, int nCols, int i, int j)
-
newInstance
protected abstract DenseData newInstance(double[] data, int nRows, int nCols, DoubleArrayOperation operation)
-
set
public void set(int i, int j, double value) throws MatrixAccessExceptionDescription copied from interface:MatrixAccessSet the matrix entry at [i,j] to a value. This is the only method that may change a matrix.- Specified by:
setin interfaceMatrixAccess- Parameters:
i- the row indexj- the column indexvalue- the value to set A[i,j] to- Throws:
MatrixAccessException- if i or j is out of range
-
get
public double get(int i, int j) throws MatrixAccessExceptionDescription copied from interface:MatrixAccessGet the matrix entry at [i,j].- Specified by:
getin interfaceMatrixAccess- Parameters:
i- the row indexj- the column index- Returns:
- A[i,j]
- Throws:
MatrixAccessException- if i or j is out of range
-
nRows
public int nRows()
Description copied from interface:TableGets the number of rows. Rows count from 1.
-
nCols
public int nCols()
Description copied from interface:TableGets the number of columns. Columns count from 1.
-
deepCopy
public DenseData deepCopy()
Description copied from interface:DeepCopyableThe implementation returns an instance created fromthisby the copy constructor of the class, or justthisif the instance itself is immutable.- Specified by:
deepCopyin interfaceDeepCopyable- Returns:
- an independent (deep) copy of the instance
-
asArray
public double[] asArray()
Cast this data structure as adouble[]. Modifying the returned value modifies the internal data.- Returns:
- itself as a
double[]
-
add
public DenseData add(DenseData that)
Add up the elements inthisandthat, element-by-element.- Parameters:
that- an array of data- Returns:
- the sums of elements
-
minus
public DenseData minus(DenseData that)
Subtract the elements inthisbythat, element-by-element.- Parameters:
that- an array of data- Returns:
- the differences of elements
-
scaled
public DenseData scaled(double c)
Multiply the elements inthisby a scalar, element-by-element.- Parameters:
c- the scaling constant- Returns:
- the scaled elements
-
-