org.jscience.mathematics.algebraic.matrices
Class DoubleSparseMatrix

java.lang.Object
  extended by org.jscience.mathematics.algebraic.AbstractHypermatrix
      extended by org.jscience.mathematics.algebraic.AbstractMatrix
          extended by org.jscience.mathematics.algebraic.matrices.AbstractDoubleMatrix
              extended by org.jscience.mathematics.algebraic.matrices.DoubleSparseMatrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Algebra.Member, Ring.Member, AbelianGroup.Member, Hypermatrix, Matrix, Module.Member, VectorSpace.Member, Member

public class DoubleSparseMatrix
extends AbstractDoubleMatrix
implements java.lang.Cloneable, java.io.Serializable

The DoubleSparseMatrix class provides an object for encapsulating sparse matrices. Uses compressed row storage.

See Also:
Serialized Form

Constructor Summary
DoubleSparseMatrix(double[][] array)
          Constructs a matrix from an array.
DoubleSparseMatrix(DoubleSparseMatrix mat)
          Copy constructor.
DoubleSparseMatrix(int rowCount, int colCount)
          Constructs an empty matrix.
 
Method Summary
 AbstractDoubleMatrix add(AbstractDoubleMatrix m)
          Returns the addition of this matrix and another.
 DoubleMatrix add(DoubleMatrix m)
          DOCUMENT ME!
 DoubleSparseMatrix add(DoubleSparseMatrix m)
          Returns the addition of this matrix and another.
 java.lang.Object clone()
          Clone matrix into a new matrix.
 boolean equals(AbstractDoubleMatrix m, double tol)
          Compares two double sparse matrices for equality.
 boolean equals(DoubleSparseMatrix m)
          DOCUMENT ME!
 boolean equals(DoubleSparseMatrix m, double tol)
          DOCUMENT ME!
 double frobeniusNorm()
          Returns the Frobenius (l2) norm.
 double getPrimitiveElement(int i, int j)
          Returns an element of the matrix.
 double infNorm()
          Returns the linfinity-norm.
 AbstractDoubleMatrix mapElements(PrimitiveMapping f)
          Applies a function on all the matrix elements.
 AbstractDoubleMatrix multiply(AbstractDoubleMatrix m)
          Returns the multiplication of this matrix and another.
 AbstractDoubleVector multiply(AbstractDoubleVector v)
          Returns the multiplication of a vector by this matrix.
 AbstractDoubleMatrix multiply(DoubleMatrix m)
          DOCUMENT ME!
 AbstractDoubleMatrix multiply(DoubleSparseMatrix m)
          Returns the multiplication of this matrix and another.
 AbstractDoubleMatrix scalarDivide(double x)
          DOCUMENT ME!
 AbstractDoubleMatrix scalarMultiply(double x)
          Returns the multiplication of this matrix by a scalar.
 double scalarProduct(AbstractDoubleMatrix m)
          Returns the scalar product of this matrix and another.
 double scalarProduct(DoubleMatrix m)
          DOCUMENT ME!
 void setAllElements(double x)
          Sets the value of all elements of the matrix.
 void setElement(int i, int j, double x)
          Sets the value of an element of the matrix.
 AbstractDoubleMatrix subtract(AbstractDoubleMatrix m)
          Returns the subtraction of this matrix and another.
 DoubleMatrix subtract(DoubleMatrix m)
          DOCUMENT ME!
 DoubleSparseMatrix subtract(DoubleSparseMatrix m)
          Returns the addition of this matrix and another.
 AbstractComplexMatrix toComplexMatrix()
          Converts this matrix to a complex matrix.
 AbstractIntegerMatrix toIntegerMatrix()
          Converts this matrix to an integer matrix.
 double[][] toPrimitiveArray()
          Projects the matrix to an array.
 java.lang.String toString()
          Returns a string representing this matrix.
 Matrix transpose()
          Returns the transpose of this matrix.
 
Methods inherited from class org.jscience.mathematics.algebraic.matrices.AbstractDoubleMatrix
abs, add, directSum, equals, equals, getColumn, getElement, getMatrixAsColumns, getMatrixAsRows, getRow, getSet, getSubMatrix, hashCode, horizontalAxisSymmetry, mass, max, mean, min, multiply, negate, read, reverse, scalarDivide, scalarMultiply, setColumn, setRow, setSubMatrix, subtract, tensorProduct, verticalAxisSymmetry
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractMatrix
getElement, getInvalidElementMsg, numColumns, numRows, print, print, print, print, toArray, toArray
 
Methods inherited from class org.jscience.mathematics.algebraic.AbstractHypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.mathematics.algebraic.Hypermatrix
getDimensions, numDimensions, numElements, numElements, toArray
 

Constructor Detail

DoubleSparseMatrix

public DoubleSparseMatrix(int rowCount,
                          int colCount)
Constructs an empty matrix.

Parameters:
rowCount - the number of rows
colCount - the number of columns

DoubleSparseMatrix

public DoubleSparseMatrix(double[][] array)
Constructs a matrix from an array.

Parameters:
array - an assigned value

DoubleSparseMatrix

public DoubleSparseMatrix(DoubleSparseMatrix mat)
Copy constructor.

Parameters:
mat - an assigned value
Method Detail

equals

public boolean equals(AbstractDoubleMatrix m,
                      double tol)
Compares two double sparse matrices for equality.

Overrides:
equals in class AbstractDoubleMatrix
Parameters:
m - a double matrix
tol - DOCUMENT ME!
Returns:
DOCUMENT ME!

equals

public boolean equals(DoubleSparseMatrix m)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

equals

public boolean equals(DoubleSparseMatrix m,
                      double tol)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
tol - DOCUMENT ME!
Returns:
DOCUMENT ME!

toString

public java.lang.String toString()
Returns a string representing this matrix.

Overrides:
toString in class AbstractDoubleMatrix
Returns:
DOCUMENT ME!

toIntegerMatrix

public AbstractIntegerMatrix toIntegerMatrix()
Converts this matrix to an integer matrix.

Overrides:
toIntegerMatrix in class AbstractDoubleMatrix
Returns:
an integer matrix

toComplexMatrix

public AbstractComplexMatrix toComplexMatrix()
Converts this matrix to a complex matrix.

Overrides:
toComplexMatrix in class AbstractDoubleMatrix
Returns:
a complex matrix

getPrimitiveElement

public double getPrimitiveElement(int i,
                                  int j)
Returns an element of the matrix.

Specified by:
getPrimitiveElement in class AbstractDoubleMatrix
Parameters:
i - row index of the element
j - column index of the element
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - 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:
setElement in class AbstractDoubleMatrix
Parameters:
i - row index of the element
j - column index of the element
x - a number
Throws:
IllegalDimensionException - If attempting to access an invalid element.

setAllElements

public void setAllElements(double x)
Sets the value of all elements of the matrix. You should think about using a DoubleSquareMatrix.

Overrides:
setAllElements in class AbstractDoubleMatrix
Parameters:
x - a double element

infNorm

public double infNorm()
Returns the linfinity-norm.

Overrides:
infNorm in class AbstractDoubleMatrix
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

frobeniusNorm

public double frobeniusNorm()
Returns the Frobenius (l2) norm.

Overrides:
frobeniusNorm in class AbstractDoubleMatrix
Returns:
DOCUMENT ME!
Throws:
java.lang.ArithmeticException - DOCUMENT ME!

add

public AbstractDoubleMatrix add(AbstractDoubleMatrix m)
Returns the addition of this matrix and another.

Overrides:
add in class AbstractDoubleMatrix
Parameters:
m - a double matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are different sizes.

add

public DoubleMatrix add(DoubleMatrix m)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

add

public DoubleSparseMatrix add(DoubleSparseMatrix m)
Returns the addition of this matrix and another.

Parameters:
m - a double sparse matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are different sizes.

subtract

public AbstractDoubleMatrix subtract(AbstractDoubleMatrix m)
Returns the subtraction of this matrix and another.

Overrides:
subtract in class AbstractDoubleMatrix
Parameters:
m - a double matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are different sizes.

subtract

public DoubleMatrix subtract(DoubleMatrix m)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

subtract

public DoubleSparseMatrix subtract(DoubleSparseMatrix m)
Returns the addition of this matrix and another.

Parameters:
m - a double sparse matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are different sizes.

scalarMultiply

public AbstractDoubleMatrix scalarMultiply(double x)
Returns the multiplication of this matrix by a scalar.

Overrides:
scalarMultiply in class AbstractDoubleMatrix
Parameters:
x - a double
Returns:
a double sparse matrix

scalarDivide

public AbstractDoubleMatrix scalarDivide(double x)
DOCUMENT ME!

Overrides:
scalarDivide in class AbstractDoubleMatrix
Parameters:
x - DOCUMENT ME!
Returns:
DOCUMENT ME!

scalarProduct

public double scalarProduct(AbstractDoubleMatrix m)
Returns the scalar product of this matrix and another.

Overrides:
scalarProduct in class AbstractDoubleMatrix
Parameters:
m - a double matrix.
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are different sizes.

scalarProduct

public double scalarProduct(DoubleMatrix m)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

multiply

public AbstractDoubleVector multiply(AbstractDoubleVector v)
Returns the multiplication of a vector by this matrix.

Overrides:
multiply in class AbstractDoubleMatrix
Parameters:
v - a double vector
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrix and vector are incompatible.

multiply

public AbstractDoubleMatrix multiply(AbstractDoubleMatrix m)
Returns the multiplication of this matrix and another.

Overrides:
multiply in class AbstractDoubleMatrix
Parameters:
m - a double matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are incompatible.

multiply

public AbstractDoubleMatrix multiply(DoubleMatrix m)
DOCUMENT ME!

Parameters:
m - DOCUMENT ME!
Returns:
DOCUMENT ME!

multiply

public AbstractDoubleMatrix multiply(DoubleSparseMatrix m)
Returns the multiplication of this matrix and another.

Parameters:
m - a double sparse matrix
Returns:
DOCUMENT ME!
Throws:
IllegalDimensionException - If the matrices are incompatible.

transpose

public Matrix transpose()
Returns the transpose of this matrix.

Specified by:
transpose in interface Matrix
Overrides:
transpose in class AbstractDoubleMatrix
Returns:
a double sparse matrix

mapElements

public AbstractDoubleMatrix mapElements(PrimitiveMapping f)
Applies a function on all the matrix elements.

Overrides:
mapElements in class AbstractDoubleMatrix
Parameters:
f - a user-defined function
Returns:
a double sparse matrix

clone

public java.lang.Object clone()
Clone matrix into a new matrix.

Overrides:
clone in class java.lang.Object
Returns:
the cloned matrix.

toPrimitiveArray

public double[][] toPrimitiveArray()
Projects the matrix to an array.

Overrides:
toPrimitiveArray in class AbstractDoubleMatrix
Returns:
an double array.