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 int
ZERO_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 DenseData
add(DenseData that)
Add up the elements inthis
andthat
, element-by-element.double[]
asArray()
Cast this data structure as adouble[]
.DenseData
deepCopy()
The implementation returns an instance created fromthis
by the copy constructor of the class, or justthis
if the instance itself is immutable.boolean
equals(Object obj)
double
get(int i, int j)
Get the matrix entry at [i,j].int
hashCode()
DenseData
minus(DenseData that)
Subtract the elements inthis
bythat
, element-by-element.int
nCols()
Gets the number of columns.protected abstract DenseData
newInstance(double[] data, int nRows, int nCols, DoubleArrayOperation operation)
int
nRows()
Gets the number of rows.protected abstract int
position(int nRows, int nCols, int i, int j)
DenseData
scaled(double c)
Multiply the elements inthis
by a scalar, element-by-element.void
set(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 MatrixAccessException
Description copied from interface:MatrixAccess
Set the matrix entry at [i,j] to a value. This is the only method that may change a matrix.- Specified by:
set
in 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 MatrixAccessException
Description copied from interface:MatrixAccess
Get the matrix entry at [i,j].- Specified by:
get
in 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:Table
Gets the number of rows. Rows count from 1.
-
nCols
public int nCols()
Description copied from interface:Table
Gets the number of columns. Columns count from 1.
-
deepCopy
public DenseData deepCopy()
Description copied from interface:DeepCopyable
The implementation returns an instance created fromthis
by the copy constructor of the class, or justthis
if the instance itself is immutable.- Specified by:
deepCopy
in 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 inthis
andthat
, element-by-element.- Parameters:
that
- an array of data- Returns:
- the sums of elements
-
minus
public DenseData minus(DenseData that)
Subtract the elements inthis
bythat
, element-by-element.- Parameters:
that
- an array of data- Returns:
- the differences of elements
-
scaled
public DenseData scaled(double c)
Multiply the elements inthis
by a scalar, element-by-element.- Parameters:
c
- the scaling constant- Returns:
- the scaled elements
-
-