public abstract class Matrix
extends java.lang.Object
implements java.io.Serializable
This class is the base class of all matrix implementations, it
is also the base class of the SquareMatrix class which adds
methods specific to square matrices.
This class both handles the storage of matrix elements and
implements the classical operations on matrices (addition,
substraction, multiplication, transposition). It relies on two
protected methods (getRangeForRow(int) and getRangeForColumn(int)) to get tight loop bounds for matrices with
known structures full of zeros. These methods should be
implemented by derived classes to provide information about their
specific shape to the general algorithms implemented by this
abstract class.
| Modifier and Type | Field and Description |
|---|---|
protected int |
columns
number of columns of the matrix.
|
protected double[] |
data
array of the matrix elements.
|
protected int |
rows
number of rows of the matrix.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Matrix(int rows,
int columns)
Simple constructor.
|
|
Matrix(int rows,
int columns,
double[] data)
Simple constructor.
|
protected |
Matrix(Matrix m)
Copy constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Matrix |
add(Matrix m)
Add a matrix to the instance.
|
abstract Matrix |
duplicate()
Polymorphic copy operator.
|
int |
getColumns()
Get the number of columns of the matrix.
|
double |
getElement(int i,
int j)
Get a matrix element.
|
protected abstract org.spaceroots.mantissa.linalg.NonNullRange |
getRangeForColumn(int j)
Set a range to the non null part covered by a column.
|
protected abstract org.spaceroots.mantissa.linalg.NonNullRange |
getRangeForRow(int i)
Set a range to the non null part covered by a row.
|
int |
getRows()
Get the number of rows of the matrix.
|
Matrix |
getTranspose()
Compute the transpose of the instance.
|
Matrix |
mul(double a)
Multiply the instance by a scalar.
|
Matrix |
mul(Matrix m)
Multiply the instance by a matrix.
|
void |
selfMul(double a)
Multiply the instance by a scalar.
|
void |
setElement(int i,
int j,
double value)
Set a matrix element.
|
Matrix |
sub(Matrix m)
Substract a matrix from the instance.
|
java.lang.String |
toString() |
protected final int rows
protected final int columns
protected final double[] data
protected Matrix(int rows,
int columns)
rows - number of rows of the matrixcolumns - number of columns of the matrixpublic Matrix(int rows,
int columns,
double[] data)
rows - number of rows of the matrixcolumns - number of columns of the matrixdata - table of the matrix elements (stored row after row)protected Matrix(Matrix m)
m - matrix to copypublic abstract Matrix duplicate()
Object.clone()
method, except that it has public access, it doesn't throw any
specific exception and it returns a Matrix.Object.clone()public int getRows()
getColumns()public int getColumns()
getRows()public double getElement(int i,
int j)
i - row index, from 0 to rows - 1j - column index, from 0 to cols - 1java.lang.ArrayIndexOutOfBoundsException - if the indices are wrongsetElement(int, int, double)public void setElement(int i,
int j,
double value)
i - row index, from 0 to rows - 1j - column index, from 0 to cols - 1value - value of the elementjava.lang.ArrayIndexOutOfBoundsException - if the indices are wronggetElement(int, int)public Matrix add(Matrix m)
m - matrix to addjava.lang.IllegalArgumentException - if there is a dimension mismatchpublic Matrix sub(Matrix m)
m - matrix to substractjava.lang.IllegalArgumentException - if there is a dimension mismatchpublic Matrix mul(Matrix m)
m - matrix by which to multiplyjava.lang.IllegalArgumentException - if there is a dimension mismatchpublic Matrix mul(double a)
a - scalar by which to multiplyselfMul(double)public void selfMul(double a)
a - scalar by which to multiplymul(double)public Matrix getTranspose()
protected abstract org.spaceroots.mantissa.linalg.NonNullRange getRangeForRow(int i)
i - index of the rowgetRangeForColumn(int)protected abstract org.spaceroots.mantissa.linalg.NonNullRange getRangeForColumn(int j)
j - index of the columngetRangeForRow(int)public java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2001-2007 Luc Maisonobe. All Rights Reserved.