jsci.maths.matrices
Class DoubleSparseMatrix
- java.lang.Object
-
- jsci.maths.matrices.Matrix
-
- jsci.maths.matrices.AbstractDoubleMatrix
-
- jsci.maths.matrices.DoubleSparseMatrix
-
- All Implemented Interfaces:
- java.io.Serializable, Algebra.Member, Module.Member, VectorSpace.Member, Ring.Member, AbelianGroup.Member, Member
public final class DoubleSparseMatrix extends AbstractDoubleMatrix
The DoubleSparseMatrix class provides an object for encapsulating sparse matrices. Uses compressed row storage.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DoubleSparseMatrix(double[][] array)Constructs a matrix from an array.DoubleSparseMatrix(int rowCount, int colCount)Constructs an empty matrix.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description AbstractDoubleMatrixadd(AbstractDoubleMatrix m)Returns the addition of this matrix and another.DoubleMatrixadd(DoubleMatrix m)DoubleSparseMatrixadd(DoubleSparseMatrix m)Returns the addition of this matrix and another.booleanequals(AbstractDoubleMatrix m, double tol)Compares two double sparse matrices for equality.booleanequals(DoubleSparseMatrix m)booleanequals(DoubleSparseMatrix m, double tol)doublefrobeniusNorm()Returns the Frobenius (l2) norm.doublegetElement(int i, int j)Returns an element of the matrix.doubleinfNorm()Returns the l
-norm.AbstractDoubleMatrixmapElements(Mapping f)Applies a function on all the matrix elements.AbstractDoubleMatrixmultiply(AbstractDoubleMatrix m)Returns the multiplication of this matrix and another.AbstractDoubleVectormultiply(AbstractDoubleVector v)Returns the multiplication of a vector by this matrix.AbstractDoubleMatrixmultiply(DoubleMatrix m)AbstractDoubleMatrixmultiply(DoubleSparseMatrix m)Returns the multiplication of this matrix and another.AbstractDoubleMatrixscalarDivide(double x)Returns the division of this matrix by a scalar.AbstractDoubleMatrixscalarMultiply(double x)Returns the multiplication of this matrix by a scalar.doublescalarProduct(AbstractDoubleMatrix m)Returns the scalar product of this matrix and another.doublescalarProduct(DoubleMatrix m)voidsetElement(int i, int j, double x)Sets the value of an element of the matrix.AbstractDoubleMatrixsubtract(AbstractDoubleMatrix m)Returns the subtraction of this matrix and another.DoubleMatrixsubtract(DoubleMatrix m)DoubleSparseMatrixsubtract(DoubleSparseMatrix m)Returns the addition of this matrix and another.AbstractComplexMatrixtoComplexMatrix()Converts this matrix to a complex matrix.AbstractIntegerMatrixtoIntegerMatrix()Converts this matrix to an integer matrix.java.lang.StringtoString()Returns a string representing this matrix.Matrixtranspose()Returns the transpose of this matrix.-
Methods inherited from class jsci.maths.matrices.AbstractDoubleMatrix
add, directSum, equals, equals, getSet, hashCode, multiply, negate, scalarDivide, scalarMultiply, subtract, tensor
-
-
-
-
Constructor Detail
-
DoubleSparseMatrix
public DoubleSparseMatrix(int rowCount, int colCount)Constructs an empty matrix.- Parameters:
rowCount- the number of rowscolCount- the number of columns
-
DoubleSparseMatrix
public DoubleSparseMatrix(double[][] array)
Constructs a matrix from an array.- Parameters:
array- an assigned value
-
-
Method Detail
-
equals
public boolean equals(AbstractDoubleMatrix m, double tol)
Compares two double sparse matrices for equality.- Overrides:
equalsin classAbstractDoubleMatrix- Parameters:
m- a double matrix
-
equals
public final boolean equals(DoubleSparseMatrix m)
-
equals
public boolean equals(DoubleSparseMatrix m, double tol)
-
toString
public java.lang.String toString()
Returns a string representing this matrix.- Overrides:
toStringin classAbstractDoubleMatrix
-
toIntegerMatrix
public AbstractIntegerMatrix toIntegerMatrix()
Converts this matrix to an integer matrix.- Overrides:
toIntegerMatrixin classAbstractDoubleMatrix- Returns:
- an integer matrix
-
toComplexMatrix
public AbstractComplexMatrix toComplexMatrix()
Converts this matrix to a complex matrix.- Overrides:
toComplexMatrixin classAbstractDoubleMatrix- Returns:
- a complex matrix
-
getElement
public double getElement(int i, int j)Returns an element of the matrix.- Specified by:
getElementin classAbstractDoubleMatrix- Parameters:
i- row index of the elementj- column index of the element- Throws:
MatrixDimensionException- If attempting to access an invalid element.
-
setElement
public void setElement(int i, int j, double x)Sets the value of an element of the matrix.- Specified by:
setElementin classAbstractDoubleMatrix- Parameters:
i- row index of the elementj- column index of the elementx- a number- Throws:
MatrixDimensionException- If attempting to access an invalid element.
-
infNorm
public double infNorm()
Returns the l
-norm.- Overrides:
infNormin classAbstractDoubleMatrix
-
frobeniusNorm
public double frobeniusNorm()
Returns the Frobenius (l2) norm.- Overrides:
frobeniusNormin classAbstractDoubleMatrix
-
add
public AbstractDoubleMatrix add(AbstractDoubleMatrix m)
Returns the addition of this matrix and another.- Overrides:
addin classAbstractDoubleMatrix- Parameters:
m- a double matrix- Throws:
MatrixDimensionException- If the matrices are different sizes.
-
add
public DoubleMatrix add(DoubleMatrix m)
-
add
public DoubleSparseMatrix add(DoubleSparseMatrix m)
Returns the addition of this matrix and another.- Parameters:
m- a double sparse matrix- Throws:
MatrixDimensionException- If the matrices are different sizes.
-
subtract
public AbstractDoubleMatrix subtract(AbstractDoubleMatrix m)
Returns the subtraction of this matrix and another.- Overrides:
subtractin classAbstractDoubleMatrix- Parameters:
m- a double matrix- Throws:
MatrixDimensionException- If the matrices are different sizes.
-
subtract
public DoubleMatrix subtract(DoubleMatrix m)
-
subtract
public DoubleSparseMatrix subtract(DoubleSparseMatrix m)
Returns the addition of this matrix and another.- Parameters:
m- a double sparse matrix- Throws:
MatrixDimensionException- If the matrices are different sizes.
-
scalarMultiply
public AbstractDoubleMatrix scalarMultiply(double x)
Returns the multiplication of this matrix by a scalar.- Overrides:
scalarMultiplyin classAbstractDoubleMatrix- Parameters:
x- a double- Returns:
- a double sparse matrix
-
scalarDivide
public AbstractDoubleMatrix scalarDivide(double x)
Description copied from class:AbstractDoubleMatrixReturns the division of this matrix by a scalar.- Overrides:
scalarDividein classAbstractDoubleMatrix- Parameters:
x- a double.- Returns:
- a double matrix.
-
scalarProduct
public double scalarProduct(AbstractDoubleMatrix m)
Returns the scalar product of this matrix and another.- Overrides:
scalarProductin classAbstractDoubleMatrix- Parameters:
m- a double matrix.- Throws:
MatrixDimensionException- If the matrices are different sizes.
-
scalarProduct
public double scalarProduct(DoubleMatrix m)
-
multiply
public AbstractDoubleVector multiply(AbstractDoubleVector v)
Returns the multiplication of a vector by this matrix.- Overrides:
multiplyin classAbstractDoubleMatrix- Parameters:
v- a double vector- Throws:
DimensionException- If the matrix and vector are incompatible.
-
multiply
public AbstractDoubleMatrix multiply(AbstractDoubleMatrix m)
Returns the multiplication of this matrix and another.- Overrides:
multiplyin classAbstractDoubleMatrix- Parameters:
m- a double matrix- Returns:
- a AbstractDoubleMatrix or a AbstractDoubleSquareMatrix as appropriate
- Throws:
MatrixDimensionException- If the matrices are incompatible.
-
multiply
public AbstractDoubleMatrix multiply(DoubleMatrix m)
-
multiply
public AbstractDoubleMatrix multiply(DoubleSparseMatrix m)
Returns the multiplication of this matrix and another.- Parameters:
m- a double sparse matrix- Throws:
MatrixDimensionException- If the matrices are incompatible.
-
transpose
public Matrix transpose()
Returns the transpose of this matrix.- Overrides:
transposein classAbstractDoubleMatrix- Returns:
- a double sparse matrix
-
mapElements
public AbstractDoubleMatrix mapElements(Mapping f)
Applies a function on all the matrix elements.- Overrides:
mapElementsin classAbstractDoubleMatrix- Parameters:
f- a user-defined function- Returns:
- a double sparse matrix
-
-
DMelt 3.0 © DataMelt by jWork.ORG