no.uib.cipr.matrix.sparse
Class LinkedSparseMatrix

java.lang.Object
  extended by no.uib.cipr.matrix.AbstractMatrix
      extended by no.uib.cipr.matrix.sparse.LinkedSparseMatrix
All Implemented Interfaces:
Iterable<MatrixEntry>, Matrix

public class LinkedSparseMatrix
extends AbstractMatrix

A Linked List (with shortcuts to important nodes) implementation of an n x m Matrix with z elements that has a typical O(z / m) insertion / lookup cost and an iterator that traverses columns then rows: a good fit for unstructured sparse matrices. A secondary link maintains fast transpose iteration.

However, memory requirements ( 1 instance (8 bytes), 2 int (16 bytes), 2 ref (16 bytes), 1 double (8 bytes) = 48 bytes per matrix element, plus 8 x numcol + 8 x numrow bytess for the cache) are slightly higher than structured sparse matrix storage. Note that on 32 bit JVMs, or on 64 bit JVMs with CompressedOops enabled, references and ints only cost 4 bytes each, bringing the cost to 28 bytes per element.

Author:
Sam Halliday

Nested Class Summary
 
Nested classes/interfaces inherited from interface no.uib.cipr.matrix.Matrix
Matrix.Norm
 
Field Summary
 
Fields inherited from class no.uib.cipr.matrix.AbstractMatrix
numColumns, numRows
 
Constructor Summary
LinkedSparseMatrix(int numRows, int numColumns)
           
LinkedSparseMatrix(Matrix A)
           
LinkedSparseMatrix(MatrixVectorReader r)
           
 
Method Summary
 Matrix copy()
          Creates a deep copy of the matrix
 double get(int row, int column)
          Returns A(row,column)
 Iterator<MatrixEntry> iterator()
           
 Matrix multAdd(double alpha, Matrix B, Matrix C)
          C = alpha*A*B + C
 Vector multAdd(double alpha, Vector x, Vector y)
          y = alpha*A*x + y
 Matrix scale(double alpha)
          A = alpha*A
 void set(int row, int column, double value)
          A(row,column) = value
 Matrix transABmultAdd(double alpha, Matrix B, Matrix C)
          C = alpha*AT*BT + C
 Matrix transAmultAdd(double alpha, Matrix B, Matrix C)
          C = alpha*AT*B + C
 Matrix transBmultAdd(double alpha, Matrix B, Matrix C)
          C = alpha*A*BT + C
 Vector transMultAdd(double alpha, Vector x, Vector y)
          y = alpha*AT*x + y
 Matrix transpose()
          Transposes the matrix in-place.
 Matrix zero()
          Zeros all the entries in the matrix, while preserving any underlying structure.
 
Methods inherited from class no.uib.cipr.matrix.AbstractMatrix
add, add, add, check, checkMultAdd, checkMultAdd, checkRank1, checkRank1, checkRank2, checkRank2, checkSize, checkSolve, checkSolve, checkTransABmultAdd, checkTransAmultAdd, checkTransBmultAdd, checkTransMultAdd, checkTranspose, checkTranspose, checkTransRank1, checkTransRank2, isSquare, max, max, mult, mult, mult, mult, multAdd, multAdd, norm, norm1, normF, normInf, numColumns, numRows, rank1, rank1, rank1, rank1, rank1, rank1, rank2, rank2, rank2, rank2, set, set, solve, solve, toString, transABmult, transABmult, transABmultAdd, transAmult, transAmult, transAmultAdd, transBmult, transBmult, transBmultAdd, transMult, transMult, transMultAdd, transpose, transRank1, transRank1, transRank2, transRank2, transSolve, transSolve
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LinkedSparseMatrix

public LinkedSparseMatrix(int numRows,
                          int numColumns)

LinkedSparseMatrix

public LinkedSparseMatrix(Matrix A)

LinkedSparseMatrix

public LinkedSparseMatrix(MatrixVectorReader r)
                   throws IOException
Throws:
IOException
Method Detail

zero

public Matrix zero()
Description copied from interface: Matrix
Zeros all the entries in the matrix, while preserving any underlying structure. Useful for general, unstructured matrices.

Specified by:
zero in interface Matrix
Overrides:
zero in class AbstractMatrix
Returns:
A

get

public double get(int row,
                  int column)
Description copied from interface: Matrix
Returns A(row,column)

Specified by:
get in interface Matrix
Overrides:
get in class AbstractMatrix

set

public void set(int row,
                int column,
                double value)
Description copied from interface: Matrix
A(row,column) = value

Specified by:
set in interface Matrix
Overrides:
set in class AbstractMatrix

iterator

public Iterator<MatrixEntry> iterator()
Specified by:
iterator in interface Iterable<MatrixEntry>
Overrides:
iterator in class AbstractMatrix

scale

public Matrix scale(double alpha)
Description copied from interface: Matrix
A = alpha*A

Specified by:
scale in interface Matrix
Overrides:
scale in class AbstractMatrix
Returns:
A

copy

public Matrix copy()
Description copied from interface: Matrix
Creates a deep copy of the matrix

Specified by:
copy in interface Matrix
Overrides:
copy in class AbstractMatrix
Returns:
A

transpose

public Matrix transpose()
Description copied from interface: Matrix
Transposes the matrix in-place. In most cases, the matrix must be square for this to work.

Specified by:
transpose in interface Matrix
Overrides:
transpose in class AbstractMatrix
Returns:
This matrix

multAdd

public Vector multAdd(double alpha,
                      Vector x,
                      Vector y)
Description copied from interface: Matrix
y = alpha*A*x + y

Specified by:
multAdd in interface Matrix
Overrides:
multAdd in class AbstractMatrix
x - Vector of size A.numColumns()
y - Vector of size A.numRows()
Returns:
y

transMultAdd

public Vector transMultAdd(double alpha,
                           Vector x,
                           Vector y)
Description copied from interface: Matrix
y = alpha*AT*x + y

Specified by:
transMultAdd in interface Matrix
Overrides:
transMultAdd in class AbstractMatrix
x - Vector of size A.numRows()
y - Vector of size A.numColumns()
Returns:
y

multAdd

public Matrix multAdd(double alpha,
                      Matrix B,
                      Matrix C)
Description copied from interface: Matrix
C = alpha*A*B + C

Specified by:
multAdd in interface Matrix
Overrides:
multAdd in class AbstractMatrix
B - Matrix such that B.numRows() == A.numColumns() and B.numColumns() == C.numColumns()
C - Matrix such that C.numRows() == A.numRows() and B.numColumns() == C.numColumns()
Returns:
C

transBmultAdd

public Matrix transBmultAdd(double alpha,
                            Matrix B,
                            Matrix C)
Description copied from interface: Matrix
C = alpha*A*BT + C

Specified by:
transBmultAdd in interface Matrix
Overrides:
transBmultAdd in class AbstractMatrix
B - Matrix such that B.numRows() == A.numRows() and B.numColumns() == C.numColumns()
C - Matrix such that C.numRows() == A.numColumns() and B.numColumns() == C.numColumns()
Returns:
C

transAmultAdd

public Matrix transAmultAdd(double alpha,
                            Matrix B,
                            Matrix C)
Description copied from interface: Matrix
C = alpha*AT*B + C

Specified by:
transAmultAdd in interface Matrix
Overrides:
transAmultAdd in class AbstractMatrix
B - Matrix such that B.numRows() == A.numRows() and B.numColumns() == C.numColumns()
C - Matrix such that C.numRows() == A.numColumns() and B.numColumns() == C.numColumns()
Returns:
C

transABmultAdd

public Matrix transABmultAdd(double alpha,
                             Matrix B,
                             Matrix C)
Description copied from interface: Matrix
C = alpha*AT*BT + C

Specified by:
transABmultAdd in interface Matrix
Overrides:
transABmultAdd in class AbstractMatrix
B - Matrix such that B.numColumns() == A.numRows() and B.numRows() == C.numColumns()
C - Matrix such that C.numRows() == A.numColumns() and B.numRows() == C.numColumns()
Returns:
C


Copyright © 2015. All Rights Reserved.