public abstract class DenseData extends Object implements MatrixAccess, DeepCopyable
double[]
is faster than that for a double[][]
.
Hence for most operations, e.g., element-by-element add, minus, this implementation has a better
performance.Modifier and Type | Field and Description |
---|---|
static int |
ZERO_ENTRY |
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
DenseData |
add(DenseData that)
Add up the elements in
this and that , element-by-element. |
double[] |
asArray()
Cast this data structure as a
double[] . |
DenseData |
deepCopy()
The implementation returns an instance created from
this by the copy
constructor of the class, or just this 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 in
this by that , 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 in
this by a scalar, element-by-element. |
void |
set(int i,
int j,
double value)
Set the matrix entry at [i,j] to a value.
|
public static final int ZERO_ENTRY
public DenseData(double[] data, int nRows, int nCols, DoubleArrayOperation operation)
data
- the datanRows
- the number of rowsnCols
- the number of columnsoperation
- the implementations of the element-wise operationspublic DenseData(double[] data, int nRows, int nCols)
data
- the datanRows
- the number of rowsnCols
- the number of columnsprotected abstract int position(int nRows, int nCols, int i, int j)
protected abstract DenseData newInstance(double[] data, int nRows, int nCols, DoubleArrayOperation operation)
public void set(int i, int j, double value) throws MatrixAccessException
MatrixAccess
set
in interface MatrixAccess
i
- the row indexj
- the column indexvalue
- the value to set A[i,j] toMatrixAccessException
- if i or j is out of rangepublic double get(int i, int j) throws MatrixAccessException
MatrixAccess
get
in interface MatrixAccess
i
- the row indexj
- the column indexMatrixAccessException
- if i or j is out of rangepublic int nRows()
Table
public int nCols()
Table
public DenseData deepCopy()
DeepCopyable
this
by the copy
constructor of the class, or just this
if the instance itself is
immutable.deepCopy
in interface DeepCopyable
public double[] asArray()
double[]
.
Modifying the returned value modifies the internal data.double[]
public DenseData add(DenseData that)
this
and that
, element-by-element.that
- an array of datapublic DenseData minus(DenseData that)
this
by that
, element-by-element.that
- an array of datapublic DenseData scaled(double c)
this
by a scalar, element-by-element.c
- the scaling constantCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.