|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsim.util.mantissa.linalg.Matrix
public abstract class Matrix
This class factor all services common to matrices.
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.
This file is from the "Mantissa" Java software package found at http://www.spaceroots.org/software/mantissa/index.html. The license is included at the end of the source file.
Field Summary | |
---|---|
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. |
Constructor Summary | |
---|---|
protected |
Matrix(int rows,
int columns)
Simple constructor. |
|
Matrix(int rows,
int columns,
double[] data)
Simple constructor. |
protected |
Matrix(Matrix m)
Copy constructor. |
Method Summary | |
---|---|
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 sim.util.mantissa.linalg.NonNullRange |
getRangeForColumn(int j)
Set a range to the non null part covered by a column. |
protected abstract sim.util.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()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final int rows
protected final int columns
protected final double[] data
Constructor Detail |
---|
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 copyMethod Detail |
---|
public 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 - 1
java.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 element
java.lang.ArrayIndexOutOfBoundsException
- if the indices are wronggetElement(int, int)
public Matrix add(Matrix m)
m
- matrix to add
java.lang.IllegalArgumentException
- if there is a dimension mismatchpublic Matrix sub(Matrix m)
m
- matrix to substract
java.lang.IllegalArgumentException
- if there is a dimension mismatchpublic Matrix mul(Matrix m)
m
- matrix by which to multiply
java.lang.IllegalArgumentException
- if there is a dimension mismatchpublic Matrix mul(double a)
a
- scalar by which to multiply
selfMul(double)
public void selfMul(double a)
a
- scalar by which to multiplymul(double)
public Matrix getTranspose()
protected abstract sim.util.mantissa.linalg.NonNullRange getRangeForRow(int i)
i
- index of the row
getRangeForColumn(int)
protected abstract sim.util.mantissa.linalg.NonNullRange getRangeForColumn(int j)
j
- index of the column
getRangeForRow(int)
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |