Class DefaultMatrixStorage
- java.lang.Object
-
- dev.nm.algebra.linear.matrix.doubles.matrixtype.DefaultMatrixStorage
-
- All Implemented Interfaces:
MatrixAccess
,Table
public class DefaultMatrixStorage extends Object implements MatrixAccess
There are multiple ways to implement the storage data structure depending on the matrix type for optimization purpose. This class provides a default way to access the storage structure. A particular matrix implementation may override these methods for performance, if implementation details ofstorage
are known.
-
-
Constructor Summary
Constructors Constructor Description DefaultMatrixStorage(MatrixAccess storage)
Construct aDefaultMatrixStorage
to wrap a storage for access.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
double
get(int row, int col)
Get the matrix entry at [i,j].Vector
getColumn(int j)
Get a column.Vector
getRow(int i)
Get a row.int
hashCode()
int
nCols()
Gets the number of columns.int
nRows()
Gets the number of rows.void
set(int row, int col, double value)
Set the matrix entry at [i,j] to a value.void
setColumn(int j, double... values)
Set the values for a column in the matrix, i.e., [*, j].void
setColumn(int j, Vector v)
Set the values for a column in the matrix, i.e., [*, j].void
setRow(int i, double... values)
Set the values for a row in the matrix, i.e., [i, *].void
setRow(int i, Vector v)
Set the values for a row in the matrix, i.e., [i, *].String
toString()
-
-
-
Constructor Detail
-
DefaultMatrixStorage
public DefaultMatrixStorage(MatrixAccess storage)
Construct aDefaultMatrixStorage
to wrap a storage for access.- Parameters:
storage
- the matrix data storage/representation
-
-
Method Detail
-
nRows
public int nRows()
Description copied from interface:Table
Gets the number of rows. Rows count from 1.
-
nCols
public int nCols()
Description copied from interface:Table
Gets the number of columns. Columns count from 1.
-
set
public void set(int row, int col, double value) throws MatrixAccessException
Description copied from interface:MatrixAccess
Set the matrix entry at [i,j] to a value. This is the only method that may change a matrix.- Specified by:
set
in interfaceMatrixAccess
- Parameters:
row
- the row indexcol
- the column indexvalue
- the value to set A[i,j] to- Throws:
MatrixAccessException
- if i or j is out of range
-
get
public double get(int row, int col) throws MatrixAccessException
Description copied from interface:MatrixAccess
Get the matrix entry at [i,j].- Specified by:
get
in interfaceMatrixAccess
- Parameters:
row
- the row indexcol
- the column index- Returns:
- A[i,j]
- Throws:
MatrixAccessException
- if i or j is out of range
-
setRow
public void setRow(int i, double... values)
Set the values for a row in the matrix, i.e., [i, *].- Parameters:
i
- the row index, counting from 1values
- the values to change the row entries to- Throws:
MatrixAccessException
- if the number ofvalues
does not match the column size
-
setRow
public void setRow(int i, Vector v)
Set the values for a row in the matrix, i.e., [i, *].- Parameters:
i
- the row index, counting from 1v
- the vector to change the row entries to- Throws:
MatrixAccessException
- if the number ofvalues
does not match the column size
-
getRow
public Vector getRow(int i) throws MatrixAccessException
Get a row.- Parameters:
i
- the row index, counting from 1- Returns:
- row i
- Throws:
MatrixAccessException
- if the row index is invalid
-
setColumn
public void setColumn(int j, double... values)
Set the values for a column in the matrix, i.e., [*, j].- Parameters:
j
- the column index, counting from 1values
- the values to change the column entries to- Throws:
MatrixAccessException
- if the number ofvalues
does not match the row size
-
setColumn
public void setColumn(int j, Vector v)
Set the values for a column in the matrix, i.e., [*, j].- Parameters:
j
- the column index, counting from 1v
- the vector to change the column entries to- Throws:
MatrixAccessException
- if the number ofvalues
does not match the row size
-
getColumn
public Vector getColumn(int j) throws MatrixAccessException
Get a column.- Parameters:
j
- the column index, counting from 1- Returns:
- row j
- Throws:
MatrixAccessException
- if the column index is invalid
-
-