public abstract class SparseMatrix extends Matrix
Modifier and Type | Field and Description |
---|---|
protected int |
cardinality |
Constructor and Description |
---|
SparseMatrix(int rows,
int columns) |
SparseMatrix(int rows,
int columns,
int cardinality) |
Modifier and Type | Method and Description |
---|---|
Matrix |
add(double value)
Adds given
value (v) to every element of this matrix (A). |
static SparseMatrix |
block(Matrix a,
Matrix b,
Matrix c,
Matrix d)
|
protected long |
capacity() |
int |
cardinality()
Returns the cardinality (the number of non-zero elements)
of this sparse matrix.
|
double |
density()
Returns the density (non-zero elements divided by total elements)
of this sparse matrix.
|
static SparseMatrix |
diagonal(int size,
double diagonal)
|
void |
eachNonZero(MatrixProcedure procedure)
Applies given
procedure to each non-zero element of this matrix. |
void |
eachNonZeroInColumn(int j,
VectorProcedure procedure)
Applies the given
procedure to each non-zero element of the specified column of this matrix. |
void |
eachNonZeroInRow(int i,
VectorProcedure procedure)
Applies the given
procedure to each non-zero element of the specified row of this matrix. |
protected void |
ensureCardinalityIsCorrect(long rows,
long columns,
long cardinality) |
double |
foldNonZero(MatrixAccumulator accumulator)
Folds non-zero elements of this matrix with given
accumulator . |
double |
foldNonZeroInColumn(int j,
VectorAccumulator accumulator)
Folds non-zero elements of the specified column in this matrix with the given
accumulator . |
double[] |
foldNonZeroInColumns(VectorAccumulator accumulator)
Folds non-zero elements (in a column-by-column manner) of this matrix with given
accumulator . |
double |
foldNonZeroInRow(int i,
VectorAccumulator accumulator)
Folds non-zero elements of the specified row in this matrix with the given
accumulator . |
double[] |
foldNonZeroInRows(VectorAccumulator accumulator)
Folds non-zero elements (in a row-by-row manner) of this matrix with given
accumulator . |
static SparseMatrix |
from1DArray(int rows,
int columns,
double[] array)
Creates a new
SparseMatrix from the given 1D array with
compressing (copying) the underlying array. |
static SparseMatrix |
from2DArray(double[][] array)
Creates a new
SparseMatrix from the given 2D array with
compressing (copying) the underlying array. |
static SparseMatrix |
fromCSV(String csv)
Parses
SparseMatrix from the given CSV string. |
static SparseMatrix |
fromMatrixMarket(String mm)
Parses
SparseMatrix from the given Matrix Market string. |
double |
get(int i,
int j)
Gets the specified element of this matrix.
|
Vector |
getColumn(int j)
Copies the specified column of this matrix into the vector.
|
abstract double |
getOrElse(int i,
int j,
double defaultValue)
Gets the specified element, or a
defaultValue if there
is no actual element at (i , j ) in this sparse matrix. |
Vector |
getRow(int i)
Copies the specified row of this matrix into the vector.
|
static SparseMatrix |
identity(int size)
Creates an identity
SparseMatrix of the given size . |
boolean |
isColumnMajor() |
abstract boolean |
isRowMajor()
Checks whether or not this sparse matrix row-major.
|
boolean |
isZeroAt(int i,
int j)
Whether or not the specified element is zero.
|
Matrix |
multiply(double value)
Scales this matrix by given
value (v). |
abstract boolean |
nonZeroAt(int i,
int j)
Whether or not the specified element is not zero.
|
ColumnMajorMatrixIterator |
nonZeroColumnMajorIterator()
Returns a non-zero column-major matrix iterator.
|
MatrixIterator |
nonZeroIterator()
Returns a non-zero matrix iterator.
|
VectorIterator |
nonZeroIteratorOfColumn(int j)
Returns a non-zero vector iterator of the given column
j . |
VectorIterator |
nonZeroIteratorOfRow(int i)
Returns a non-zero vector iterator of the given row
i . |
RowMajorMatrixIterator |
nonZeroRowMajorIterator()
Returns a non-zero row-major matrix iterator.
|
static SparseMatrix |
random(int rows,
int columns,
double density,
Random random)
|
static SparseMatrix |
randomSymmetric(int size,
double density,
Random random)
Creates a random symmetric
SparseMatrix of the given size . |
String |
toMatrixMarket(NumberFormat formatter)
Converts this matrix into the Matrix Market string using the
given number
formatter . |
static SparseMatrix |
zero(int rows,
int columns)
|
static SparseMatrix |
zero(int rows,
int columns,
int capacity)
|
add, apply, apply, apply, blank, blankOfColumns, blankOfRows, blankOfShape, columnMajorIterator, columns, constant, copy, copyOfColumns, copyOfRows, copyOfShape, determinant, diagonalProduct, divide, each, eachInColumn, eachInRow, ensureDimensionsAreCorrect, ensureIndexesAreInBounds, equals, equals, euclideanNorm, fail, fold, foldColumn, foldColumns, foldRow, foldRows, hadamardProduct, hashCode, infinityNorm, insert, insert, insert, insert, insertColumn, insertRow, is, is, iterator, iteratorOfColumn, iteratorOfRow, kroneckerProduct, manhattanNorm, max, maxInColumn, maxInRow, min, minInColumn, minInRow, mkString, mkString, mkString, multiply, multiply, multiplyByItsTranspose, non, non, norm, power, product, random, randomSymmetric, rank, removeColumn, removeFirstColumn, removeFirstRow, removeLastColumn, removeLastRow, removeRow, rotate, rowMajorIterator, rows, select, set, setAll, setColumn, setColumn, setRow, setRow, shuffle, slice, sliceBottomRight, sliceTopLeft, subtract, subtract, sum, swapColumns, swapRows, to, toBinary, toColumnMajorSparseMatrix, toColumnVector, toCSV, toCSV, toDenseMatrix, toMatrixMarket, toRowMajorSparseMatrix, toRowVector, toSparseMatrix, toString, trace, transform, transformColumn, transformRow, transpose, unit, update, updateAt, updateColumn, updateRow, withDecompositor, withInverter, withSolver
public SparseMatrix(int rows, int columns)
public SparseMatrix(int rows, int columns, int cardinality)
public static SparseMatrix zero(int rows, int columns)
public static SparseMatrix zero(int rows, int columns, int capacity)
public static SparseMatrix diagonal(int size, double diagonal)
public static SparseMatrix identity(int size)
SparseMatrix
of the given size
.public static SparseMatrix random(int rows, int columns, double density, Random random)
public static SparseMatrix randomSymmetric(int size, double density, Random random)
SparseMatrix
of the given size
.public static SparseMatrix from1DArray(int rows, int columns, double[] array)
SparseMatrix
from the given 1D array
with
compressing (copying) the underlying array.public static SparseMatrix from2DArray(double[][] array)
SparseMatrix
from the given 2D array
with
compressing (copying) the underlying array.public static SparseMatrix block(Matrix a, Matrix b, Matrix c, Matrix d)
public static SparseMatrix fromCSV(String csv)
SparseMatrix
from the given CSV string.csv
- the CSV string representing a matrixpublic static SparseMatrix fromMatrixMarket(String mm)
SparseMatrix
from the given Matrix Market string.mm
- the string in Matrix Market formatpublic double get(int i, int j)
Matrix
public abstract double getOrElse(int i, int j, double defaultValue)
defaultValue
if there
is no actual element at (i
, j
) in this sparse matrix.i
- the element's row indexj
- the element's column indexdefaultValue
- the default valuepublic abstract boolean isRowMajor()
public boolean isColumnMajor()
public int cardinality()
public double density()
protected long capacity()
public Vector getRow(int i)
Matrix
public Vector getColumn(int j)
Matrix
public Matrix multiply(double value)
Matrix
value
(v).public Matrix add(double value)
Matrix
value
(v) to every element of this matrix (A).public boolean isZeroAt(int i, int j)
i
- element's row indexj
- element's column indextrue
if specified element is zero, false
otherwisepublic abstract boolean nonZeroAt(int i, int j)
i
- element's row indexj
- element's column indextrue
if specified element is not zero, false
otherwisepublic void eachNonZero(MatrixProcedure procedure)
procedure
to each non-zero element of this matrix.procedure
- the matrix procedurepublic void eachNonZeroInRow(int i, VectorProcedure procedure)
procedure
to each non-zero element of the specified row of this matrix.i
- the row index.procedure
- the VectorProcedure
.public void eachNonZeroInColumn(int j, VectorProcedure procedure)
procedure
to each non-zero element of the specified column of this matrix.j
- the column index.procedure
- the VectorProcedure
.public double foldNonZero(MatrixAccumulator accumulator)
accumulator
.accumulator
- the matrix accumulatorpublic double foldNonZeroInRow(int i, VectorAccumulator accumulator)
accumulator
.i
- the row index.accumulator
- the VectorAccumulator
.public double foldNonZeroInColumn(int j, VectorAccumulator accumulator)
accumulator
.j
- the column index.accumulator
- the VectorAccumulator
.public double[] foldNonZeroInColumns(VectorAccumulator accumulator)
accumulator
.accumulator
- the matrix accumulatorpublic double[] foldNonZeroInRows(VectorAccumulator accumulator)
accumulator
.accumulator
- the matrix accumulatorpublic MatrixIterator nonZeroIterator()
public RowMajorMatrixIterator nonZeroRowMajorIterator()
public ColumnMajorMatrixIterator nonZeroColumnMajorIterator()
public VectorIterator nonZeroIteratorOfRow(int i)
i
.public VectorIterator nonZeroIteratorOfColumn(int j)
j
.public String toMatrixMarket(NumberFormat formatter)
Matrix
formatter
.toMatrixMarket
in class Matrix
protected void ensureCardinalityIsCorrect(long rows, long columns, long cardinality)
Copyright © 2015. All rights reserved.