org.biojava.nbio.structure.math

## Class 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.
Serialized Form
• ### Constructor Summary

Constructors
Constructor and Description
`SparseSquareMatrix(int N)`
initialize an N-by-N matrix of all 0s
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` ```get(int i, int j)```
access a value at i,j
`int` `nnz()`
return the number of nonzero entries (not the most efficient implementation)
`SparseSquareMatrix` `plus(SparseSquareMatrix B)`
return C = A + B
`void` ```put(int i, int j, double value)```
set A[i][j] = value
`SparseVector` `times(SparseVector x)`
`String` `toString()`
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### 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:
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`