Package no.uib.cipr.matrix
Class AbstractMatrix
java.lang.Object
no.uib.cipr.matrix.AbstractMatrix
- All Implemented Interfaces:
Iterable<MatrixEntry>
,Matrix
- Direct Known Subclasses:
BandMatrix
,CompColMatrix
,CompDiagMatrix
,CompRowMatrix
,DenseMatrix
,DistColMatrix
,DistRowMatrix
,FlexCompColMatrix
,FlexCompRowMatrix
,LowerSymmBandMatrix
,LowerSymmDenseMatrix
,LowerSymmPackMatrix
,LowerTriangBandMatrix
,LowerTriangDenseMatrix
,LowerTriangPackMatrix
,SymmTridiagMatrix
,TridiagMatrix
,UpperSymmBandMatrix
,UpperSymmDenseMatrix
,UpperSymmPackMatrix
,UpperTriangBandMatrix
,UpperTriangDenseMatrix
,UpperTriangPackMatrix
Partial implementation of
Matrix
. The following methods throw
UnsupportedOperationException
, and should be overridden by a
subclass:
get(int,int)
set(int,int,double)
copy
- All the direct solution methods
For the rest of the methods, simple default implementations using a matrix
iterator has been provided. There are some kernel operations which the
simpler operations forward to, for instance, mult(Matrix,Matrix)
forwards to multAdd(double,Matrix,Matrix)
. Subclasses can
thus focus on overriding the kernel operations, which are:
-
multAdd(double,Vector,Vector)
andtransMultAdd(double,Vector,Vector)
. -
rank1(double,Vector,Vector)
andrank1(double,Vector,Vector)
. -
multAdd(double,Matrix,Matrix)
,transAmultAdd(double,Matrix,Matrix)
,transBmultAdd(double,Matrix,Matrix)
, andtransABmultAdd(double,Matrix,Matrix)
. -
scale(double)
. -
set(double,Matrix)
andadd(double,Matrix)
. -
transpose
andtranspose(Matrix)
. - All the norms.
Finally, a default iterator is provided by this class, which works by calling
the get
function. A tailored replacement should be used by
subclasses.
-
Nested Class Summary
Nested classes/interfaces inherited from interface no.uib.cipr.matrix.Matrix
Matrix.Norm
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
Number of columnsprotected int
Number of rows -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractMatrix
(int numRows, int numColumns) Constructor for AbstractMatrixprotected
Constructor for AbstractMatrix, same size as A. -
Method Summary
Modifier and TypeMethodDescriptionA = alpha*B + A
.void
add
(int row, int column, double value) A(row,column) += value
A = B + A
.protected void
check
(int row, int column) Checks the passed row and column indicesprotected void
checkMultAdd
(Matrix B, Matrix C) Checks the arguments tomult
andmultAdd
protected void
checkMultAdd
(Vector x, Vector y) Checks the arguments tomult
andmultAdd
protected void
checkRank1
(Matrix C) Checks that a matrix rank1 update is possible for the given matrixprotected void
checkRank1
(Vector x, Vector y) Checks that a vector rank1 update is possible for the given vectorsprotected void
checkRank2
(Matrix B, Matrix C) Checks that a rank2 update is legal for the given argumentsprotected void
checkRank2
(Vector x, Vector y) Checks that a vector rank2 update is legal with the given vectorsprotected void
Checks that the sizes of this matrix and the given conformprotected void
checkSolve
(Matrix B, Matrix X) Checks that a matrix inversion is legal for the given arguments.protected void
checkSolve
(Vector b, Vector x) Checks that a matrix inversion is legal for the given arguments.protected void
checkTransABmultAdd
(Matrix B, Matrix C) Checks the arguments totransABmultAdd
andtransABmultAdd
protected void
checkTransAmultAdd
(Matrix B, Matrix C) Checks the arguments totransAmult
andtransAmultAdd
protected void
checkTransBmultAdd
(Matrix B, Matrix C) Checks the arguments totransBmult
andtransBmultAdd
protected void
checkTransMultAdd
(Vector x, Vector y) Checks the arguments totransMult
andtransMultAdd
protected void
Checks that the matrix may be transposedprotected void
Checks that this matrix can be transposed into the given matrixprotected void
Checks that a transposed rank1 update is leagal with the given argumentprotected void
checkTransRank2
(Matrix B, Matrix C) Checks that a transposed rank2 update is leagal with the given argumentscopy()
Creates a deep copy of the matrixdouble
get
(int row, int column) ReturnsA(row,column)
boolean
isSquare()
Returns true if the matrix is squareiterator()
protected double
max()
Returns the largest absolute valueprotected double
max
(double[] x) Returns the largest element of the passed arrayC = alpha*A*B
y = alpha*A*x
C = A*B
y = A*x
C = alpha*A*B + C
y = alpha*A*x + y
C = A*B + C
y = A*x + y
double
norm
(Matrix.Norm type) Computes the given norm of the matrixprotected double
norm1()
Computes the 1 normprotected double
normF()
Computes the Frobenius norm.protected double
normInf()
Computes the infinity normint
Number of columns in the matrixint
numRows()
Number of rows in the matrixA = alpha*C*CT + A
.A = alpha*x*xT + A
.A = alpha*x*yT + A
.A = C*CT + A
.A = x*xT + A
.A = x*yT + A
.A = alpha*B*CT + alpha*C*BT + A
.A = alpha*x*yT + alpha*y*xT + A
.A = B*CT + C*BT + A
.A = x*yT + y*xT + A
.scale
(double alpha) A = alpha*A
A=alpha*B
.void
set
(int row, int column, double value) A(row,column) = value
A=B
.X = A\B
.x = A\b
.toString()
transABmult
(double alpha, Matrix B, Matrix C) C = alpha*AT*BT
transABmult
(Matrix B, Matrix C) C = AT*BT
transABmultAdd
(double alpha, Matrix B, Matrix C) C = alpha*AT*BT + C
transABmultAdd
(Matrix B, Matrix C) C = AT*BT + C
transAmult
(double alpha, Matrix B, Matrix C) C = alpha*AT*B
transAmult
(Matrix B, Matrix C) C = AT*B
transAmultAdd
(double alpha, Matrix B, Matrix C) C = alpha*AT*B + C
transAmultAdd
(Matrix B, Matrix C) C = AT*B + C
transBmult
(double alpha, Matrix B, Matrix C) C = alpha*A*BT
transBmult
(Matrix B, Matrix C) C = A*BT
transBmultAdd
(double alpha, Matrix B, Matrix C) C = alpha*A*BT + C
transBmultAdd
(Matrix B, Matrix C) C = A*BT + C
y = alpha*AT*x
y = AT*x
transMultAdd
(double alpha, Vector x, Vector y) y = alpha*AT*x + y
transMultAdd
(Vector x, Vector y) y = AT*x + y
Transposes the matrix in-place.Sets the tranpose of this matrix intoB
.transRank1
(double alpha, Matrix C) A = alpha*CT*C + A
The matrices must be square and of the same sizetransRank1
(Matrix C) A = CT*C + A
The matrices must be square and of the same sizetransRank2
(double alpha, Matrix B, Matrix C) A = alpha*BT*C + alpha*CT*B + A
.transRank2
(Matrix B, Matrix C) A = BT*C + CT*B + A
.transSolve
(Matrix B, Matrix X) X = AT\B
.transSolve
(Vector b, Vector x) x = AT\b
.zero()
Zeros all the entries in the matrix, while preserving any underlying structure.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
numRows
protected int numRowsNumber of rows -
numColumns
protected int numColumnsNumber of columns
-
-
Constructor Details
-
AbstractMatrix
protected AbstractMatrix(int numRows, int numColumns) Constructor for AbstractMatrix -
AbstractMatrix
Constructor for AbstractMatrix, same size as A. The invoking constructor should set this matrix equal the argument matrix
-
-
Method Details
-
numRows
public int numRows()Description copied from interface:Matrix
Number of rows in the matrix -
numColumns
public int numColumns()Description copied from interface:Matrix
Number of columns in the matrix- Specified by:
numColumns
in interfaceMatrix
-
isSquare
public boolean isSquare()Description copied from interface:Matrix
Returns true if the matrix is square -
set
public void set(int row, int column, double value) Description copied from interface:Matrix
A(row,column) = value
-
add
public void add(int row, int column, double value) Description copied from interface:Matrix
A(row,column) += value
-
get
public double get(int row, int column) Description copied from interface:Matrix
ReturnsA(row,column)
-
check
protected void check(int row, int column) Checks the passed row and column indices -
copy
Description copied from interface:Matrix
Creates a deep copy of the matrix -
zero
Description copied from interface:Matrix
Zeros all the entries in the matrix, while preserving any underlying structure. Useful for general, unstructured matrices. -
mult
Description copied from interface:Matrix
y = A*x
-
mult
Description copied from interface:Matrix
y = alpha*A*x
-
multAdd
Description copied from interface:Matrix
y = A*x + y
-
multAdd
Description copied from interface:Matrix
y = alpha*A*x + y
-
checkMultAdd
Checks the arguments tomult
andmultAdd
-
transMult
Description copied from interface:Matrix
y = AT*x
-
transMult
Description copied from interface:Matrix
y = alpha*AT*x
-
transMultAdd
Description copied from interface:Matrix
y = AT*x + y
- Specified by:
transMultAdd
in interfaceMatrix
- Parameters:
x
- Vector of sizeA.numRows()
y
- Vector of sizeA.numColumns()
- Returns:
- y
-
transMultAdd
Description copied from interface:Matrix
y = alpha*AT*x + y
- Specified by:
transMultAdd
in interfaceMatrix
- Parameters:
x
- Vector of sizeA.numRows()
y
- Vector of sizeA.numColumns()
- Returns:
- y
-
checkTransMultAdd
Checks the arguments totransMult
andtransMultAdd
-
solve
Description copied from interface:Matrix
x = A\b
. Not all matrices support this operation, those that do not throwUnsupportedOperationException
. Note that it is often more efficient to use a matrix decomposition and its associated solver -
transSolve
Description copied from interface:Matrix
x = AT\b
. Not all matrices support this operation, those that do not throwUnsupportedOperationException
. Note that it is often more efficient to use a matrix decomposition and its associated solver- Specified by:
transSolve
in interfaceMatrix
- Parameters:
b
- Vector of sizeA.numColumns()
x
- Vector of sizeA.numRows()
- Returns:
- x
-
checkSolve
Checks that a matrix inversion is legal for the given arguments. This is for the square case, not for least-squares problems -
rank1
Description copied from interface:Matrix
A = x*xT + A
. The matrix must be square, and the vector of the same length -
rank1
Description copied from interface:Matrix
A = alpha*x*xT + A
. The matrix must be square, and the vector of the same length -
rank1
Description copied from interface:Matrix
A = x*yT + A
. The matrix must be square, and the vectors of the same length -
rank1
Description copied from interface:Matrix
A = alpha*x*yT + A
. The matrix must be square, and the vectors of the same length -
checkRank1
Checks that a vector rank1 update is possible for the given vectors -
rank2
Description copied from interface:Matrix
A = x*yT + y*xT + A
. The matrix must be square, and the vectors of the same length -
rank2
Description copied from interface:Matrix
A = alpha*x*yT + alpha*y*xT + A
. The matrix must be square, and the vectors of the same length -
checkRank2
Checks that a vector rank2 update is legal with the given vectors -
mult
Description copied from interface:Matrix
C = A*B
-
mult
Description copied from interface:Matrix
C = alpha*A*B
-
multAdd
Description copied from interface:Matrix
C = A*B + C
-
multAdd
Description copied from interface:Matrix
C = alpha*A*B + C
-
checkMultAdd
Checks the arguments tomult
andmultAdd
-
transAmult
Description copied from interface:Matrix
C = AT*B
- Specified by:
transAmult
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numRows() == A.numRows()
andB.numColumns() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numColumns() == C.numColumns()
- Returns:
- C
-
transAmult
Description copied from interface:Matrix
C = alpha*AT*B
- Specified by:
transAmult
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numRows() == A.numRows()
andB.numColumns() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numColumns() == C.numColumns()
- Returns:
- C
-
transAmultAdd
Description copied from interface:Matrix
C = AT*B + C
- Specified by:
transAmultAdd
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numRows() == A.numRows()
andB.numColumns() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numColumns() == C.numColumns()
- Returns:
- C
-
transAmultAdd
Description copied from interface:Matrix
C = alpha*AT*B + C
- Specified by:
transAmultAdd
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numRows() == A.numRows()
andB.numColumns() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numColumns() == C.numColumns()
- Returns:
- C
-
checkTransAmultAdd
Checks the arguments totransAmult
andtransAmultAdd
-
transBmult
Description copied from interface:Matrix
C = A*BT
- Specified by:
transBmult
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numRows() == A.numRows()
andB.numColumns() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numColumns() == C.numColumns()
- Returns:
- C
-
transBmult
Description copied from interface:Matrix
C = alpha*A*BT
- Specified by:
transBmult
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numRows() == A.numRows()
andB.numColumns() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numColumns() == C.numColumns()
- Returns:
- C
-
transBmultAdd
Description copied from interface:Matrix
C = A*BT + C
- Specified by:
transBmultAdd
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numRows() == A.numRows()
andB.numColumns() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numColumns() == C.numColumns()
- Returns:
- C
-
transBmultAdd
Description copied from interface:Matrix
C = alpha*A*BT + C
- Specified by:
transBmultAdd
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numRows() == A.numRows()
andB.numColumns() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numColumns() == C.numColumns()
- Returns:
- C
-
checkTransBmultAdd
Checks the arguments totransBmult
andtransBmultAdd
-
transABmult
Description copied from interface:Matrix
C = AT*BT
- Specified by:
transABmult
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numColumns() == A.numRows()
andB.numRows() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numRows() == C.numColumns()
- Returns:
- C
-
transABmult
Description copied from interface:Matrix
C = alpha*AT*BT
- Specified by:
transABmult
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numColumns() == A.numRows()
andB.numRows() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numRows() == C.numColumns()
- Returns:
- C
-
transABmultAdd
Description copied from interface:Matrix
C = AT*BT + C
- Specified by:
transABmultAdd
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numColumns() == A.numRows()
andB.numRows() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numRows() == C.numColumns()
- Returns:
- C
-
transABmultAdd
Description copied from interface:Matrix
C = alpha*AT*BT + C
- Specified by:
transABmultAdd
in interfaceMatrix
- Parameters:
B
- Matrix such thatB.numColumns() == A.numRows()
andB.numRows() == C.numColumns()
C
- Matrix such thatC.numRows() == A.numColumns()
andB.numRows() == C.numColumns()
- Returns:
- C
-
checkTransABmultAdd
Checks the arguments totransABmultAdd
andtransABmultAdd
-
solve
Description copied from interface:Matrix
X = A\B
. Not all matrices support this operation, those that do not throwUnsupportedOperationException
. Note that it is often more efficient to use a matrix decomposition and its associated solver -
transSolve
Description copied from interface:Matrix
X = AT\B
. Not all matrices support this operation, those that do not throwUnsupportedOperationException
. Note that it is often more efficient to use a matrix decomposition and its associated transpose solver- Specified by:
transSolve
in interfaceMatrix
- Parameters:
B
- Matrix with a number of rows equalA.numColumns()
, and the same number of columns asX
X
- Matrix with the same number of rows asA
, and the same number of columns asB
- Returns:
- X
-
checkSolve
Checks that a matrix inversion is legal for the given arguments. This is for the square case, not for least-squares problems -
rank1
Description copied from interface:Matrix
A = C*CT + A
. The matrices must be square and of the same size -
rank1
Description copied from interface:Matrix
A = alpha*C*CT + A
. The matrices must be square and of the same size -
checkRank1
Checks that a matrix rank1 update is possible for the given matrix -
transRank1
Description copied from interface:Matrix
A = CT*C + A
The matrices must be square and of the same size- Specified by:
transRank1
in interfaceMatrix
- Returns:
- A
-
transRank1
Description copied from interface:Matrix
A = alpha*CT*C + A
The matrices must be square and of the same size- Specified by:
transRank1
in interfaceMatrix
- Returns:
- A
-
checkTransRank1
Checks that a transposed rank1 update is leagal with the given argument -
rank2
Description copied from interface:Matrix
A = B*CT + C*BT + A
. This matrix must be square -
rank2
Description copied from interface:Matrix
A = alpha*B*CT + alpha*C*BT + A
. This matrix must be square -
checkRank2
Checks that a rank2 update is legal for the given arguments -
transRank2
Description copied from interface:Matrix
A = BT*C + CT*B + A
. This matrix must be square- Specified by:
transRank2
in interfaceMatrix
- Parameters:
B
- Matrix with the same number of rows asC
and the same number of columns asA
C
- Matrix with the same number of rows asB
and the same number of columns asA
- Returns:
- A
-
transRank2
Description copied from interface:Matrix
A = alpha*BT*C + alpha*CT*B + A
. This matrix must be square- Specified by:
transRank2
in interfaceMatrix
- Parameters:
B
- Matrix with the same number of rows asC
and the same number of columns asA
C
- Matrix with the same number of rows asB
and the same number of columns asA
- Returns:
- A
-
checkTransRank2
Checks that a transposed rank2 update is leagal with the given arguments -
scale
Description copied from interface:Matrix
A = alpha*A
-
set
Description copied from interface:Matrix
A=B
. The matrices must be of the same size -
set
Description copied from interface:Matrix
A=alpha*B
. The matrices must be of the same size -
add
Description copied from interface:Matrix
A = B + A
. The matrices must be of the same size -
add
Description copied from interface:Matrix
A = alpha*B + A
. The matrices must be of the same size -
checkSize
Checks that the sizes of this matrix and the given conform -
transpose
Description copied from interface:Matrix
Transposes the matrix in-place. In most cases, the matrix must be square for this to work. -
checkTranspose
protected void checkTranspose()Checks that the matrix may be transposed -
transpose
Description copied from interface:Matrix
Sets the tranpose of this matrix intoB
. Matrix dimensions must be compatible -
checkTranspose
Checks that this matrix can be transposed into the given matrix -
norm
Description copied from interface:Matrix
Computes the given norm of the matrix -
norm1
protected double norm1()Computes the 1 norm -
normF
protected double normF()Computes the Frobenius norm. This implementation is overflow resistant -
normInf
protected double normInf()Computes the infinity norm -
max
protected double max()Returns the largest absolute value -
max
protected double max(double[] x) Returns the largest element of the passed array -
toString
-
iterator
- Specified by:
iterator
in interfaceIterable<MatrixEntry>
-