#include <APPSPACK_Matrix.hpp>
Collaboration diagram for APPSPACK::Matrix:

Vectorized storage
When interfacing with BLAS and LAPACK routines it is necessary to first write matrix elements to a vector of columns, and/or a vector of rows. To enhance computational efficiency when such a copy is made, it will be automatically be stored. If A is written to a vector by columns, a copy is stored in fmatvec and fmatvecSet is set to true. Similarly, if A is written to vector by rows, a copy is stored in fmatvecT and fmatvecTSet is set to true. To ensure that the vectorized forms of A are kept current, both fmatvecSet and fmatvecTSet are set to false upon instantiation and whenever a non-const method is called.
Definition at line 69 of file APPSPACK_Matrix.hpp.
Public Types | |
| enum | TransposeType { Transpose, NoTranspose } |
| Indicator for transpose operations. More... | |
Public Member Functions | |
| Matrix () | |
| Constructor. Creates an empty matrix. | |
| Matrix (const Matrix &B, TransposeType ttype=NoTranspose) | |
| Copy constructor. | |
| Matrix (const Matrix &B, const Vector &s, TransposeType ttype=NoTranspose) | |
| Copy constructor with scaling. | |
| Matrix (double **Aptr, int nrows, int ncols) | |
| Resizes A to be nrows by ncols. Sets A(i,j) = Aptr[i][j]. | |
| ~Matrix () | |
| Destructor. | |
Accessors | |
| bool | empty () const |
| Returns true if A is empty, i.e., the number of rows is zero. | |
| int | getNrows () const |
| Returns number of rows in A. | |
| int | getNcols () const |
| Returns number of columns in A. | |
| const Vector & | getRow (int i) const |
| Return ith row of A. | |
Modifiers | |
| void | getRowPointers (vector< double * > &Aptr) |
| On exit Aptr[i] points to row i of A. | |
| void | clear () |
| Empty the matrix A. | |
| void | addRow (const Vector &r) |
| Append a copy of r to the bottom of A. | |
| void | deleteRow (int i) |
| Deletes the ith row of A. | |
| void | addRow (const Vector &r, double alpha) |
| Append alpha * r (i.e., a scaled copy of r) to the bottom of A. | |
| void | addMatrix (const Matrix &B) |
| Append copies of the rows of matrix B to the bottom of A. | |
| void | addMatrix (const Matrix &B, double alpha) |
| Append the matrix alpha * B (i.e., a scaled copy of B) to the bottom of A. | |
| void | addMatrix (const Matrix &B, const Vector &s) |
| Append matrix B scaled columnwise to the bottom of A. | |
| void | addUniqueRows (const Matrix &B, double epsilon) |
| Selectivly appends the rows which are unique to B to the bottom of A. | |
| void | operator= (const Matrix &B) |
| Copy matrix (A = B). | |
| void | transpose (const Matrix &B) |
| Copy transposed matrix (A = B'). | |
| void | scale (const Matrix &B, const Vector &s) |
| Copy and scale matrix. | |
| void | scale (const Vector &s) |
| Scale matrix. | |
| void | setToIdentity (int n) |
| Sets A = I, an n by n identity matrix. | |
| void | normalize () |
| Normalizes the rows of A. | |
Calculations involving A | |
| void | multVec (const Vector &x, Vector &y, TransposeType ttype=NoTranspose) const |
| Compute y = Ax (or y = A'x if ttype = Transpose). | |
| void | svd (Matrix &U, Vector &s, Matrix &VT) const |
| Compute the singular value decomposition (SVD) of A. | |
| void | multMat (const Matrix &B, TransposeType ttype=NoTranspose) |
| On exit A = A*B if ttype = NoTranspose, and A = A*B' otherwise. | |
| void | multMat (const Matrix &B, Matrix &C, TransposeType ttype=NoTranspose) const |
| On exit C = A*B if ttype = NoTranspose, and C = A*B' otherwise. | |
| void | nullSpace (Matrix &ZT, double tol) const |
| On exit the rows of ZT form an orthonormal basis for null(A). | |
| bool | getRighInvAndNullBasis (Matrix &RT, Matrix &NT, double tol) const |
| Computes right inverse and null space basis matrix for A (if possible). | |
| void | pruneDependentRows (Vector &b, double epsilon) |
| Deletes dependent rows of A and corresponding entries in b. On exit, Ax = b forms a consistent system. | |
| void | constrainedLSQR (Vector &x, const Vector &b) const |
| Solve a constrained least-squares problem for the case when A has full row rank. | |
Printing help | |
| ostream & | leftshift (ostream &stream) const |
| Print object to the given stream | |
Private Member Functions | |
| void | matrixChanged () |
| Sets fmatvecSet and fmatvecTSet to false. | |
| const Vector & | getMatrixVector (TransposeType ttype=NoTranspose) const |
| Private member variables fmatvec and fmatvecTSet should never be access directly. Instead method getMatrixVector() should be called. If ttype equals NoTranspose, A is returns as a single vector stored column-wise. If ttype equals Transpose, A is returns as a single vector stored row-wise. | |
| void | copyToFortranVector (Vector &Avec, TransposeType ttype=NoTranspose) const |
| Converts A to a Fortran-style vector. | |
| void | copyFromFortranVector (const Vector &Avec, int nrows, int ncols, TransposeType ttype=NoTranspose) |
| Unpack A from a Fortran-style vector. | |
| void | resize (int m, int n) |
| Resize A to have m rows and n columns. | |
| void | copySubMatrix (int istart, int iextent, const Matrix &B) |
| Sets A equal to the specified block-row submatrix of B. | |
| void | multMatWithBlas (const APPSPACK::Matrix &Bin, APPSPACK::Matrix &C, TransposeType ttype) const |
| Performs a matrix multiply using Blas 3 routine DGEMM_F77(). | |
| void | multMatWithoutBlas (const APPSPACK::Matrix &Bin, APPSPACK::Matrix &C, TransposeType ttype) const |
| Performs a matrix multiply by hand without blas subroutines. | |
| void | multVecWithBlas (const Vector &x, Vector &y, TransposeType ttype=NoTranspose) const |
| Performs a matrix-vector multiply with Blas subroutine DGEMV_F77(). | |
| void | multVecWithoutBlas (const Vector &x, Vector &y, TransposeType ttype=NoTranspose) const |
| Performs a matrix-vector multiply by hand without blas subroutines. | |
Private Attributes | |
| vector< Vector > | matrix |
| The matrix A. | |
Vectorized matrix storage. | |
| Vector | fmatvec |
| bool | fmatvecSet |
| Vector | fmatvecT |
| bool | fmatvecTSet |
|
|
Indicator for transpose operations.
Definition at line 74 of file APPSPACK_Matrix.hpp. |
|
|
Constructor. Creates an empty matrix.
Definition at line 43 of file APPSPACK_Matrix.cpp. |
|
||||||||||||
|
Copy constructor. Sets A = B (or A = B' if ttype = Transpose). Definition at line 49 of file APPSPACK_Matrix.cpp. References operator=(), and transpose(). |
|
||||||||||||||||
|
Copy constructor with scaling. Copies B into A and scales column j by s[j]. In other words,
If ttype = Transpose, the
Definition at line 59 of file APPSPACK_Matrix.cpp. References operator=(), scale(), and transpose(). |
|
||||||||||||||||
|
Resizes A to be nrows by ncols. Sets A(i,j) = Aptr[i][j].
Definition at line 70 of file APPSPACK_Matrix.cpp. |
|
|
Destructor.
Definition at line 80 of file APPSPACK_Matrix.cpp. |
|
|
|
|
Returns number of columns in A.
Definition at line 94 of file APPSPACK_Matrix.cpp. References matrix. Referenced by addRow(), addUniqueRows(), APPSPACK::Directions::buildWithLapack(), constrainedLSQR(), copyToFortranVector(), APPSPACK::Constraints::Linear::formSnapSystem(), getRighInvAndNullBasis(), leftshift(), multMat(), multMatWithBlas(), multMatWithoutBlas(), multVec(), multVecWithBlas(), multVecWithoutBlas(), nullSpace(), pruneDependentRows(), scale(), APPSPACK::Constraints::Linear::setupMatrix(), APPSPACK::Constraints::Linear::setupScaledSystem(), svd(), and transpose(). |
|
|
Return ith row of A.
Definition at line 102 of file APPSPACK_Matrix.cpp. References getNrows(), and matrix. Referenced by addMatrix(), addUniqueRows(), APPSPACK::Directions::buildNormalCone(), copySubMatrix(), APPSPACK::Constraints::Linear::formSnapSystem(), APPSPACK::Directions::getDirection(), APPSPACK::Constraints::Linear::getEqState(), APPSPACK::Constraints::Linear::getIneqState(), APPSPACK::Directions::print(), and APPSPACK::Constraints::Linear::setupScaledSystem(). |
|
|
On exit Aptr[i] points to row i of A.
Definition at line 114 of file APPSPACK_Matrix.cpp. References getNrows(), matrix, matrixChanged(), and APPSPACK::Vector::push_back(). |
|
|
Empty the matrix A.
Definition at line 121 of file APPSPACK_Matrix.cpp. References matrixChanged(), and resize(). Referenced by APPSPACK::Directions::buildWithCddlib(), APPSPACK::Directions::buildWithLapack(), APPSPACK::Directions::buildWithNothing(), copySubMatrix(), APPSPACK::Constraints::Linear::formSnapSystem(), APPSPACK::Directions::generateForLinear(), APPSPACK::Directions::generateUnconstrained(), and getRighInvAndNullBasis(). |
|
|
Append a copy of r to the bottom of A.
Definition at line 127 of file APPSPACK_Matrix.cpp. References getNcols(), matrix, matrixChanged(), APPSPACK::Vector::push_back(), and APPSPACK::Vector::size(). Referenced by addMatrix(), addRow(), addUniqueRows(), APPSPACK::Directions::buildNormalCone(), APPSPACK::Directions::buildWithNothing(), copySubMatrix(), APPSPACK::Constraints::Linear::formSnapSystem(), APPSPACK::Directions::generateUnconstrained(), and APPSPACK::processTextInputFileLine(). |
|
|
Deletes the ith row of A.
Definition at line 140 of file APPSPACK_Matrix.cpp. References APPSPACK::Vector::erase(), getNrows(), matrix, and matrixChanged(). Referenced by normalize(), and pruneDependentRows(). |
|
||||||||||||
|
Append alpha * r (i.e., a scaled copy of r) to the bottom of A.
Definition at line 153 of file APPSPACK_Matrix.cpp. References addRow(), matrix, matrixChanged(), and APPSPACK::Vector::scale(). |
|
|
Append copies of the rows of matrix B to the bottom of A.
Definition at line 160 of file APPSPACK_Matrix.cpp. References addRow(), getNrows(), getRow(), and matrixChanged(). Referenced by APPSPACK::Directions::addNormalDirections(), APPSPACK::Directions::buildNormalCone(), APPSPACK::Directions::buildWithCddlib(), APPSPACK::Directions::buildWithLapack(), and APPSPACK::Constraints::Linear::setupScaledSystem(). |
|
||||||||||||
|
Append the matrix alpha * B (i.e., a scaled copy of B) to the bottom of A.
Definition at line 167 of file APPSPACK_Matrix.cpp. References addRow(), getNrows(), getRow(), and matrixChanged(). |
|
||||||||||||
|
Append matrix B scaled columnwise to the bottom of A.
In other words the matrix
Definition at line 174 of file APPSPACK_Matrix.cpp. References addRow(), getNrows(), getRow(), matrix, matrixChanged(), and APPSPACK::Vector::scale(). |
|
||||||||||||
|
Selectivly appends the rows which are unique to B to the bottom of A.
In other words, the ith row
Here
Definition at line 184 of file APPSPACK_Matrix.cpp. References addRow(), getNcols(), getNrows(), getRow(), matrixChanged(), and APPSPACK::Vector::norm(). Referenced by APPSPACK::Directions::addCompassDirections(), and APPSPACK::Directions::appendNewDirections(). |
|
|
Copy matrix (A = B).
Definition at line 213 of file APPSPACK_Matrix.cpp. References matrix, and matrixChanged(). Referenced by Matrix(). |
|
|
Copy transposed matrix (A = B').
Definition at line 219 of file APPSPACK_Matrix.cpp. References getNcols(), getNrows(), matrix, matrixChanged(), and resize(). Referenced by Matrix(). |
|
||||||||||||
|
Copy and scale matrix. Copies B into A and scales column j by s[j]. In other words,
Definition at line 232 of file APPSPACK_Matrix.cpp. References matrix, and matrixChanged(). Referenced by APPSPACK::Directions::addCompassDirections(), APPSPACK::Directions::addNormalDirections(), APPSPACK::Directions::buildWithCddlib(), APPSPACK::Directions::buildWithLapack(), getRighInvAndNullBasis(), Matrix(), and APPSPACK::Constraints::Linear::setupScaledSystem(). |
|
|
Scale matrix. Scales column j by s[j]. In other words,
Definition at line 242 of file APPSPACK_Matrix.cpp. References getNcols(), getNrows(), matrix, and matrixChanged(). |
|
|
Sets A = I, an n by n identity matrix.
Definition at line 253 of file APPSPACK_Matrix.cpp. References matrix, matrixChanged(), resize(), and APPSPACK::Vector::zero(). Referenced by APPSPACK::Directions::buildWithLapack(), and APPSPACK::Constraints::Linear::setupScaledSystem(). |
|
|
Normalizes the rows of A.
Definition at line 264 of file APPSPACK_Matrix.cpp. References deleteRow(), getNrows(), matrix, matrixChanged(), APPSPACK::Vector::norm(), and APPSPACK::Vector::scale(). Referenced by APPSPACK::Directions::addCompassDirections(), APPSPACK::Directions::addNormalDirections(), APPSPACK::Directions::buildWithCddlib(), and APPSPACK::Directions::buildWithLapack(). |
|
||||||||||||||||
|
Compute y = Ax (or y = A'x if ttype = Transpose).
Definition at line 277 of file APPSPACK_Matrix.cpp. References getNcols(), getNrows(), multVecWithBlas(), multVecWithoutBlas(), and APPSPACK::Vector::size(). Referenced by APPSPACK::Constraints::Linear::formDistanceVector(), APPSPACK::Constraints::Linear::formSnapSystem(), APPSPACK::Constraints::Linear::maxStep(), and APPSPACK::Constraints::Linear::setupScaledSystem(). |
|
||||||||||||||||
|
Compute the singular value decomposition (SVD) of A.
Compute
with
Definition at line 320 of file APPSPACK_Matrix.cpp. References copyFromFortranVector(), APPSPACK::DGESVD_F77(), getMatrixVector(), getNcols(), getNrows(), and APPSPACK::Vector::resize(). Referenced by getRighInvAndNullBasis(), and nullSpace(). |
|
||||||||||||
|
On exit A = A*B if ttype = NoTranspose, and A = A*B' otherwise.
Definition at line 363 of file APPSPACK_Matrix.cpp. References matrix, and matrixChanged(). Referenced by APPSPACK::Directions::addCompassDirections(), APPSPACK::Directions::addNormalDirections(), APPSPACK::Directions::buildWithLapack(), getRighInvAndNullBasis(), and APPSPACK::Constraints::Linear::setupScaledSystem(). |
|
||||||||||||||||
|
On exit C = A*B if ttype = NoTranspose, and C = A*B' otherwise.
Definition at line 372 of file APPSPACK_Matrix.cpp. References getNcols(), getNrows(), multMatWithBlas(), and multMatWithoutBlas(). |
|
||||||||||||
|
On exit the rows of ZT form an orthonormal basis for null(A).
Definition at line 403 of file APPSPACK_Matrix.cpp. References copySubMatrix(), getNcols(), getNrows(), APPSPACK::Vector::size(), and svd(). Referenced by APPSPACK::Directions::addCompassDirections(), APPSPACK::Directions::addNormalDirections(), APPSPACK::Directions::buildWithLapack(), and APPSPACK::Constraints::Linear::setupScaledSystem(). |
|
||||||||||||||||
|
Computes right inverse and null space basis matrix for A (if possible).
Let A be an
Definition at line 436 of file APPSPACK_Matrix.cpp. References clear(), copySubMatrix(), getNcols(), getNrows(), multMat(), scale(), APPSPACK::Vector::size(), and svd(). Referenced by APPSPACK::Directions::buildWithLapack(). |
|
||||||||||||
|
Deletes dependent rows of A and corresponding entries in b. On exit, Ax = b forms a consistent system.
Dependent rows are determined as follows:
An LQ factorization of A is first computed, where L denotes a lower triangular matrix and Q an orthogonal matrix. In exact arithmetic, the nonzero diagonal entries of L correspond to a linearly independent subset of the rows of A. To allow for numerical round off, row
Definition at line 475 of file APPSPACK_Matrix.cpp. References deleteRow(), APPSPACK::DGELQF_F77(), APPSPACK::Vector::erase(), getMatrixVector(), getNcols(), getNrows(), matrixChanged(), and NoTranspose. Referenced by APPSPACK::Constraints::Linear::formSnapSystem(). |
|
||||||||||||
|
Solve a constrained least-squares problem for the case when A has full row rank.
using LAPACK function DGGLSE_F77().
Definition at line 502 of file APPSPACK_Matrix.cpp. References APPSPACK::DGGLSE_F77(), empty(), getMatrixVector(), getNcols(), and getNrows(). Referenced by APPSPACK::Constraints::Linear::snapToBoundary(). |
|
|
Print object to the given stream
Definition at line 528 of file APPSPACK_Matrix.cpp. References APPSPACK::Print::formatDouble(), getNcols(), getNrows(), and matrix. Referenced by operator<<(). |
|
|
Sets fmatvecSet and fmatvecTSet to false. Should be called inside ever non-const method. Definition at line 542 of file APPSPACK_Matrix.cpp. References fmatvecSet, and fmatvecTSet. Referenced by addMatrix(), addRow(), addUniqueRows(), clear(), copyFromFortranVector(), copySubMatrix(), deleteRow(), getRowPointers(), multMat(), normalize(), operator=(), pruneDependentRows(), resize(), scale(), setToIdentity(), and transpose(). |
|
|
Private member variables fmatvec and fmatvecTSet should never be access directly. Instead method getMatrixVector() should be called. If ttype equals NoTranspose, A is returns as a single vector stored column-wise. If ttype equals Transpose, A is returns as a single vector stored row-wise.
Definition at line 548 of file APPSPACK_Matrix.cpp. References copyToFortranVector(), fmatvec, fmatvecSet, fmatvecT, and fmatvecTSet. Referenced by constrainedLSQR(), multMatWithBlas(), multVecWithBlas(), pruneDependentRows(), and svd(). |
|
||||||||||||
|
Converts A to a Fortran-style vector. Converts A to a vector stored columnwise so that the vector representation is
The index mapping is:
Store A' instead if ttype = Transpose Definition at line 570 of file APPSPACK_Matrix.cpp. References APPSPACK::Vector::append(), getNcols(), getNrows(), matrix, APPSPACK::Vector::push_back(), APPSPACK::Vector::reserve(), and APPSPACK::Vector::resize(). Referenced by getMatrixVector(). |
|
||||||||||||||||||||
|
Unpack A from a Fortran-style vector. Assumes A' is stored in the vector if ttype = Transpose Definition at line 595 of file APPSPACK_Matrix.cpp. References matrix, matrixChanged(), and resize(). Referenced by multMatWithBlas(), and svd(). |
|
||||||||||||
|
Resize A to have m rows and n columns.
Definition at line 624 of file APPSPACK_Matrix.cpp. References matrix, matrixChanged(), and APPSPACK::Vector::resize(). Referenced by clear(), copyFromFortranVector(), APPSPACK::Constraints::Linear::getActiveIndex(), Matrix(), multMatWithoutBlas(), setToIdentity(), and transpose(). |
|
||||||||||||||||
|
Sets A equal to the specified block-row submatrix of B.
where Definition at line 633 of file APPSPACK_Matrix.cpp. References addRow(), clear(), getNrows(), getRow(), and matrixChanged(). Referenced by getRighInvAndNullBasis(), and nullSpace(). |
|
||||||||||||||||
|
Performs a matrix multiply using Blas 3 routine DGEMM_F77(). On exit C = A*B if ttype = NoTranspose, and C = A*B' otherwise.
Definition at line 648 of file APPSPACK_Matrix.cpp. References copyFromFortranVector(), APPSPACK::DGEMM_F77(), getMatrixVector(), getNcols(), getNrows(), and Transpose. Referenced by multMat(). |
|
||||||||||||||||
|
Performs a matrix multiply by hand without blas subroutines. On exit C = A*B if ttype = NoTranspose, and C = A*B' otherwise. Definition at line 698 of file APPSPACK_Matrix.cpp. References getNcols(), getNrows(), matrix, and resize(). Referenced by multMat(). |
|
||||||||||||||||
|
Performs a matrix-vector multiply with Blas subroutine DGEMV_F77(). Computes y = Ax (or y = A'x if ttype = Transpose).
Definition at line 754 of file APPSPACK_Matrix.cpp. References APPSPACK::DGEMV_F77(), getMatrixVector(), getNcols(), and getNrows(). Referenced by multVec(). |
|
||||||||||||||||
|
Performs a matrix-vector multiply by hand without blas subroutines. Computes y = Ax (or y = A'x if ttype = Transpose). Definition at line 733 of file APPSPACK_Matrix.cpp. References getNcols(), getNrows(), matrix, and APPSPACK::Vector::zero(). Referenced by multVec(). |
|
|
The matrix A. The matrix is stored rowwise, i.e., matrix[i] is row i of A. and matrix[i][j] is A_ij. Definition at line 414 of file APPSPACK_Matrix.hpp. Referenced by addMatrix(), addRow(), copyFromFortranVector(), copyToFortranVector(), deleteRow(), empty(), getNcols(), getNrows(), getRow(), getRowPointers(), leftshift(), Matrix(), multMat(), multMatWithoutBlas(), multVecWithoutBlas(), normalize(), o |