public abstract class AbstractMatrix extends Object implements Matrix
Matrix
interface to minimize the effort required to implement it.
Subclasses may override some of the implemented methods if a more
specific or optimized implementation is desirable.Matrix.Element
Constructor and Description |
---|
AbstractMatrix() |
AbstractMatrix(MatrixStorage sto) |
Modifier and Type | Method and Description |
---|---|
Spliterator<Double> |
allSpliterator()
Gets spliterator for all values in this matrix.
|
Matrix |
assign(double val)
Assigns given value to all elements of this matrix.
|
Matrix |
assign(double[][] vals)
Assigns given values to this matrix.
|
Matrix |
assign(IntIntToDoubleFunction fun)
Assigns each matrix element to the value generated by given function.
|
Matrix |
assign(Matrix mtx)
Assigns values from given matrix to this matrix.
|
Matrix |
assignColumn(int col,
Vector vec)
Assigns values from given vector to the specified column in this matrix.
|
Matrix |
assignRow(int row,
Vector vec)
Assigns values from given vector to the specified row in this matrix.
|
int |
columnSize()
Gets number of columns in this matrix.
|
void |
compute(int row,
int col,
IgniteTriFunction<Integer,Integer,Double,Double> f)
Replace matrix entry with value oldVal at (row, col) with result of computing f(row, col, oldVal).
|
Matrix |
copy()
Clones this matrix.
|
boolean |
density(double threshold)
Calculates the density of the matrix based on supplied criteria.
|
void |
destroy()
Destroys object if managed outside of JVM.
|
double |
determinant()
Returns matrix determinant using Laplace theorem.
|
Matrix |
divide(double d)
Divides each value in this matrix by the argument.
|
boolean |
equals(Object o)
We ignore guid's for comparisons.
|
Vector |
foldColumns(IgniteFunction<Vector,Double> fun)
Collects the results of applying a given function to all columns in this matrix.
|
<T> T |
foldMap(IgniteBiFunction<T,Double,T> foldFun,
IgniteDoubleFunction<Double> mapFun,
T zeroVal)
Folds this matrix into a single value.
|
Vector |
foldRows(IgniteFunction<Vector,Double> fun)
Collects the results of applying a given function to all rows in this matrix.
|
double |
get(int row,
int col)
Gets the matrix value at the provided location.
|
Vector |
getCol(int col)
Get a specific row from matrix.
|
Matrix.Element |
getElement(int row,
int col)
Gets the matrix's element at the given coordinates.
|
Map<String,Object> |
getMetaStorage()
Implementation should return an instance of the map to store meta attributes.
|
Vector |
getRow(int row)
Get a specific row from matrix.
|
MatrixStorage |
getStorage()
Gets matrix storage model.
|
double |
getX(int row,
int col)
Gets the matrix value at the provided location without checking boundaries.
|
IgniteUuid |
guid()
Auto-generated globally unique matrix ID.
|
int |
hashCode() |
Matrix |
inverse()
Returns the inverse matrix of this matrix
|
boolean |
isArrayBased()
Checks if implementation is based on Java arrays.
|
boolean |
isDense()
Checks if this implementation should be considered dense so that it explicitly
represents every value.
|
boolean |
isDistributed()
Checks whether implementation is JVM-local or distributed (multi-JVM).
|
protected Matrix |
likeIdentity() |
Matrix |
map(IgniteDoubleFunction<Double> fun)
Maps all values in this matrix through a given function.
|
Matrix |
map(Matrix mtx,
IgniteBiFunction<Double,Double,Double> fun)
Maps all values in this matrix through a given function.
|
Matrix.Element |
maxElement()
Gets the maximum element in this matrix.
|
double |
maxValue()
Gets the maximum value in this matrix.
|
Matrix.Element |
minElement()
Gets the minimum element in this matrix.
|
Matrix |
minus(Matrix mtx)
Creates new matrix where each value is a difference between corresponding value of this matrix and
passed in argument matrix.
|
double |
minValue()
Gets the minimum value in this matrix.
|
int |
nonZeroElements()
Gets number of non-zero elements in this matrix.
|
Spliterator<Double> |
nonZeroSpliterator()
Gets spliterator for all non-zero values in this matrix.
|
Matrix |
plus(double x)
Creates new matrix where each value is a sum of the corresponding value of this matrix and
argument value.
|
Matrix |
plus(Matrix mtx)
Creates new matrix where each value is a sum of corresponding values of this matrix and
passed in argument matrix.
|
void |
readExternal(ObjectInput in) |
int |
rowSize()
Gets number of rows in this matrix.
|
Matrix |
set(int row,
int col,
double val)
Sets given value.
|
Matrix |
setColumn(int col,
double[] data)
Sets values for given column.
|
Matrix |
setRow(int row,
double[] data)
Sets values for given row.
|
protected void |
setStorage(MatrixStorage sto) |
Matrix |
setX(int row,
int col,
double val)
Sets given value without checking for index bounds.
|
protected double |
storageGet(int row,
int col) |
protected void |
storageSet(int row,
int col,
double v) |
double |
sum()
Gets sum of all elements in the matrix.
|
Matrix |
swapColumns(int col1,
int col2)
Swaps two columns in this matrix.
|
Matrix |
swapRows(int row1,
int row2)
Swaps two rows in this matrix.
|
Matrix |
times(double x)
Creates new matrix containing the product of given value and values in this matrix.
|
Matrix |
times(Matrix mtx)
Creates new matrix that is the product of multiplying this matrix and the argument matrix.
|
Vector |
times(Vector vec)
Creates new matrix that is the product of multiplying this matrix and the argument vector.
|
String |
toString() |
Matrix |
transpose()
Creates new matrix that is transpose of this matrix.
|
Vector |
viewColumn(int col)
Creates new view into matrix column .
|
Vector |
viewDiagonal()
Creates new view into matrix diagonal.
|
Vector |
viewRow(int row)
Creates new view into matrix row.
|
void |
writeExternal(ObjectOutput out) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
isNumeric, like, likeVector
getAttribute, hasAttribute, removeAttribute, setAttribute
public AbstractMatrix(MatrixStorage sto)
sto
- Backing MatrixStorage
.public AbstractMatrix()
protected void setStorage(MatrixStorage sto)
sto
- Backing MatrixStorage
.protected void storageSet(int row, int col, double v)
row
- Row index in the matrix.col
- Column index in the matrix.v
- Value to set.protected double storageGet(int row, int col)
row
- Row index in the matrix.col
- Column index in the matrix.public Matrix.Element maxElement()
maxElement
in interface Matrix
public Matrix.Element minElement()
minElement
in interface Matrix
public double maxValue()
public double minValue()
public Matrix.Element getElement(int row, int col)
getElement
in interface Matrix
row
- Row index.col
- Column index.public Matrix swapRows(int row1, int row2)
public Matrix swapColumns(int col1, int col2)
swapColumns
in interface Matrix
col1
- Column #1.col2
- Column #2.public MatrixStorage getStorage()
getStorage
in interface Matrix
public boolean isDense()
isDense
in interface StorageOpsMetrics
public boolean isDistributed()
isDistributed
in interface StorageOpsMetrics
public boolean isArrayBased()
isArrayBased
in interface StorageOpsMetrics
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public Map<String,Object> getMetaStorage()
getMetaStorage
in interface MetaAttributes
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
public Matrix assign(double val)
public Matrix assign(IntIntToDoubleFunction fun)
public Matrix assign(double[][] vals)
public Matrix map(IgniteDoubleFunction<Double> fun)
public Matrix map(Matrix mtx, IgniteBiFunction<Double,Double,Double> fun)
For this matrix A
, argument matrix B
and the
function F
this method maps every cell x, y
as:
A(x,y) = fun(A(x,y), B(x,y))
.
public Spliterator<Double> allSpliterator()
allSpliterator
in interface Matrix
public int nonZeroElements()
nonZeroElements
in interface Matrix
public Spliterator<Double> nonZeroSpliterator()
nonZeroSpliterator
in interface Matrix
public Matrix assignColumn(int col, Vector vec)
assignColumn
in interface Matrix
col
- Column index.vec
- Vector to get values from.public Matrix assignRow(int row, Vector vec)
public Vector foldRows(IgniteFunction<Vector,Double> fun)
public Vector foldColumns(IgniteFunction<Vector,Double> fun)
foldColumns
in interface Matrix
fun
- Aggregating function.public <T> T foldMap(IgniteBiFunction<T,Double,T> foldFun, IgniteDoubleFunction<Double> mapFun, T zeroVal)
foldMap
in interface Matrix
T
- Type of the folded value.foldFun
- Folding function that takes two parameters: accumulator and the current value.mapFun
- Mapping function that is called on each matrix cell before its passed to the accumulator (as its
second parameter).zeroVal
- Zero value for fold function.public int columnSize()
columnSize
in interface Matrix
public int rowSize()
public Matrix divide(double d)
public double get(int row, int col)
public double getX(int row, int col)
Matrix.get(int, int)
sibling.public Matrix minus(Matrix mtx)
public Matrix plus(double x)
public Matrix plus(Matrix mtx)
public IgniteUuid guid()
public Matrix set(int row, int col, double val)
public Matrix setRow(int row, double[] data)
public Vector getRow(int row)
public Matrix setColumn(int col, double[] data)
public Vector getCol(int col)
public Matrix setX(int row, int col, double val)
Matrix.set(int, int, double)
sibling.public Matrix times(double x)
public Vector times(Vector vec)
public Matrix times(Matrix mtx)
public double sum()
public Matrix transpose()
public boolean density(double threshold)
true
if this matrix is denser than threshold with at least 80% confidence.public Vector viewRow(int row)
public Vector viewColumn(int col)
viewColumn
in interface Matrix
col
- Column index.public Vector viewDiagonal()
viewDiagonal
in interface Matrix
public void destroy()
destroy
in interface Destroyable
destroy
in interface Matrix
public Matrix copy()
NOTE: new matrix will have the same flavor as the this matrix but a different ID.
public boolean equals(Object o)
public void compute(int row, int col, IgniteTriFunction<Integer,Integer,Double,Double> f)
public double determinant()
determinant
in interface Matrix
public Matrix inverse()
protected Matrix likeIdentity()
GridGain In-Memory Computing Platform : ver. 8.9.15 Release Date : December 3 2024