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 ofstorageare known.
-
-
Constructor Summary
Constructors Constructor Description DefaultMatrixStorage(MatrixAccess storage)Construct aDefaultMatrixStorageto wrap a storage for access.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)doubleget(int row, int col)Get the matrix entry at [i,j].VectorgetColumn(int j)Get a column.VectorgetRow(int i)Get a row.inthashCode()intnCols()Gets the number of columns.intnRows()Gets the number of rows.voidset(int row, int col, double value)Set the matrix entry at [i,j] to a value.voidsetColumn(int j, double... values)Set the values for a column in the matrix, i.e., [*, j].voidsetColumn(int j, Vector v)Set the values for a column in the matrix, i.e., [*, j].voidsetRow(int i, double... values)Set the values for a row in the matrix, i.e., [i, *].voidsetRow(int i, Vector v)Set the values for a row in the matrix, i.e., [i, *].StringtoString()
-
-
-
Constructor Detail
-
DefaultMatrixStorage
public DefaultMatrixStorage(MatrixAccess storage)
Construct aDefaultMatrixStorageto wrap a storage for access.- Parameters:
storage- the matrix data storage/representation
-
-
Method Detail
-
nRows
public int nRows()
Description copied from interface:TableGets the number of rows. Rows count from 1.
-
nCols
public int nCols()
Description copied from interface:TableGets the number of columns. Columns count from 1.
-
set
public void set(int row, int col, double value) throws MatrixAccessExceptionDescription copied from interface:MatrixAccessSet the matrix entry at [i,j] to a value. This is the only method that may change a matrix.- Specified by:
setin 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 MatrixAccessExceptionDescription copied from interface:MatrixAccessGet the matrix entry at [i,j].- Specified by:
getin 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 ofvaluesdoes 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 ofvaluesdoes 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 ofvaluesdoes 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 ofvaluesdoes 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
-
-