|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.DenseData
public abstract class DenseData
This class provides an implementation of a dense matrix.
It stores the data of a 2D matrix as a 1D array for performance reason. In general computing index for a double[][] array is slower than that for a double[] array. Hence for most operations, e.g., element-by-element add, minus, this implementation will be faster.
To loop over the matrix element by rows, here is a code snippet.
for (int row = 0; row < this.dataImpl.length; row += nCols()) {//loop over rows
for (int col = 0; col < nCols(); col += 1) {//loop over cols
int index = row + col;//A[row][col] = A[index]
//do something useful
}
}
This class implements some common element-by-element operations so that its subclass implementation of a dense matrix can reuse these pieces of code.
For Java, an initialized data array (1D or 2D) seems to have all entries 0. We use this "assumption" to save an Arrays.fill.
| Field Summary | |
|---|---|
protected double[] |
data
stores the values of matrix entries |
| Constructor Summary | |
|---|---|
DenseData(double[] data)
|
|
DenseData(double[] data,
DoubleArrayOperation doubleArrayOperation)
|
|
DenseData(int length)
|
|
| Method Summary | |
|---|---|
double[] |
add(DenseData that)
Add up the elements in this and that, element-by-element. |
boolean |
equals(java.lang.Object obj)
Check if two DenseData are equal. |
int |
hashCode()
|
double[] |
minus(DenseData that)
Subtract the elements in this by that, element-by-element. |
double[] |
scaled(double scalar)
Multiply the elements in this by a scalar, element-by-element. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixData |
|---|
get, set |
| Methods inherited from interface com.numericalmethod.suanshu.DeepCopyable |
|---|
deepCopy |
| Field Detail |
|---|
protected double[] data
| Constructor Detail |
|---|
public DenseData(double[] data,
DoubleArrayOperation doubleArrayOperation)
public DenseData(double[] data)
public DenseData(int length)
| Method Detail |
|---|
public double[] add(DenseData that)
that - a DenseData
this.data and that.datapublic double[] minus(DenseData that)
that - a DenseData
this.data and that.datapublic double[] scaled(double scalar)
scalar - the constant to multiply with
scalarpublic boolean equals(java.lang.Object obj)
DoubleUtils.equal is used in place of Arrays.equal
because we need to compare doubles.
equals in class java.lang.Objecttrue iff two DenseData have the same values, element-by-elementpublic int hashCode()
hashCode in class java.lang.Object
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||