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). -
transposeandtranspose(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 intNumber of columnsprotected intNumber of rows -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMatrix(int numRows, int numColumns) Constructor for AbstractMatrixprotectedConstructor for AbstractMatrix, same size as A. -
Method Summary
Modifier and TypeMethodDescriptionA = alpha*B + A.voidadd(int row, int column, double value) A(row,column) += valueA = B + A.protected voidcheck(int row, int column) Checks the passed row and column indicesprotected voidcheckMultAdd(Matrix B, Matrix C) Checks the arguments tomultandmultAddprotected voidcheckMultAdd(Vector x, Vector y) Checks the arguments tomultandmultAddprotected voidcheckRank1(Matrix C) Checks that a matrix rank1 update is possible for the given matrixprotected voidcheckRank1(Vector x, Vector y) Checks that a vector rank1 update is possible for the given vectorsprotected voidcheckRank2(Matrix B, Matrix C) Checks that a rank2 update is legal for the given argumentsprotected voidcheckRank2(Vector x, Vector y) Checks that a vector rank2 update is legal with the given vectorsprotected voidChecks that the sizes of this matrix and the given conformprotected voidcheckSolve(Matrix B, Matrix X) Checks that a matrix inversion is legal for the given arguments.protected voidcheckSolve(Vector b, Vector x) Checks that a matrix inversion is legal for the given arguments.protected voidcheckTransABmultAdd(Matrix B, Matrix C) Checks the arguments totransABmultAddandtransABmultAddprotected voidcheckTransAmultAdd(Matrix B, Matrix C) Checks the arguments totransAmultandtransAmultAddprotected voidcheckTransBmultAdd(Matrix B, Matrix C) Checks the arguments totransBmultandtransBmultAddprotected voidcheckTransMultAdd(Vector x, Vector y) Checks the arguments totransMultandtransMultAddprotected voidChecks that the matrix may be transposedprotected voidChecks that this matrix can be transposed into the given matrixprotected voidChecks that a transposed rank1 update is leagal with the given argumentprotected voidcheckTransRank2(Matrix B, Matrix C) Checks that a transposed rank2 update is leagal with the given argumentscopy()Creates a deep copy of the matrixdoubleget(int row, int column) ReturnsA(row,column)booleanisSquare()Returns true if the matrix is squareiterator()protected doublemax()Returns the largest absolute valueprotected doublemax(double[] x) Returns the largest element of the passed arrayC = alpha*A*By = alpha*A*xC = A*By = A*xC = alpha*A*B + Cy = alpha*A*x + yC = A*B + Cy = A*x + ydoublenorm(Matrix.Norm type) Computes the given norm of the matrixprotected doublenorm1()Computes the 1 normprotected doublenormF()Computes the Frobenius norm.protected doublenormInf()Computes the infinity normintNumber of columns in the matrixintnumRows()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*AA=alpha*B.voidset(int row, int column, double value) A(row,column) = valueA=B.X = A\B.x = A\b.toString()transABmult(double alpha, Matrix B, Matrix C) C = alpha*AT*BTtransABmult(Matrix B, Matrix C) C = AT*BTtransABmultAdd(double alpha, Matrix B, Matrix C) C = alpha*AT*BT + CtransABmultAdd(Matrix B, Matrix C) C = AT*BT + CtransAmult(double alpha, Matrix B, Matrix C) C = alpha*AT*BtransAmult(Matrix B, Matrix C) C = AT*BtransAmultAdd(double alpha, Matrix B, Matrix C) C = alpha*AT*B + CtransAmultAdd(Matrix B, Matrix C) C = AT*B + CtransBmult(double alpha, Matrix B, Matrix C) C = alpha*A*BTtransBmult(Matrix B, Matrix C) C = A*BTtransBmultAdd(double alpha, Matrix B, Matrix C) C = alpha*A*BT + CtransBmultAdd(Matrix B, Matrix C) C = A*BT + Cy = alpha*AT*xy = AT*xtransMultAdd(double alpha, Vector x, Vector y) y = alpha*AT*x + ytransMultAdd(Vector x, Vector y) y = AT*x + yTransposes the matrix in-place.Sets the tranpose of this matrix intoB.transRank1(double alpha, Matrix C) A = alpha*CT*C + AThe matrices must be square and of the same sizetransRank1(Matrix C) A = CT*C + AThe 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, waitMethods 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:MatrixNumber of rows in the matrix -
numColumns
public int numColumns()Description copied from interface:MatrixNumber of columns in the matrix- Specified by:
numColumnsin interfaceMatrix
-
isSquare
public boolean isSquare()Description copied from interface:MatrixReturns true if the matrix is square -
set
public void set(int row, int column, double value) Description copied from interface:MatrixA(row,column) = value -
add
public void add(int row, int column, double value) Description copied from interface:MatrixA(row,column) += value -
get
public double get(int row, int column) Description copied from interface:MatrixReturnsA(row,column) -
check
protected void check(int row, int column) Checks the passed row and column indices -
copy
Description copied from interface:MatrixCreates a deep copy of the matrix -
zero
Description copied from interface:MatrixZeros all the entries in the matrix, while preserving any underlying structure. Useful for general, unstructured matrices. -
mult
Description copied from interface:Matrixy = A*x -
mult
Description copied from interface:Matrixy = alpha*A*x -
multAdd
Description copied from interface:Matrixy = A*x + y -
multAdd
Description copied from interface:Matrixy = alpha*A*x + y -
checkMultAdd
Checks the arguments tomultandmultAdd -
transMult
Description copied from interface:Matrixy = AT*x -
transMult
Description copied from interface:Matrixy = alpha*AT*x -
transMultAdd
Description copied from interface:Matrixy = AT*x + y- Specified by:
transMultAddin interfaceMatrix- Parameters:
x- Vector of sizeA.numRows()y- Vector of sizeA.numColumns()- Returns:
- y
-
transMultAdd
Description copied from interface:Matrixy = alpha*AT*x + y- Specified by:
transMultAddin interfaceMatrix- Parameters:
x- Vector of sizeA.numRows()y- Vector of sizeA.numColumns()- Returns:
- y
-
checkTransMultAdd
Checks the arguments totransMultandtransMultAdd -
solve
Description copied from interface:Matrixx = 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:Matrixx = 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:
transSolvein 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:MatrixA = x*xT + A. The matrix must be square, and the vector of the same length -
rank1
Description copied from interface:MatrixA = alpha*x*xT + A. The matrix must be square, and the vector of the same length -
rank1
Description copied from interface:MatrixA = x*yT + A. The matrix must be square, and the vectors of the same length -
rank1
Description copied from interface:MatrixA = 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:MatrixA = x*yT + y*xT + A. The matrix must be square, and the vectors of the same length -
rank2
Description copied from interface:MatrixA = 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:MatrixC = A*B -
mult
Description copied from interface:MatrixC = alpha*A*B -
multAdd
Description copied from interface:MatrixC = A*B + C -
multAdd
Description copied from interface:MatrixC = alpha*A*B + C -
checkMultAdd
Checks the arguments tomultandmultAdd -
transAmult
Description copied from interface:MatrixC = AT*B- Specified by:
transAmultin 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:MatrixC = alpha*AT*B- Specified by:
transAmultin 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:MatrixC = AT*B + C- Specified by:
transAmultAddin 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:MatrixC = alpha*AT*B + C- Specified by:
transAmultAddin 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 totransAmultandtransAmultAdd -
transBmult
Description copied from interface:MatrixC = A*BT- Specified by:
transBmultin 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:MatrixC = alpha*A*BT- Specified by:
transBmultin 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:MatrixC = A*BT + C- Specified by:
transBmultAddin 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:MatrixC = alpha*A*BT + C- Specified by:
transBmultAddin 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 totransBmultandtransBmultAdd -
transABmult
Description copied from interface:MatrixC = AT*BT- Specified by:
transABmultin 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:MatrixC = alpha*AT*BT- Specified by:
transABmultin 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:MatrixC = AT*BT + C- Specified by:
transABmultAddin 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:MatrixC = alpha*AT*BT + C- Specified by:
transABmultAddin 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 totransABmultAddandtransABmultAdd -
solve
Description copied from interface:MatrixX = 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:MatrixX = 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:
transSolvein interfaceMatrix- Parameters:
B- Matrix with a number of rows equalA.numColumns(), and the same number of columns asXX- 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:MatrixA = C*CT + A. The matrices must be square and of the same size -
rank1
Description copied from interface:MatrixA = 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:MatrixA = CT*C + AThe matrices must be square and of the same size- Specified by:
transRank1in interfaceMatrix- Returns:
- A
-
transRank1
Description copied from interface:MatrixA = alpha*CT*C + AThe matrices must be square and of the same size- Specified by:
transRank1in interfaceMatrix- Returns:
- A
-
checkTransRank1
Checks that a transposed rank1 update is leagal with the given argument -
rank2
Description copied from interface:MatrixA = B*CT + C*BT + A. This matrix must be square -
rank2
Description copied from interface:MatrixA = 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:MatrixA = BT*C + CT*B + A. This matrix must be square- Specified by:
transRank2in interfaceMatrix- Parameters:
B- Matrix with the same number of rows asCand the same number of columns asAC- Matrix with the same number of rows asBand the same number of columns asA- Returns:
- A
-
transRank2
Description copied from interface:MatrixA = alpha*BT*C + alpha*CT*B + A. This matrix must be square- Specified by:
transRank2in interfaceMatrix- Parameters:
B- Matrix with the same number of rows asCand the same number of columns asAC- Matrix with the same number of rows asBand 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:MatrixA = alpha*A -
set
Description copied from interface:MatrixA=B. The matrices must be of the same size -
set
Description copied from interface:MatrixA=alpha*B. The matrices must be of the same size -
add
Description copied from interface:MatrixA = B + A. The matrices must be of the same size -
add
Description copied from interface:MatrixA = 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:MatrixTransposes 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:MatrixSets 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:MatrixComputes 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:
iteratorin interfaceIterable<MatrixEntry>
-