public class DenseSparseMatrix extends Object implements Matrix
Backed by an array of SparseVector
.
Constructor and Description |
---|
DenseSparseMatrix(DenseSparseMatrix other) |
DenseSparseMatrix(List<SparseVector> values) |
Modifier and Type | Method and Description |
---|---|
void |
add(int i,
int j,
double value)
Adds the argument value to the value at the supplied index.
|
static DenseSparseMatrix |
createFromSparseVectors(SparseVector[] values)
Defensively copies the values.
|
boolean |
equals(Object other) |
void |
foreachInPlace(DoubleUnaryOperator f)
Applies a
DoubleUnaryOperator elementwise to this Tensor . |
double |
get(int i,
int j)
Gets an element from this
Matrix . |
int |
getDimension1Size()
The size of the first dimension.
|
int |
getDimension2Size()
The size of the second dimension.
|
SparseVector |
getRow(int i)
Extract a row as an
SGDVector . |
int[] |
getShape()
Returns an int array specifying the shape of this
Tensor . |
void |
hadamardProductInPlace(Tensor other,
DoubleUnaryOperator f)
Only implemented for
DenseMatrix . |
int |
hashCode() |
void |
intersectAndAddInPlace(Tensor other,
DoubleUnaryOperator f)
Only implemented for
DenseMatrix . |
MatrixIterator |
iterator() |
DenseVector |
leftMultiply(SGDVector input)
Multiplies this Matrix by a
SGDVector returning a vector of the appropriate size. |
DenseMatrix |
matrixMultiply(Matrix other)
Multiplies this Matrix by another
Matrix returning a matrix of the appropriate size. |
DenseMatrix |
matrixMultiply(Matrix other,
boolean transposeThis,
boolean transposeOther)
Multiplies this Matrix by another
Matrix returning a matrix of the appropriate size. |
int |
numActiveElements(int row)
The number of non-zero elements in that row.
|
Tensor |
reshape(int[] newShape)
Reshapes the Tensor to the supplied shape.
|
DenseVector |
rightMultiply(SGDVector input)
rightMultiply is very inefficient on DenseSparseMatrix due to the storage format.
|
void |
rowScaleInPlace(DenseVector scalingCoefficients)
Scales each row by the appropriate value in the
DenseVector . |
DenseVector |
rowSum()
Generates a
DenseVector representing the sum of each row. |
void |
set(int i,
int j,
double value)
Sets an element at the supplied location.
|
String |
toString() |
double |
twoNorm()
Calculates the euclidean norm for this vector.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
hadamardProductInPlace, intersectAndAddInPlace, scalarAddInPlace, scaleInPlace, shapeCheck, shapeSum
forEach, spliterator
public DenseSparseMatrix(List<SparseVector> values)
public DenseSparseMatrix(DenseSparseMatrix other)
public static DenseSparseMatrix createFromSparseVectors(SparseVector[] values)
values
- The sparse vectors to use.public int[] getShape()
Tensor
Tensor
.public Tensor reshape(int[] newShape)
Tensor
IllegalArgumentException
if the shape isn't compatible.public double get(int i, int j)
Matrix
Matrix
.public void set(int i, int j, double value)
Matrix
public int getDimension1Size()
Matrix
getDimension1Size
in interface Matrix
public int getDimension2Size()
Matrix
getDimension2Size
in interface Matrix
public DenseVector leftMultiply(SGDVector input)
Matrix
SGDVector
returning a vector of the appropriate size.
The input must have dimension equal to Matrix.getDimension2Size()
.
leftMultiply
in interface Matrix
input
- The input vector.SGDVector
of size Matrix.getDimension1Size()
.public DenseVector rightMultiply(SGDVector input)
rightMultiply
in interface Matrix
input
- The input vector.public void add(int i, int j, double value)
Matrix
public void intersectAndAddInPlace(Tensor other, DoubleUnaryOperator f)
DenseMatrix
.intersectAndAddInPlace
in interface Tensor
other
- The other Tensor
.f
- A function to apply.public void hadamardProductInPlace(Tensor other, DoubleUnaryOperator f)
DenseMatrix
.hadamardProductInPlace
in interface Tensor
other
- The other Tensor
.f
- A function to apply.public void foreachInPlace(DoubleUnaryOperator f)
Tensor
DoubleUnaryOperator
elementwise to this Tensor
.foreachInPlace
in interface Tensor
f
- The function to apply.public int numActiveElements(int row)
Matrix
An element could be active and zero, if it was active on construction.
numActiveElements
in interface Matrix
row
- The index of the row.public SparseVector getRow(int i)
Matrix
SGDVector
.
This refers to the same values as the matrix, so updating this vector will update the matrix.
public double twoNorm()
Tensor
public DenseMatrix matrixMultiply(Matrix other)
Matrix
Matrix
returning a matrix of the appropriate size.
The input must have dimension 1 equal to Matrix.getDimension2Size()
.
matrixMultiply
in interface Matrix
other
- The input matrix.Matrix
of size Matrix.getDimension1Size()
, input.getDimension2Size()
.public DenseMatrix matrixMultiply(Matrix other, boolean transposeThis, boolean transposeOther)
Matrix
Matrix
returning a matrix of the appropriate size.
Must obey the rules of matrix multiplication after the transposes are applied.
matrixMultiply
in interface Matrix
other
- The input matrix.transposeThis
- Implicitly transposes this matrix just for the multiplication.transposeOther
- Implicitly transposes other just for the multiplication.Matrix
.public DenseVector rowSum()
Matrix
DenseVector
representing the sum of each row.rowSum
in interface Matrix
DenseVector
of size Matrix.getDimension1Size()
.public void rowScaleInPlace(DenseVector scalingCoefficients)
Matrix
DenseVector
.rowScaleInPlace
in interface Matrix
scalingCoefficients
- A DenseVector
with size Matrix.getDimension1Size()
.public MatrixIterator iterator()
iterator
in interface Iterable<MatrixTuple>
Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.