Package org.biojava.nbio.structure.math
Class SparseSquareMatrix
- java.lang.Object
-
- org.biojava.nbio.structure.math.SparseSquareMatrix
-
- All Implemented Interfaces:
Serializable
public class SparseSquareMatrix extends Object implements Serializable
A sparse, square matrix, implementing using two arrays of sparse vectors, one representation for the rows and one for the columns. For matrix-matrix product, we might also want to store the column representation. Derived from http://introcs.cs.princeton.edu/java/44st/SparseMatrix.java.html For additional documentation, see Section 4.4 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SparseSquareMatrix(int N)initialize an N-by-N matrix of all 0s
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleget(int i, int j)access a value at i,jintnnz()return the number of nonzero entries (not the most efficient implementation)SparseSquareMatrixplus(SparseSquareMatrix B)return C = A + Bvoidput(int i, int j, double value)set A[i][j] = valueSparseVectortimes(SparseVector x)StringtoString()
-
-
-
Constructor Detail
-
SparseSquareMatrix
public SparseSquareMatrix(int N)
initialize an N-by-N matrix of all 0s- Parameters:
N- - size
-
-
Method Detail
-
put
public void put(int i, int j, double value)
set A[i][j] = value- Parameters:
i-j-value-
-
get
public double get(int i, int j)
access a value at i,j- Parameters:
i-j-- Returns:
- return A[i][j]
-
nnz
public int nnz()
return the number of nonzero entries (not the most efficient implementation)- Returns:
-
times
public SparseVector times(SparseVector x)
- Parameters:
x-- Returns:
- return the matrix-vector product b = Ax
-
plus
public SparseSquareMatrix plus(SparseSquareMatrix B)
return C = A + B- Parameters:
B-- Returns:
-
-