Loading isis/src/base/objs/SparseBlockMatrix/SparseBlockMatrix.cpp +50 −44 Original line number Diff line number Diff line #include "SparseBlockMatrix.h" #include <boost/numeric/ublas/matrix_sparse.hpp> #include <boost/numeric/ublas/matrix_proxy.hpp> #include <boost/numeric/ublas/io.hpp> // std lib #include <iostream> #include <iomanip> // qt lib #include <QDataStream> #include <QDebug> #include <QMapIterator> #include <QListIterator> // boost lib #include <boost/numeric/ublas/matrix_sparse.hpp> #include <boost/numeric/ublas/matrix_proxy.hpp> #include <boost/numeric/ublas/io.hpp> // Isis lib #include "IString.h" #include "LinearAlgebra.h" using namespace boost::numeric::ublas; Loading Loading @@ -56,12 +61,12 @@ namespace Isis { wipe(); // copy matrix blocks from src QMapIterator<int, matrix<double>*> it(src); QMapIterator<int, LinearAlgebra::Matrix *> it(src); while ( it.hasNext() ) { it.next(); // copy matrix block from src matrix<double>* m = new matrix<double>(*(it.value())); LinearAlgebra::Matrix *m = new LinearAlgebra::Matrix(*(it.value())); // insert matrix into map this->insert(it.key(),m); Loading @@ -86,8 +91,8 @@ namespace Isis { /** * Inserts a "newed" boost matrix<double>* of size (nRows, nCols) into the map with the block * column number as key. The matrix::clear call initializes the matrix elements to zero. If an * Inserts a "newed" LinearAlgebra::Matrix pointer of size (nRows, nCols) into the map with the * block column number as key. The clear call initializes the matrix elements to zero. If an * entry exists at the key nColumnBlock, no insertion is made. * * @param nColumnBlock block column number of inserted matrix (key into map) Loading @@ -103,7 +108,7 @@ namespace Isis { return true; // allocate matrix block with nRows and nCols matrix<double>* m = new matrix<double>(nRows,nCols); LinearAlgebra::Matrix *m = new LinearAlgebra::Matrix(nRows,nCols); if ( !m ) return false; Loading @@ -127,7 +132,7 @@ namespace Isis { int SparseBlockColumnMatrix::numberOfElements() { int nElements = 0; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading @@ -150,7 +155,7 @@ namespace Isis { int nColumns = 0; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading @@ -174,7 +179,7 @@ namespace Isis { int SparseBlockColumnMatrix::numberOfRows() { // iterate to last block (the diagonal one) QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading Loading @@ -202,7 +207,7 @@ namespace Isis { } outstream << "Printing SparseBlockColumnMatrix..." << std::endl; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading @@ -228,11 +233,11 @@ namespace Isis { return; } QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); matrix<double>* m = it.value(); LinearAlgebra::Matrix * m = it.value(); int rows = m->size1(); int cols = m->size2(); Loading @@ -256,7 +261,7 @@ namespace Isis { * Sets all elements of all matrix blocks to zero. */ void SparseBlockColumnMatrix::zeroBlocks() { QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); it.value()->clear(); Loading @@ -275,7 +280,7 @@ namespace Isis { int nBlocks = sbcm.size(); stream << (qint32)nBlocks; QMapIterator<int, matrix<double>*> it(sbcm); QMapIterator<int, LinearAlgebra::Matrix *> it(sbcm); while ( it.hasNext() ) { it.next(); Loading Loading @@ -323,7 +328,7 @@ namespace Isis { sbcm.insertMatrixBlock(nBlockNumber, nRows, nCols); // get matrix matrix<double>* matrix = sbcm[nBlockNumber]; LinearAlgebra::Matrix *matrix = sbcm[nBlockNumber]; // fill with data for ( r = 0; r < nRows; r++ ) { Loading @@ -347,7 +352,7 @@ namespace Isis { QDebug operator<<(QDebug dbg, const SparseBlockColumnMatrix &sbcm) { dbg.space() << "New Block" << endl; QMapIterator<int, matrix<double>*> it(sbcm); QMapIterator<int, LinearAlgebra::Matrix *> it(sbcm); while ( it.hasNext() ) { it.next(); Loading @@ -355,7 +360,7 @@ namespace Isis { continue; // get matrix matrix<double>* matrix = it.value(); LinearAlgebra::Matrix *matrix = it.value(); // matrix rows, columns int nRows = matrix->size1(); Loading Loading @@ -419,12 +424,12 @@ namespace Isis { wipe(); // copy matrix blocks from src QMapIterator<int, matrix<double>*> it(src); QMapIterator<int, LinearAlgebra::Matrix *> it(src); while ( it.hasNext() ) { it.next(); // copy matrix block from src matrix<double>* m = new matrix<double>(*(it.value())); LinearAlgebra::Matrix *m = new LinearAlgebra::Matrix(*(it.value())); // insert matrix into map this->insert(it.key(),m); Loading @@ -449,9 +454,9 @@ namespace Isis { /** * Inserts a "newed" boost matrix<double>* of size (nRows, nCols) into the map with the block row * number as key. The matrix::clear call initializes the matrix elements to zero. If an entry * exists at the key nRowBlock, no insertion is made. * Inserts a "newed" LinearAlgebra::Matrix pointer of size (nRows, nCols) into the map with the * block row number as key. The matrix::clear call initializes the matrix elements to zero. If an * entry exists at the key nRowBlock, no insertion is made. * * @param nRowBlock block row number of inserted matrix (key into map) * @param nRows number of rows in matrix to be inserted Loading @@ -467,7 +472,7 @@ namespace Isis { if ( this->contains(nRowBlock) ) return false; matrix<double>* m = new matrix<double>(nRows,nCols); LinearAlgebra::Matrix *m = new LinearAlgebra::Matrix(nRows,nCols); if ( !m ) return false; Loading @@ -489,7 +494,7 @@ namespace Isis { int SparseBlockRowMatrix::numberOfElements() { int nElements = 0; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading @@ -515,7 +520,7 @@ namespace Isis { } outstream << "Printing SparseBlockRowMatrix..." << std::endl; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading @@ -540,11 +545,11 @@ namespace Isis { return; } QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); matrix<double>* m = it.value(); LinearAlgebra::Matrix *m = it.value(); int rows = m->size1(); int cols = m->size2(); Loading @@ -568,7 +573,7 @@ namespace Isis { * Sets all elements of all matrix blocks to zero. */ void SparseBlockRowMatrix::zeroBlocks() { QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); it.value()->clear(); Loading @@ -589,12 +594,12 @@ namespace Isis { range rRow = range(0,3); range rCol; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); nrowBlock = it.key(); matrix<double>* m = it.value(); LinearAlgebra::Matrix *m = it.value(); ncols = m->size2(); Loading Loading @@ -657,7 +662,7 @@ namespace Isis { int nBlocks = sbrm.size(); stream << (qint32)nBlocks; QMapIterator<int, matrix<double>*> it(sbrm); QMapIterator<int, LinearAlgebra::Matrix *> it(sbrm); while ( it.hasNext() ) { it.next(); Loading Loading @@ -705,7 +710,7 @@ namespace Isis { sbrm.insertMatrixBlock(nBlockNumber, nRows, nCols); // get matrix matrix<double>* matrix = sbrm[nBlockNumber]; LinearAlgebra::Matrix *matrix = sbrm[nBlockNumber]; // fill with data for ( r = 0; r < nRows; r++ ) { Loading @@ -729,7 +734,7 @@ namespace Isis { QDebug operator<<(QDebug dbg, const SparseBlockRowMatrix &sbrm) { dbg.space() << "New Block" << endl; QMapIterator<int, matrix<double>*> it(sbrm); QMapIterator<int, LinearAlgebra::Matrix *> it(sbrm); while ( it.hasNext() ) { it.next(); Loading @@ -737,7 +742,7 @@ namespace Isis { continue; // get matrix matrix<double>* matrix = it.value(); LinearAlgebra::Matrix *matrix = it.value(); // matrix rows, columns int nRows = matrix->size1(); Loading Loading @@ -839,9 +844,9 @@ namespace Isis { /** * Inserts a "newed" boost matrix<double>* of size (nRows, nCols) into the * matrix at nColumnBlock, nRowBlock. The inserted matrix elements are * initialized to zero. * Inserts a "newed" boost LinearAlgebra::Matrix pointer of size (nRows, * nCols) into the matrix at nColumnBlock, nRowBlock. The inserted matrix * elements are initialized to zero. * If an entry exists at nColumnBlock, RowBlock, no insertion is made. * * @param nColumnBlock block column number of inserted matrix (QList index) Loading Loading @@ -889,7 +894,7 @@ namespace Isis { if ( !column ) continue; QMapIterator<int, matrix<double>*> it(*column); QMapIterator<int, LinearAlgebra::Matrix *> it(*column); while ( it.hasNext() ) { it.next(); Loading Loading @@ -939,9 +944,10 @@ namespace Isis { * @param column block column number * @param row block row number * * @return matrix<double>* Pointer to Boost matrix at position (column, row) * @return LinearAlgebra::Matrix Pointer to Boost matrix at position (column, * row) */ matrix<double>* SparseBlockMatrix::getBlock(int column, int row) { LinearAlgebra::Matrix *SparseBlockMatrix::getBlock(int column, int row) { return (*(*this)[column])[row]; } Loading Loading @@ -1057,7 +1063,7 @@ namespace Isis { if ( !column ) continue; QMapIterator<int, matrix<double>*> it(*column); QMapIterator<int, LinearAlgebra::Matrix *> it(*column); // iterate to last element in column while ( it.hasNext() ) { it.next(); Loading isis/src/base/objs/SparseBlockMatrix/SparseBlockMatrix.h +17 −9 Original line number Diff line number Diff line Loading @@ -20,14 +20,20 @@ * http://www.usgs.gov/privacy.html. */ // std library #include <iostream> // Qt library #include <QMap> #include <QList> // boost library #include <boost/numeric/ublas/fwd.hpp> // Isis library #include "LinearAlgebra.h" // Qt library class QDebug; namespace Isis { Loading @@ -38,7 +44,7 @@ namespace Isis { * The SparseBlockMatrix class is a QList of SparseBlockColumnMatrix objects. Each * SparseBlockColumnMatrix is a QMap of square matrix blocks and represents a column of square * matrix blocks in the reduced normal equations matrix. The key into each column map is the * block’s row index. The value at each key is a square dense matrix (Boost matrix) with a * block's row index. The value at each key is a square dense matrix (Boost matrix) with a * dimension equivalent to the number of exterior orientation parameters used for the image. * Zero blocks are not stored. * Loading @@ -54,9 +60,11 @@ namespace Isis { * as recommended by Qt documentation. * @history 2015-12-18 Ken Edmundson - 1) added more detailed documentation; 2) brought up to * ISIS coding standards. * @history 2016-08-10 Jeannie Backer - Replaced boost matrix with Isis::LinearAlgebra::Matrix. * References #4163. */ class SparseBlockColumnMatrix : public QMap< int, boost::numeric::ublas::matrix<double>* > { public QMap< int, LinearAlgebra::Matrix * > { public: SparseBlockColumnMatrix(){} // default constructor Loading Loading @@ -115,7 +123,7 @@ namespace Isis { * to ISIS coding standards. */ class SparseBlockRowMatrix : public QMap< int, boost::numeric::ublas::matrix<double>* > { public QMap< int, LinearAlgebra::Matrix * > { public: SparseBlockRowMatrix(){} // default constructor Loading Loading @@ -193,7 +201,7 @@ namespace Isis { bool setNumberOfColumns( int n ); void zeroBlocks(); bool insertMatrixBlock(int nColumnBlock, int nRowBlock, int nRows, int nCols); boost::numeric::ublas::matrix<double>* getBlock(int column, int row); LinearAlgebra::Matrix *getBlock(int column, int row); int numberOfBlocks(); int numberOfDiagonalBlocks(); int numberOfOffDiagonalBlocks(); Loading isis/src/base/objs/SparseBlockMatrix/unitTest.cpp +6 −4 Original line number Diff line number Diff line #include "SparseBlockMatrix.h" // std lib #include <iostream> // boost lib #include <boost/numeric/ublas/matrix.hpp> // Isis lib #include "IException.h" #include "Preference.h" #include <boost/numeric/ublas/matrix.hpp> #include "SparseBlockMatrix.h" using namespace std; using namespace Isis; using boost::numeric::ublas::matrix; int main(int argc, char *argv[]) { Preference::Preferences(true); Loading isis/src/control/objs/BundleAdjust/BundleAdjust.cpp +38 −38 Original line number Diff line number Diff line Loading @@ -906,13 +906,13 @@ namespace Isis { m_bundleResults.setNumberObservations(0);// ??? m_bundleResults.resetNumberConstrainedPointParameters();//??? static boost::numeric::ublas::matrix<double> coeff_target; static boost::numeric::ublas::matrix<double> coeff_image; static boost::numeric::ublas::matrix<double> coeff_point3D(2, 3); static boost::numeric::ublas::vector<double> coeff_RHS(2); static LinearAlgebra::Matrix coeff_target; static LinearAlgebra::Matrix coeff_image; static LinearAlgebra::Matrix coeff_point3D(2, 3); static LinearAlgebra::Vector coeff_RHS(2); static boost::numeric::ublas::symmetric_matrix<double, upper> N22(3); // 3x3 upper triangular SparseBlockColumnMatrix N12; static boost::numeric::ublas::vector<double> n2(3); // 3x1 vector static LinearAlgebra::Vector n2(3); // 3x1 vector boost::numeric::ublas::compressed_vector<double> n1(m_nRank); // image parameters x 1 m_nj.resize(m_nRank); Loading Loading @@ -1116,7 +1116,7 @@ namespace Isis { int nImagePartials = coeff_image.size2(); static boost::numeric::ublas::vector<double> n1_image(nImagePartials); static LinearAlgebra::Vector n1_image(nImagePartials); n1_image.resize(nImagePartials); n1_image.clear(); Loading Loading @@ -1313,7 +1313,7 @@ namespace Isis { int n = 0; for (int i = 0; i < m_SparseNormals.size(); i++) { boost::numeric::ublas::matrix<double> *diagonalBlock = m_SparseNormals.getBlock(i, i); LinearAlgebra::Matrix *diagonalBlock = m_SparseNormals.getBlock(i, i); if ( !diagonalBlock ) continue; Loading Loading @@ -1343,8 +1343,8 @@ namespace Isis { else observation = m_bundleObservations.at(i); boost::numeric::ublas::vector< double > weights = observation->parameterWeights(); boost::numeric::ublas::vector< double > corrections = observation->parameterCorrections(); LinearAlgebra::Vector weights = observation->parameterWeights(); LinearAlgebra::Vector corrections = observation->parameterCorrections(); int blockSize = diagonalBlock->size1(); for (int j = 0; j < blockSize; j++) { Loading Loading @@ -1387,12 +1387,12 @@ namespace Isis { m_bundleResults.setNumberObservations(0); // ??? necessary??? m_bundleResults.resetNumberConstrainedPointParameters(); static boost::numeric::ublas::matrix<double> coeff_image; static boost::numeric::ublas::matrix<double> coeff_point3D(2, 3); static boost::numeric::ublas::vector<double> coeff_RHS(2); static LinearAlgebra::Matrix coeff_image; static LinearAlgebra::Matrix coeff_point3D(2, 3); static LinearAlgebra::Vector coeff_RHS(2); static boost::numeric::ublas::symmetric_matrix<double, upper> N22(3); // 3x3 upper triangular static boost::numeric::ublas::matrix< double> N12(m_nRank, 3); // image parameters x 3 (should this be compressed? We only make one, so probably not) static boost::numeric::ublas::vector<double> n2(3); // 3x1 vector static LinearAlgebra::Matrix N12(m_nRank, 3); // image parameters x 3 (should this be compressed? We only make one, so probably not) static LinearAlgebra::Vector n2(3); // 3x1 vector boost::numeric::ublas::compressed_vector<double> n1(m_nRank); // image parameters x 1 m_nj.resize(m_nRank); Loading Loading @@ -1726,7 +1726,7 @@ namespace Isis { SparseBlockRowMatrix &Q, vector<double> &v1) { QMapIterator< int, boost::numeric::ublas::matrix<double> * > iQ(Q); QMapIterator< int, LinearAlgebra::Matrix * > iQ(Q); // subrange start, end int srStart, srEnd; Loading Loading @@ -1755,7 +1755,7 @@ namespace Isis { SparseBlockColumnMatrix &N12, SparseBlockRowMatrix &Q) { QMapIterator< int, boost::numeric::ublas::matrix<double> * > iN12(N12); QMapIterator< int, LinearAlgebra::Matrix * > iN12(N12); while ( iN12.hasNext() ) { iN12.next(); Loading Loading @@ -1788,15 +1788,15 @@ namespace Isis { } // iterators for N12 and Q QMapIterator<int, boost::numeric::ublas::matrix<double>*> iN12(N12); QMapIterator<int, boost::numeric::ublas::matrix<double>*> iQ(Q); QMapIterator<int, LinearAlgebra::Matrix*> iN12(N12); QMapIterator<int, LinearAlgebra::Matrix*> iQ(Q); // now multiply blocks and subtract from m_SparseNormals while ( iN12.hasNext() ) { iN12.next(); int nrow = iN12.key(); boost::numeric::ublas::matrix<double> *in12 = iN12.value(); LinearAlgebra::Matrix *in12 = iN12.value(); while ( iQ.hasNext() ) { iQ.next(); Loading @@ -1806,7 +1806,7 @@ namespace Isis { if ( nrow > ncol ) continue; boost::numeric::ublas::matrix<double> *iq = iQ.value(); LinearAlgebra::Matrix *iq = iQ.value(); // insert submatrix at column, row m_SparseNormals.insertMatrixBlock(ncol, nrow, Loading Loading @@ -1886,15 +1886,15 @@ namespace Isis { int nTargetParameters = m_bundleSettings->numberTargetBodyParameters(); QMapIterator<int, boost::numeric::ublas::matrix<double>*> iQ(Q); QMapIterator<int, LinearAlgebra::Matrix*> iQ(Q); while ( iQ.hasNext() ) { iQ.next(); int nrow = iQ.key(); boost::numeric::ublas::matrix<double> *m = iQ.value(); LinearAlgebra::Matrix *m = iQ.value(); boost::numeric::ublas::vector<double> v = prod(trans(*m),n2); LinearAlgebra::Vector v = prod(trans(*m),n2); //testing - should ask m_bundleObservations for this??? // int n = Q.getLeadingColumnsForBlock(nrow); Loading Loading @@ -2208,7 +2208,7 @@ namespace Isis { int nLeadingColumns = m_SparseNormals.getLeadingColumnsForBlock(ncol); QMapIterator< int, boost::numeric::ublas::matrix<double> * > it(*sbc); QMapIterator< int, LinearAlgebra::Matrix * > it(*sbc); while ( it.hasNext() ) { it.next(); Loading @@ -2217,7 +2217,7 @@ namespace Isis { int nLeadingRows = m_SparseNormals.getLeadingRowsForBlock(nrow); boost::numeric::ublas::matrix<double> *m = it.value(); LinearAlgebra::Matrix *m = it.value(); if ( !m ) { printf("matrix block retrieval failure at column %d, row %d", ncol,nrow); printf("Total # of block columns: %d", nblockcolumns); Loading Loading @@ -2450,10 +2450,10 @@ namespace Isis { // symmetric_matrix<double,lower> tmp = m_Normals; // solution vector boost::numeric::ublas::vector<double> s(m_nRank); LinearAlgebra::Vector s(m_nRank); // initialize column vector boost::numeric::ublas::vector<double> column(m_nRank); LinearAlgebra::Vector column(m_nRank); column.clear(); column(0) = 1.0; Loading Loading @@ -3312,8 +3312,8 @@ namespace Isis { BundleObservationQsp observation = m_bundleObservations.at(i); // get weight and correction vector for this observation const boost::numeric::ublas::vector<double> &weights = observation->parameterWeights(); const boost::numeric::ublas::vector<double> &corrections = observation->parameterCorrections(); const LinearAlgebra::Vector &weights = observation->parameterWeights(); const LinearAlgebra::Vector &corrections = observation->parameterCorrections(); for (int j = 0; j < (int)corrections.size(); j++) { if (weights[j] > 0.0) { Loading Loading @@ -3628,8 +3628,8 @@ namespace Isis { if ( !CholeskyUT_NOSQR_Inverse() ) return false; boost::numeric::ublas::matrix<double> T(3, 3); boost::numeric::ublas::matrix<double> QS(3, m_nRank); LinearAlgebra::Matrix T(3, 3); LinearAlgebra::Matrix QS(3, m_nRank); double dSigmaLat, dSigmaLong, dSigmaRadius; double t; Loading Loading @@ -3706,7 +3706,7 @@ namespace Isis { cholmod_free_triplet(&m_pTriplet, &m_cm); cholmod_free_sparse(&m_N, &m_cm); boost::numeric::ublas::matrix<double> T(3, 3); LinearAlgebra::Matrix T(3, 3); double dSigmaLat, dSigmaLong, dSigmaRadius; double t; Loading Loading @@ -3796,7 +3796,7 @@ namespace Isis { // store solution in corresponding column of inverse for (k = 0; k < sbcMatrix.size(); k++) { boost::numeric::ublas::matrix<double> *matrix = sbcMatrix.value(k); LinearAlgebra::Matrix *matrix = sbcMatrix.value(k); int sz1 = matrix->size1(); Loading Loading @@ -3865,7 +3865,7 @@ namespace Isis { boost::numeric::ublas::symmetric_matrix<double> &cv = point_covs[nPointIndex]; // get qT - index i is the key into Q for qT boost::numeric::ublas::matrix<double> *qT = Q.value(i); LinearAlgebra::Matrix *qT = Q.value(i); if (!qT) { nPointIndex++; continue; Loading @@ -3873,7 +3873,7 @@ namespace Isis { // iterate over Q // q is current map value QMapIterator< int, boost::numeric::ublas::matrix<double> * > it(Q); QMapIterator< int, LinearAlgebra::Matrix * > it(Q); while ( it.hasNext() ) { it.next(); Loading @@ -3883,13 +3883,13 @@ namespace Isis { break; } boost::numeric::ublas::matrix<double> *q = it.value(); LinearAlgebra::Matrix *q = it.value(); if ( !q ) {// should never be NULL continue; } boost::numeric::ublas::matrix<double> *nI = sbcMatrix.value(it.key()); LinearAlgebra::Matrix *nI = sbcMatrix.value(it.key()); if ( !nI ) {// should never be NULL continue; Loading Loading @@ -5229,7 +5229,7 @@ namespace Isis { output_columns.clear(); // data structure to contain adjusted image parameter sigmas for CHOLMOD error propagation only boost::numeric::ublas::vector<double> vImageAdjustedSigmas; LinearAlgebra::Vector vImageAdjustedSigmas; std::vector<double> BFP(3); Loading isis/src/control/objs/BundleAdjust/BundleAdjust.h +62 −61 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
isis/src/base/objs/SparseBlockMatrix/SparseBlockMatrix.cpp +50 −44 Original line number Diff line number Diff line #include "SparseBlockMatrix.h" #include <boost/numeric/ublas/matrix_sparse.hpp> #include <boost/numeric/ublas/matrix_proxy.hpp> #include <boost/numeric/ublas/io.hpp> // std lib #include <iostream> #include <iomanip> // qt lib #include <QDataStream> #include <QDebug> #include <QMapIterator> #include <QListIterator> // boost lib #include <boost/numeric/ublas/matrix_sparse.hpp> #include <boost/numeric/ublas/matrix_proxy.hpp> #include <boost/numeric/ublas/io.hpp> // Isis lib #include "IString.h" #include "LinearAlgebra.h" using namespace boost::numeric::ublas; Loading Loading @@ -56,12 +61,12 @@ namespace Isis { wipe(); // copy matrix blocks from src QMapIterator<int, matrix<double>*> it(src); QMapIterator<int, LinearAlgebra::Matrix *> it(src); while ( it.hasNext() ) { it.next(); // copy matrix block from src matrix<double>* m = new matrix<double>(*(it.value())); LinearAlgebra::Matrix *m = new LinearAlgebra::Matrix(*(it.value())); // insert matrix into map this->insert(it.key(),m); Loading @@ -86,8 +91,8 @@ namespace Isis { /** * Inserts a "newed" boost matrix<double>* of size (nRows, nCols) into the map with the block * column number as key. The matrix::clear call initializes the matrix elements to zero. If an * Inserts a "newed" LinearAlgebra::Matrix pointer of size (nRows, nCols) into the map with the * block column number as key. The clear call initializes the matrix elements to zero. If an * entry exists at the key nColumnBlock, no insertion is made. * * @param nColumnBlock block column number of inserted matrix (key into map) Loading @@ -103,7 +108,7 @@ namespace Isis { return true; // allocate matrix block with nRows and nCols matrix<double>* m = new matrix<double>(nRows,nCols); LinearAlgebra::Matrix *m = new LinearAlgebra::Matrix(nRows,nCols); if ( !m ) return false; Loading @@ -127,7 +132,7 @@ namespace Isis { int SparseBlockColumnMatrix::numberOfElements() { int nElements = 0; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading @@ -150,7 +155,7 @@ namespace Isis { int nColumns = 0; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading @@ -174,7 +179,7 @@ namespace Isis { int SparseBlockColumnMatrix::numberOfRows() { // iterate to last block (the diagonal one) QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading Loading @@ -202,7 +207,7 @@ namespace Isis { } outstream << "Printing SparseBlockColumnMatrix..." << std::endl; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading @@ -228,11 +233,11 @@ namespace Isis { return; } QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); matrix<double>* m = it.value(); LinearAlgebra::Matrix * m = it.value(); int rows = m->size1(); int cols = m->size2(); Loading @@ -256,7 +261,7 @@ namespace Isis { * Sets all elements of all matrix blocks to zero. */ void SparseBlockColumnMatrix::zeroBlocks() { QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); it.value()->clear(); Loading @@ -275,7 +280,7 @@ namespace Isis { int nBlocks = sbcm.size(); stream << (qint32)nBlocks; QMapIterator<int, matrix<double>*> it(sbcm); QMapIterator<int, LinearAlgebra::Matrix *> it(sbcm); while ( it.hasNext() ) { it.next(); Loading Loading @@ -323,7 +328,7 @@ namespace Isis { sbcm.insertMatrixBlock(nBlockNumber, nRows, nCols); // get matrix matrix<double>* matrix = sbcm[nBlockNumber]; LinearAlgebra::Matrix *matrix = sbcm[nBlockNumber]; // fill with data for ( r = 0; r < nRows; r++ ) { Loading @@ -347,7 +352,7 @@ namespace Isis { QDebug operator<<(QDebug dbg, const SparseBlockColumnMatrix &sbcm) { dbg.space() << "New Block" << endl; QMapIterator<int, matrix<double>*> it(sbcm); QMapIterator<int, LinearAlgebra::Matrix *> it(sbcm); while ( it.hasNext() ) { it.next(); Loading @@ -355,7 +360,7 @@ namespace Isis { continue; // get matrix matrix<double>* matrix = it.value(); LinearAlgebra::Matrix *matrix = it.value(); // matrix rows, columns int nRows = matrix->size1(); Loading Loading @@ -419,12 +424,12 @@ namespace Isis { wipe(); // copy matrix blocks from src QMapIterator<int, matrix<double>*> it(src); QMapIterator<int, LinearAlgebra::Matrix *> it(src); while ( it.hasNext() ) { it.next(); // copy matrix block from src matrix<double>* m = new matrix<double>(*(it.value())); LinearAlgebra::Matrix *m = new LinearAlgebra::Matrix(*(it.value())); // insert matrix into map this->insert(it.key(),m); Loading @@ -449,9 +454,9 @@ namespace Isis { /** * Inserts a "newed" boost matrix<double>* of size (nRows, nCols) into the map with the block row * number as key. The matrix::clear call initializes the matrix elements to zero. If an entry * exists at the key nRowBlock, no insertion is made. * Inserts a "newed" LinearAlgebra::Matrix pointer of size (nRows, nCols) into the map with the * block row number as key. The matrix::clear call initializes the matrix elements to zero. If an * entry exists at the key nRowBlock, no insertion is made. * * @param nRowBlock block row number of inserted matrix (key into map) * @param nRows number of rows in matrix to be inserted Loading @@ -467,7 +472,7 @@ namespace Isis { if ( this->contains(nRowBlock) ) return false; matrix<double>* m = new matrix<double>(nRows,nCols); LinearAlgebra::Matrix *m = new LinearAlgebra::Matrix(nRows,nCols); if ( !m ) return false; Loading @@ -489,7 +494,7 @@ namespace Isis { int SparseBlockRowMatrix::numberOfElements() { int nElements = 0; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading @@ -515,7 +520,7 @@ namespace Isis { } outstream << "Printing SparseBlockRowMatrix..." << std::endl; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); Loading @@ -540,11 +545,11 @@ namespace Isis { return; } QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); matrix<double>* m = it.value(); LinearAlgebra::Matrix *m = it.value(); int rows = m->size1(); int cols = m->size2(); Loading @@ -568,7 +573,7 @@ namespace Isis { * Sets all elements of all matrix blocks to zero. */ void SparseBlockRowMatrix::zeroBlocks() { QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); it.value()->clear(); Loading @@ -589,12 +594,12 @@ namespace Isis { range rRow = range(0,3); range rCol; QMapIterator<int, matrix<double>*> it(*this); QMapIterator<int, LinearAlgebra::Matrix *> it(*this); while ( it.hasNext() ) { it.next(); nrowBlock = it.key(); matrix<double>* m = it.value(); LinearAlgebra::Matrix *m = it.value(); ncols = m->size2(); Loading Loading @@ -657,7 +662,7 @@ namespace Isis { int nBlocks = sbrm.size(); stream << (qint32)nBlocks; QMapIterator<int, matrix<double>*> it(sbrm); QMapIterator<int, LinearAlgebra::Matrix *> it(sbrm); while ( it.hasNext() ) { it.next(); Loading Loading @@ -705,7 +710,7 @@ namespace Isis { sbrm.insertMatrixBlock(nBlockNumber, nRows, nCols); // get matrix matrix<double>* matrix = sbrm[nBlockNumber]; LinearAlgebra::Matrix *matrix = sbrm[nBlockNumber]; // fill with data for ( r = 0; r < nRows; r++ ) { Loading @@ -729,7 +734,7 @@ namespace Isis { QDebug operator<<(QDebug dbg, const SparseBlockRowMatrix &sbrm) { dbg.space() << "New Block" << endl; QMapIterator<int, matrix<double>*> it(sbrm); QMapIterator<int, LinearAlgebra::Matrix *> it(sbrm); while ( it.hasNext() ) { it.next(); Loading @@ -737,7 +742,7 @@ namespace Isis { continue; // get matrix matrix<double>* matrix = it.value(); LinearAlgebra::Matrix *matrix = it.value(); // matrix rows, columns int nRows = matrix->size1(); Loading Loading @@ -839,9 +844,9 @@ namespace Isis { /** * Inserts a "newed" boost matrix<double>* of size (nRows, nCols) into the * matrix at nColumnBlock, nRowBlock. The inserted matrix elements are * initialized to zero. * Inserts a "newed" boost LinearAlgebra::Matrix pointer of size (nRows, * nCols) into the matrix at nColumnBlock, nRowBlock. The inserted matrix * elements are initialized to zero. * If an entry exists at nColumnBlock, RowBlock, no insertion is made. * * @param nColumnBlock block column number of inserted matrix (QList index) Loading Loading @@ -889,7 +894,7 @@ namespace Isis { if ( !column ) continue; QMapIterator<int, matrix<double>*> it(*column); QMapIterator<int, LinearAlgebra::Matrix *> it(*column); while ( it.hasNext() ) { it.next(); Loading Loading @@ -939,9 +944,10 @@ namespace Isis { * @param column block column number * @param row block row number * * @return matrix<double>* Pointer to Boost matrix at position (column, row) * @return LinearAlgebra::Matrix Pointer to Boost matrix at position (column, * row) */ matrix<double>* SparseBlockMatrix::getBlock(int column, int row) { LinearAlgebra::Matrix *SparseBlockMatrix::getBlock(int column, int row) { return (*(*this)[column])[row]; } Loading Loading @@ -1057,7 +1063,7 @@ namespace Isis { if ( !column ) continue; QMapIterator<int, matrix<double>*> it(*column); QMapIterator<int, LinearAlgebra::Matrix *> it(*column); // iterate to last element in column while ( it.hasNext() ) { it.next(); Loading
isis/src/base/objs/SparseBlockMatrix/SparseBlockMatrix.h +17 −9 Original line number Diff line number Diff line Loading @@ -20,14 +20,20 @@ * http://www.usgs.gov/privacy.html. */ // std library #include <iostream> // Qt library #include <QMap> #include <QList> // boost library #include <boost/numeric/ublas/fwd.hpp> // Isis library #include "LinearAlgebra.h" // Qt library class QDebug; namespace Isis { Loading @@ -38,7 +44,7 @@ namespace Isis { * The SparseBlockMatrix class is a QList of SparseBlockColumnMatrix objects. Each * SparseBlockColumnMatrix is a QMap of square matrix blocks and represents a column of square * matrix blocks in the reduced normal equations matrix. The key into each column map is the * block’s row index. The value at each key is a square dense matrix (Boost matrix) with a * block's row index. The value at each key is a square dense matrix (Boost matrix) with a * dimension equivalent to the number of exterior orientation parameters used for the image. * Zero blocks are not stored. * Loading @@ -54,9 +60,11 @@ namespace Isis { * as recommended by Qt documentation. * @history 2015-12-18 Ken Edmundson - 1) added more detailed documentation; 2) brought up to * ISIS coding standards. * @history 2016-08-10 Jeannie Backer - Replaced boost matrix with Isis::LinearAlgebra::Matrix. * References #4163. */ class SparseBlockColumnMatrix : public QMap< int, boost::numeric::ublas::matrix<double>* > { public QMap< int, LinearAlgebra::Matrix * > { public: SparseBlockColumnMatrix(){} // default constructor Loading Loading @@ -115,7 +123,7 @@ namespace Isis { * to ISIS coding standards. */ class SparseBlockRowMatrix : public QMap< int, boost::numeric::ublas::matrix<double>* > { public QMap< int, LinearAlgebra::Matrix * > { public: SparseBlockRowMatrix(){} // default constructor Loading Loading @@ -193,7 +201,7 @@ namespace Isis { bool setNumberOfColumns( int n ); void zeroBlocks(); bool insertMatrixBlock(int nColumnBlock, int nRowBlock, int nRows, int nCols); boost::numeric::ublas::matrix<double>* getBlock(int column, int row); LinearAlgebra::Matrix *getBlock(int column, int row); int numberOfBlocks(); int numberOfDiagonalBlocks(); int numberOfOffDiagonalBlocks(); Loading
isis/src/base/objs/SparseBlockMatrix/unitTest.cpp +6 −4 Original line number Diff line number Diff line #include "SparseBlockMatrix.h" // std lib #include <iostream> // boost lib #include <boost/numeric/ublas/matrix.hpp> // Isis lib #include "IException.h" #include "Preference.h" #include <boost/numeric/ublas/matrix.hpp> #include "SparseBlockMatrix.h" using namespace std; using namespace Isis; using boost::numeric::ublas::matrix; int main(int argc, char *argv[]) { Preference::Preferences(true); Loading
isis/src/control/objs/BundleAdjust/BundleAdjust.cpp +38 −38 Original line number Diff line number Diff line Loading @@ -906,13 +906,13 @@ namespace Isis { m_bundleResults.setNumberObservations(0);// ??? m_bundleResults.resetNumberConstrainedPointParameters();//??? static boost::numeric::ublas::matrix<double> coeff_target; static boost::numeric::ublas::matrix<double> coeff_image; static boost::numeric::ublas::matrix<double> coeff_point3D(2, 3); static boost::numeric::ublas::vector<double> coeff_RHS(2); static LinearAlgebra::Matrix coeff_target; static LinearAlgebra::Matrix coeff_image; static LinearAlgebra::Matrix coeff_point3D(2, 3); static LinearAlgebra::Vector coeff_RHS(2); static boost::numeric::ublas::symmetric_matrix<double, upper> N22(3); // 3x3 upper triangular SparseBlockColumnMatrix N12; static boost::numeric::ublas::vector<double> n2(3); // 3x1 vector static LinearAlgebra::Vector n2(3); // 3x1 vector boost::numeric::ublas::compressed_vector<double> n1(m_nRank); // image parameters x 1 m_nj.resize(m_nRank); Loading Loading @@ -1116,7 +1116,7 @@ namespace Isis { int nImagePartials = coeff_image.size2(); static boost::numeric::ublas::vector<double> n1_image(nImagePartials); static LinearAlgebra::Vector n1_image(nImagePartials); n1_image.resize(nImagePartials); n1_image.clear(); Loading Loading @@ -1313,7 +1313,7 @@ namespace Isis { int n = 0; for (int i = 0; i < m_SparseNormals.size(); i++) { boost::numeric::ublas::matrix<double> *diagonalBlock = m_SparseNormals.getBlock(i, i); LinearAlgebra::Matrix *diagonalBlock = m_SparseNormals.getBlock(i, i); if ( !diagonalBlock ) continue; Loading Loading @@ -1343,8 +1343,8 @@ namespace Isis { else observation = m_bundleObservations.at(i); boost::numeric::ublas::vector< double > weights = observation->parameterWeights(); boost::numeric::ublas::vector< double > corrections = observation->parameterCorrections(); LinearAlgebra::Vector weights = observation->parameterWeights(); LinearAlgebra::Vector corrections = observation->parameterCorrections(); int blockSize = diagonalBlock->size1(); for (int j = 0; j < blockSize; j++) { Loading Loading @@ -1387,12 +1387,12 @@ namespace Isis { m_bundleResults.setNumberObservations(0); // ??? necessary??? m_bundleResults.resetNumberConstrainedPointParameters(); static boost::numeric::ublas::matrix<double> coeff_image; static boost::numeric::ublas::matrix<double> coeff_point3D(2, 3); static boost::numeric::ublas::vector<double> coeff_RHS(2); static LinearAlgebra::Matrix coeff_image; static LinearAlgebra::Matrix coeff_point3D(2, 3); static LinearAlgebra::Vector coeff_RHS(2); static boost::numeric::ublas::symmetric_matrix<double, upper> N22(3); // 3x3 upper triangular static boost::numeric::ublas::matrix< double> N12(m_nRank, 3); // image parameters x 3 (should this be compressed? We only make one, so probably not) static boost::numeric::ublas::vector<double> n2(3); // 3x1 vector static LinearAlgebra::Matrix N12(m_nRank, 3); // image parameters x 3 (should this be compressed? We only make one, so probably not) static LinearAlgebra::Vector n2(3); // 3x1 vector boost::numeric::ublas::compressed_vector<double> n1(m_nRank); // image parameters x 1 m_nj.resize(m_nRank); Loading Loading @@ -1726,7 +1726,7 @@ namespace Isis { SparseBlockRowMatrix &Q, vector<double> &v1) { QMapIterator< int, boost::numeric::ublas::matrix<double> * > iQ(Q); QMapIterator< int, LinearAlgebra::Matrix * > iQ(Q); // subrange start, end int srStart, srEnd; Loading Loading @@ -1755,7 +1755,7 @@ namespace Isis { SparseBlockColumnMatrix &N12, SparseBlockRowMatrix &Q) { QMapIterator< int, boost::numeric::ublas::matrix<double> * > iN12(N12); QMapIterator< int, LinearAlgebra::Matrix * > iN12(N12); while ( iN12.hasNext() ) { iN12.next(); Loading Loading @@ -1788,15 +1788,15 @@ namespace Isis { } // iterators for N12 and Q QMapIterator<int, boost::numeric::ublas::matrix<double>*> iN12(N12); QMapIterator<int, boost::numeric::ublas::matrix<double>*> iQ(Q); QMapIterator<int, LinearAlgebra::Matrix*> iN12(N12); QMapIterator<int, LinearAlgebra::Matrix*> iQ(Q); // now multiply blocks and subtract from m_SparseNormals while ( iN12.hasNext() ) { iN12.next(); int nrow = iN12.key(); boost::numeric::ublas::matrix<double> *in12 = iN12.value(); LinearAlgebra::Matrix *in12 = iN12.value(); while ( iQ.hasNext() ) { iQ.next(); Loading @@ -1806,7 +1806,7 @@ namespace Isis { if ( nrow > ncol ) continue; boost::numeric::ublas::matrix<double> *iq = iQ.value(); LinearAlgebra::Matrix *iq = iQ.value(); // insert submatrix at column, row m_SparseNormals.insertMatrixBlock(ncol, nrow, Loading Loading @@ -1886,15 +1886,15 @@ namespace Isis { int nTargetParameters = m_bundleSettings->numberTargetBodyParameters(); QMapIterator<int, boost::numeric::ublas::matrix<double>*> iQ(Q); QMapIterator<int, LinearAlgebra::Matrix*> iQ(Q); while ( iQ.hasNext() ) { iQ.next(); int nrow = iQ.key(); boost::numeric::ublas::matrix<double> *m = iQ.value(); LinearAlgebra::Matrix *m = iQ.value(); boost::numeric::ublas::vector<double> v = prod(trans(*m),n2); LinearAlgebra::Vector v = prod(trans(*m),n2); //testing - should ask m_bundleObservations for this??? // int n = Q.getLeadingColumnsForBlock(nrow); Loading Loading @@ -2208,7 +2208,7 @@ namespace Isis { int nLeadingColumns = m_SparseNormals.getLeadingColumnsForBlock(ncol); QMapIterator< int, boost::numeric::ublas::matrix<double> * > it(*sbc); QMapIterator< int, LinearAlgebra::Matrix * > it(*sbc); while ( it.hasNext() ) { it.next(); Loading @@ -2217,7 +2217,7 @@ namespace Isis { int nLeadingRows = m_SparseNormals.getLeadingRowsForBlock(nrow); boost::numeric::ublas::matrix<double> *m = it.value(); LinearAlgebra::Matrix *m = it.value(); if ( !m ) { printf("matrix block retrieval failure at column %d, row %d", ncol,nrow); printf("Total # of block columns: %d", nblockcolumns); Loading Loading @@ -2450,10 +2450,10 @@ namespace Isis { // symmetric_matrix<double,lower> tmp = m_Normals; // solution vector boost::numeric::ublas::vector<double> s(m_nRank); LinearAlgebra::Vector s(m_nRank); // initialize column vector boost::numeric::ublas::vector<double> column(m_nRank); LinearAlgebra::Vector column(m_nRank); column.clear(); column(0) = 1.0; Loading Loading @@ -3312,8 +3312,8 @@ namespace Isis { BundleObservationQsp observation = m_bundleObservations.at(i); // get weight and correction vector for this observation const boost::numeric::ublas::vector<double> &weights = observation->parameterWeights(); const boost::numeric::ublas::vector<double> &corrections = observation->parameterCorrections(); const LinearAlgebra::Vector &weights = observation->parameterWeights(); const LinearAlgebra::Vector &corrections = observation->parameterCorrections(); for (int j = 0; j < (int)corrections.size(); j++) { if (weights[j] > 0.0) { Loading Loading @@ -3628,8 +3628,8 @@ namespace Isis { if ( !CholeskyUT_NOSQR_Inverse() ) return false; boost::numeric::ublas::matrix<double> T(3, 3); boost::numeric::ublas::matrix<double> QS(3, m_nRank); LinearAlgebra::Matrix T(3, 3); LinearAlgebra::Matrix QS(3, m_nRank); double dSigmaLat, dSigmaLong, dSigmaRadius; double t; Loading Loading @@ -3706,7 +3706,7 @@ namespace Isis { cholmod_free_triplet(&m_pTriplet, &m_cm); cholmod_free_sparse(&m_N, &m_cm); boost::numeric::ublas::matrix<double> T(3, 3); LinearAlgebra::Matrix T(3, 3); double dSigmaLat, dSigmaLong, dSigmaRadius; double t; Loading Loading @@ -3796,7 +3796,7 @@ namespace Isis { // store solution in corresponding column of inverse for (k = 0; k < sbcMatrix.size(); k++) { boost::numeric::ublas::matrix<double> *matrix = sbcMatrix.value(k); LinearAlgebra::Matrix *matrix = sbcMatrix.value(k); int sz1 = matrix->size1(); Loading Loading @@ -3865,7 +3865,7 @@ namespace Isis { boost::numeric::ublas::symmetric_matrix<double> &cv = point_covs[nPointIndex]; // get qT - index i is the key into Q for qT boost::numeric::ublas::matrix<double> *qT = Q.value(i); LinearAlgebra::Matrix *qT = Q.value(i); if (!qT) { nPointIndex++; continue; Loading @@ -3873,7 +3873,7 @@ namespace Isis { // iterate over Q // q is current map value QMapIterator< int, boost::numeric::ublas::matrix<double> * > it(Q); QMapIterator< int, LinearAlgebra::Matrix * > it(Q); while ( it.hasNext() ) { it.next(); Loading @@ -3883,13 +3883,13 @@ namespace Isis { break; } boost::numeric::ublas::matrix<double> *q = it.value(); LinearAlgebra::Matrix *q = it.value(); if ( !q ) {// should never be NULL continue; } boost::numeric::ublas::matrix<double> *nI = sbcMatrix.value(it.key()); LinearAlgebra::Matrix *nI = sbcMatrix.value(it.key()); if ( !nI ) {// should never be NULL continue; Loading Loading @@ -5229,7 +5229,7 @@ namespace Isis { output_columns.clear(); // data structure to contain adjusted image parameter sigmas for CHOLMOD error propagation only boost::numeric::ublas::vector<double> vImageAdjustedSigmas; LinearAlgebra::Vector vImageAdjustedSigmas; std::vector<double> BFP(3); Loading
isis/src/control/objs/BundleAdjust/BundleAdjust.h +62 −61 File changed.Preview size limit exceeded, changes collapsed. Show changes