Commit 8569b508 authored by Jeannie Backer's avatar Jeannie Backer
Browse files

PROG: Added new methods to SparseBlockMatrix and improved documentation,...

PROG: Added new methods to SparseBlockMatrix and improved documentation, coding standards, and test coverage. Merged from IPCE branch.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6494 41f8697f-d340-4b68-9986-7bafba869bb8
parent 8e0fdb5b
Loading
Loading
Loading
Loading
+332 −51
Original line number Diff line number Diff line
@@ -25,9 +25,8 @@ namespace Isis {


  /**
   * Deletes all pointer elements and removes them from the map.
   * Effectively, a destructor, and in fact, called by the
   * ~SparseBlockColumnMatrix above.
   * Deletes all pointer elements and removes them from the map. Effectively, a destructor, and in
   *  fact, called by the ~SparseBlockColumnMatrix above.
   */
  void SparseBlockColumnMatrix::wipe() {
    qDeleteAll(values());
@@ -37,6 +36,8 @@ namespace Isis {

  /**
   * Copy constructor. Calls copy method immediately below.
   *
   * @param src SparseBlockColumnMatrix to copy
   */
  SparseBlockColumnMatrix::SparseBlockColumnMatrix(const SparseBlockColumnMatrix& src) {
    copy(src);
@@ -45,6 +46,8 @@ namespace Isis {

  /**
   * Copy method.
   *
   * @param src SparseBlockColumnMatrix to copy
   */
  void SparseBlockColumnMatrix::copy(const SparseBlockColumnMatrix& src) {
    // handi-wipe
@@ -66,6 +69,8 @@ namespace Isis {

  /**
   * "Equals" operator.
   *
   * @param src SparseBlockColumnMatrix to check against
   */
  SparseBlockColumnMatrix&
      SparseBlockColumnMatrix::operator=(const SparseBlockColumnMatrix& src) {
@@ -79,18 +84,18 @@ 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 entry exists at the key nColumnBlock, no insertion is made.
   * 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
   *  entry exists at the key nColumnBlock, no insertion is made.
   *
   * @param nColumnBlock block column number of inserted matrix (key into map)
   * @param nRows number of rows in matrix to be inserted
   * @param nCols number of columns in matrix to be inserted
   *
   * @return bool Returns true if insertion is successful or if block already exists at nColumnBlock
   *              Returns false if attempt to allocate new block fails
   */
  bool SparseBlockColumnMatrix::InsertMatrixBlock(int nColumnBlock, int nRows,
                                                  int nCols) {

  bool SparseBlockColumnMatrix::insertMatrixBlock(int nColumnBlock, int nRows, int nCols) {
    // check if matrix already exists at the key "nColumnBlock"
    if ( this->contains(nColumnBlock) )
      return true;
@@ -112,8 +117,10 @@ namespace Isis {


  /**
   * Returns total number of matrix elements in map (NOTE: NOT the number of
   * matrix blocks). The sum of all the elements of all the matrix blocks.
   * Returns total number of matrix elements in map (NOTE: NOT the number of matrix blocks). The sum
   *  of all the elements in all of the matrix blocks.
   *
   * @return int Total number of matrix elements in SparseBlockColumnMatrix
   */
  int SparseBlockColumnMatrix::numberOfElements() {
    int nElements = 0;
@@ -133,8 +140,9 @@ namespace Isis {


  /**
   * Returns total number of columns in map (NOTE: NOT the number of
   * matrix blocks).
   * Returns total number of columns in map (NOTE: NOT the number of matrix blocks).
   *
   * @return int Total number of columns in SparseBlockColumnMatrix
   */
  int SparseBlockColumnMatrix::numberOfColumns() {

@@ -156,8 +164,10 @@ namespace Isis {


  /**
   * Returns total number of rows in map (this needs to be clarified and maybe rewritten)
   * its the number of rows in the block on the diagonal (the last one in the column).
   * Returns total number of rows in map (this needs to be clarified and maybe rewritten). It's the
   *  number of rows in the block on the diagonal (the last one in the column).
   *
   * @return int Total number of rows in SparseBlockColumnMatrix
   */
  int SparseBlockColumnMatrix::numberOfRows() {

@@ -177,7 +187,11 @@ namespace Isis {


  /**
   * Prints matrix blocks to std output stream out for debugging.
   * Prints matrix blocks to std output stream out for debugging. This version makes use of the
   *  Boost matrix library output of matrices as opposed to the printClean method below which
   *  explicitly prints the matrix elements for more control over the format.
   *
   * @param outstream output stream
   */
  void SparseBlockColumnMatrix::print(std::ostream& outstream) {
    if ( size() == 0 ) {
@@ -200,6 +214,42 @@ namespace Isis {
  }


  /**
   * Prints matrix blocks to std output stream out for debugging. Explicitly prints the matrix
   *  elements for more control over the format as opposed to the print method above.
   *
   * @param outstream output stream
   */
  void SparseBlockColumnMatrix::printClean(std::ostream& outstream) {
    if ( size() == 0 ) {
      outstream << "Empty SparseBlockColumnMatrix..." << std::endl;
      return;
    }

    QMapIterator<int, matrix<double>*> it(*this);
    while ( it.hasNext() ) {
      it.next();

      matrix<double>* m = it.value();

      int rows = m->size1();
      int cols = m->size2();

      for ( int i = 0; i < rows; i++ ) {
        for ( int j = 0; j < cols; j++ ) {
          double d = m->at_element(i,j);
          if ( j == cols-1 )
            outstream << std::setprecision(12) << d << std::endl;
          else
            outstream << std::setprecision(12) << d << ",";
        }
      }

    }
    outstream << std::endl;
  }


  /**
   * Sets all elements of all matrix blocks to zero.
   */
@@ -214,11 +264,14 @@ namespace Isis {

  /**
   * Writes matrix to binary disk file pointed to by QDataStream stream
   *
   * @param stream stream pointing to binary disk file
   * @param sbcm SparseBlockColumnMatrix to write
   */
  QDataStream &operator<<(QDataStream &stream, const SparseBlockColumnMatrix &sbcm) {
    // write number of blocks in this column
    int nBlocks = sbcm.size();
    stream << nBlocks;
    stream << (qint32)nBlocks;

    QMapIterator<int, matrix<double>*> it(sbcm);
    while ( it.hasNext() ) {
@@ -231,7 +284,7 @@ namespace Isis {
      int nCols = it.value()->size2();

      // write block number (key); rows (size1); and columns (size2)
       stream << it.key() << nRows << nCols;
      stream << it.key() << (qint32)nRows << (qint32)nCols;

      double* data = &it.value()->data()[0];

@@ -245,9 +298,12 @@ namespace Isis {

  /**
   * Reads matrix from binary disk file pointed to by QDataStream stream
   *
   * @param stream stream pointing to binary disk file
   * @param sbcm SparseBlockColumnMatrix to read
   */
  QDataStream &operator>>(QDataStream &stream, SparseBlockColumnMatrix &sbcm) {
    int nBlocks, nBlockNumber, nRows, nCols;
    qint32 nBlocks, nBlockNumber, nRows, nCols;
    int i, r, c;

    stream >> nBlocks;
@@ -262,7 +318,7 @@ namespace Isis {
      stream.readRawData((char*)data, nRows*nCols*sizeof(double));

      // insert matrix at correct key
      sbcm.InsertMatrixBlock(nBlockNumber, nRows, nCols);
      sbcm.insertMatrixBlock(nBlockNumber, nRows, nCols);

      // get matrix
      matrix<double>* matrix = sbcm[nBlockNumber];
@@ -279,8 +335,12 @@ namespace Isis {
    return stream;
  }


  /**
   * Writes matrix to QDebug stream (dbg)
   * Writes matrix to QDebug stream
   *
   * @param dbg debug stream
   * @param sbcm SparseBlockColumnMatrix to write to debug stream
   */
  QDebug operator<<(QDebug dbg, const SparseBlockColumnMatrix &sbcm) {
    dbg.space() << "New Block" << endl;
@@ -308,6 +368,7 @@ namespace Isis {
        }
        dbg.space() << endl;
      }

      dbg.space() << endl;
    }

@@ -327,9 +388,8 @@ namespace Isis {


  /**
   * Deletes all pointer elements and removes them from the map.
   * Effectively, a destructor, and in fact, called by the
   * ~SparseBlockColumnMatrix above.
   * Deletes all pointer elements and removes them from the map. Effectively, a destructor, and in
   * fact, called by the ~SparseBlockColumnMatrix above.
   */
  void SparseBlockRowMatrix::wipe() {
    qDeleteAll(values());
@@ -338,7 +398,9 @@ namespace Isis {


  /**
   * Copy constructor. Calls method immediately below.
   * Copy constructor. Calls copy method immediately below.
   *
   * @param src SparseBlockRowMatrix to copy
   */
  SparseBlockRowMatrix::SparseBlockRowMatrix(const SparseBlockRowMatrix& src) {
    copy(src);
@@ -347,6 +409,8 @@ namespace Isis {

  /**
   * Copy method.
   *
   * @param src SparseBlockRowMatrix to copy
   */
  void SparseBlockRowMatrix::copy(const SparseBlockRowMatrix& src) {
    // handi-wipe
@@ -368,6 +432,8 @@ namespace Isis {

  /**
   * "Equals" operator.
   *
   * @param src SparseBlockRowMatrix to check against
   */
  SparseBlockRowMatrix&
      SparseBlockRowMatrix::operator=(const SparseBlockRowMatrix& src) {
@@ -381,17 +447,21 @@ 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" 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.
   *
   * @param nRowBlock block row number of inserted matrix (key into map)
   * @param nRows number of rows in matrix to be inserted
   * @param nCols number of columns in matrix to be inserted
   *
   * @return bool Returns true if insertion successful
   *              Returns false if block already exists at nRowBlock or if allocation of new block
   *              fails
   *              TODO: we return true in the SparseBlockColumnMatrix if the block already exists,
   *                    why is it different here?
   */
  bool SparseBlockRowMatrix::InsertMatrixBlock(int nRowBlock, int nRows,
                                                  int nCols) {
  bool SparseBlockRowMatrix::insertMatrixBlock(int nRowBlock, int nRows, int nCols) {
    if ( this->contains(nRowBlock) )
      return false;

@@ -411,6 +481,8 @@ namespace Isis {
  /**
   * Returns total number of matrix elements in map (NOTE: NOT the number of
   * matrix blocks). The sum of all the elements of all the matrix blocks.
   *
   * @return int Total number of matrix elements in SparseBlockRowMatrix
   */
  int SparseBlockRowMatrix::numberOfElements() {
    int nElements = 0;
@@ -431,6 +503,8 @@ namespace Isis {

  /**
   * Prints matrix blocks to std output stream out for debugging.
   *
   * @param outstream output stream
   */
  void SparseBlockRowMatrix::print(std::ostream& outstream) {
    if ( size() == 0 ) {
@@ -453,6 +527,41 @@ namespace Isis {
  }


  /**
   * Prints matrix blocks to std output stream out for debugging.
   *
   * @param outstream output stream
   */
  void SparseBlockRowMatrix::printClean(std::ostream& outstream) {
    if ( size() == 0 ) {
      outstream << "Empty SparseBlockRowMatrix..." << std::endl;
      return;
    }

    QMapIterator<int, matrix<double>*> it(*this);
    while ( it.hasNext() ) {
      it.next();

      matrix<double>* m = it.value();

      int rows = m->size1();
      int cols = m->size2();

      for ( int i = 0; i < rows; i++ ) {
        for ( int j = 0; j < cols; j++ ) {
          double d = m->at_element(i,j);
          if ( j == cols-1 )
            outstream << std::setprecision(9) << d << std::endl;
          else
            outstream << std::setprecision(9) << d << ",";
        }
      }

    }
    outstream << std::endl;
  }


  /**
   * Sets all elements of all matrix blocks to zero.
   */
@@ -466,8 +575,10 @@ namespace Isis {


  /**
   * Copies a SparseBlockRowMatrix to a Boost compressed_matrix
   * This may be a temporary implementation
   * Copies a SparseBlockRowMatrix to a Boost compressed_matrix. This may be a temporary
   *  implementation
   *
   * @param B Boost matrix to copy this SparseBlockRowMatrix to
   */
  void SparseBlockRowMatrix::copyToBoost(compressed_matrix<double>& B) {
    B.clear();
@@ -496,13 +607,53 @@ namespace Isis {
    }
  }


  /**
   * Sums and returns the number of columns in each matrix block prior to nblockColumn
   *
   * @param nblockColumn
   *
   * @return int Number of leading columns for block at nblockColumn
   */
    int SparseBlockRowMatrix::getLeadingColumnsForBlock(int nblockColumn) {

      if ( nblockColumn == 0 )
        return 0;

      int nLeadingColumnsElements = 0;

      int nCol = 0;

      while ( nCol < nblockColumn ) {
        if ( !(*this)[nCol] ) {
          nCol++;
          continue;
        }

        int ncolumns = (*this)[nCol]->size2();

        if ( ncolumns == -1 )
          continue;

        nLeadingColumnsElements += ncolumns;

        nCol++;
      }

      return nLeadingColumnsElements;
    }


  /**
   * Writes matrix to binary disk file pointed to by QDataStream stream
   *
   * @param stream stream pointing to binary disk file
   * @param sbrm SparseBlockRowMatrix to write
   */
  QDataStream &operator<<(QDataStream &stream, const SparseBlockRowMatrix &sbrm) {
    // write number of blocks in this column
    int nBlocks = sbrm.size();
    stream << nBlocks;
    stream << (qint32)nBlocks;

    QMapIterator<int, matrix<double>*> it(sbrm);
    while ( it.hasNext() ) {
@@ -515,7 +666,7 @@ namespace Isis {
      int nCols = it.value()->size2();

      // write block number (key); rows (size1); and columns (size2)
       stream << it.key() << nRows << nCols;
      stream << it.key() << (qint32)nRows << (qint32)nCols;

      double* data = &it.value()->data()[0];

@@ -529,9 +680,12 @@ namespace Isis {

  /**
   * Reads matrix from binary disk file pointed to by QDataStream stream
   *
   * @param stream stream pointing to binary disk file
   * @param sbcm SparseBlockColumnMatrix to read
   */
  QDataStream &operator>>(QDataStream &stream, SparseBlockRowMatrix &sbrm) {
    int nBlocks, nBlockNumber, nRows, nCols;
    qint32 nBlocks, nBlockNumber, nRows, nCols;
    int i, r, c;

    stream >> nBlocks;
@@ -546,7 +700,7 @@ namespace Isis {
      stream.readRawData((char*)data, nRows*nCols*sizeof(double));

      // insert matrix at correct key
      sbrm.InsertMatrixBlock(nBlockNumber, nRows, nCols);
      sbrm.insertMatrixBlock(nBlockNumber, nRows, nCols);

      // get matrix
      matrix<double>* matrix = sbrm[nBlockNumber];
@@ -563,8 +717,12 @@ namespace Isis {
    return stream;
  }


  /**
   * Writes matrix to QDebug stream (dbg)
   * Writes matrix to QDebug stream
   *
   * @param dbt debug stream
   * @param sbcm SparseBlockRowMatrix to write to debug stream
   */
  QDebug operator<<(QDebug dbg, const SparseBlockRowMatrix &sbrm) {
    dbg.space() << "New Block" << endl;
@@ -611,9 +769,8 @@ namespace Isis {


  /**
   * Deletes all pointer elements and removes them from the list.
   * Effectively, a destructor, and in fact, called by the
   * ~SparseBlockMatrix above.
   * Deletes all pointer elements and removes them from the list. Effectively, a destructor, and in
   *  fact, called by the ~SparseBlockMatrix above.
   */
  void SparseBlockMatrix::wipe() {
    qDeleteAll(*this);
@@ -623,13 +780,18 @@ namespace Isis {

  /**
   * Copy constructor. Calls copy method immediately below.
   *
   * @param src SparseBlockMatrix to copy
   */
  SparseBlockMatrix::SparseBlockMatrix(const SparseBlockMatrix& src) {
    copy(src);
  }


  /**
   * Copy method.
   *
   * @param src SparseBlockMatrix to copy
   */
  void SparseBlockMatrix::copy(const SparseBlockMatrix& src) {
    // handi-wipe
@@ -644,6 +806,8 @@ namespace Isis {

  /**
   * "Equals" operator.
   *
   * @param src SparseBlockMatrix to check against
   */
  SparseBlockMatrix& SparseBlockMatrix::operator=(const SparseBlockMatrix& src) {
    if ( this == &src )
@@ -659,6 +823,9 @@ namespace Isis {
   * Initializes number of columns (SparseBlockColumnMatrix).
   *
   * @param n number of columns to insert
   *
   * @return bool Always returns true
   *              TODO: why bother returning bool? should there be a false condition?
   */
  bool SparseBlockMatrix::setNumberOfColumns( int n ) {

@@ -679,15 +846,18 @@ namespace Isis {
   * @param nRowBlock block row number of inserted matrix (key into map)
   * @param nRows number of rows in matrix to be inserted
   * @param nCols number of columns in matrix to be inserted
   *
   * @return bool Returns result of SparseBlockColumnMatrix::insertMatrixBlock()
   */
  bool SparseBlockMatrix::InsertMatrixBlock(int nColumnBlock, int nRowBlock,
                                            int nRows, int nCols) {
    return (*this)[nColumnBlock]->InsertMatrixBlock(nRowBlock, nRows, nCols);
  bool SparseBlockMatrix::insertMatrixBlock(int nColumnBlock, int nRowBlock, int nRows, int nCols) {
    return (*this)[nColumnBlock]->insertMatrixBlock(nRowBlock, nRows, nCols);
  }


  /**
   * Returns total number of blocks in matrix.
   *
   * @return int Total number of blocks in matrix
   */
  int SparseBlockMatrix::numberOfBlocks() {
    int nBlocks = 0;
@@ -704,8 +874,9 @@ namespace Isis {


  /**
   * Returns number of diagonal matrix blocks (equivalent to size - there is one
   * per column).
   * Returns number of diagonal matrix blocks (equivalent to size - there is one per column).
   *
   * @return int Number of diagnonal blocks in matrix
   */
  int SparseBlockMatrix::numberOfDiagonalBlocks() {
    int ndiagBlocks = 0;
@@ -733,6 +904,8 @@ namespace Isis {

  /**
   * Returns number of off-diagonal matrix blocks.
   *
   * @return int Number of off-diagonal blocks in matrix
   */
  int SparseBlockMatrix::numberOfOffDiagonalBlocks() {
    return (numberOfBlocks() - numberOfDiagonalBlocks());
@@ -741,6 +914,8 @@ namespace Isis {

  /**
   * Returns number of matrix elements in matrix.
   *
   * @return int Total number of matrix elements
   */
  int SparseBlockMatrix::numberOfElements() {
    int nElements = 0;
@@ -757,10 +932,12 @@ namespace Isis {


  /**
   * Returns pointer to boost matrix at (column, row).
   * Returns pointer to boost matrix at position (column, row).
   *
   * @param column block column number
   * @param row block row number
   *
   * @return matrix<double>* Pointer to Boost matrix at position (column, row)
   */
  matrix<double>* SparseBlockMatrix::getBlock(int column, int row) {
    return (*(*this)[column])[row];
@@ -778,6 +955,8 @@ namespace Isis {

  /**
   * Prints matrix blocks to std output stream out for debugging.
   *
   * @param outstream output stream
   */
  void SparseBlockMatrix::print(std::ostream& outstream) {
    if ( size() == 0 ) {
@@ -798,13 +977,109 @@ namespace Isis {
  }


  /**
   * Prints matrix blocks to std output stream out for debugging.
   *
   * @param outstream output stream
   */
  void SparseBlockMatrix::printClean(std::ostream& outstream) {
    if ( size() == 0 ) {
      outstream << "Empty SparseBlockMatrix..." << std::endl;
      return;
    }

    for( int i = 0; i < size(); i++ ) {
      SparseBlockColumnMatrix* column = at(i);

      if ( column )
        column->printClean(outstream);
      else
        outstream << "NULL column pointer at column[" << IString(i)
                  << "]!" << std::endl;
    }
  }


  /**
   * Sums and returns the number of columns in each matrix block prior to nblockColumn
   *
   * @param nblockColumn
   *
   * @return int Number of leading column elements for block at nblockColumn
   */
  int SparseBlockMatrix::getLeadingColumnsForBlock(int nblockColumn) {

    if ( nblockColumn == 0 )
      return 0;

    int nLeadingColumnsElements = 0;

    int nCol = 0;

    while ( nCol < nblockColumn ) {
      if ( !(*this)[nCol] )
        continue;

      int ncolumns = (*this)[nCol]->numberOfColumns();

      if ( ncolumns == -1 )
        continue;

      nLeadingColumnsElements += ncolumns;

      nCol++;
    }

    return nLeadingColumnsElements;
  }


  /**
   * Sums and returns the number of rows in each matrix block prior to nblockRow
   *
   * @param nblockRow
   *
   * @return int Number of leading row elements for block at nblockRow
   */
  int SparseBlockMatrix::getLeadingRowsForBlock(int nblockRow) {

    if ( nblockRow == 0 )
      return 0;

    int i = 0;
    int nLeadingRows = 0;

    while ( i < nblockRow ) {
      SparseBlockColumnMatrix* column = at(i);

      if ( !column )
        continue;

      QMapIterator<int, matrix<double>*> it(*column);
      // iterate to last element in column
      while ( it.hasNext() ) {
        it.next();

        if( it.key() == i )
          nLeadingRows += it.value()->size1();
      }
      i++;
    }

    return nLeadingRows;
  }


  /**
   * Writes matrix to binary disk file pointed to by QDataStream stream
   *
   * @param stream stream pointing to binary disk file
   * @param sparseBlockMatrix SparseBlockMatrix to write
   */
  QDataStream &operator<<(QDataStream &stream, const SparseBlockMatrix &sparseBlockMatrix) {
    int nBlockColumns = sparseBlockMatrix.size();

    stream << nBlockColumns;
    stream << (qint32)nBlockColumns;

    for ( int i =0; i < nBlockColumns; i++ )
      stream << *sparseBlockMatrix.at(i);
@@ -815,9 +1090,12 @@ namespace Isis {

  /**
   * Reads matrix from binary disk file pointed to by QDataStream stream
   *
   * @param stream stream pointing to binary disk file
   * @param sparseBlockMatrix SparseBlockMatrix to read
   */
  QDataStream &operator>>(QDataStream &stream, SparseBlockMatrix &sparseBlockMatrix) {
    int nBlockColumns;
    qint32 nBlockColumns;

    // read and set number of block columns
    stream >> nBlockColumns;
@@ -830,7 +1108,10 @@ namespace Isis {
  }

  /**
   * Writes matrix to QDebug stream (dbg)
   * Writes matrix to QDebug stream
   *
   * @param dbg debug stream
   * @param m SparseBlockMatrix to write to debug stream
   */
  QDebug operator<<(QDebug dbg, const SparseBlockMatrix &m) {
    int nBlockColumns = m.size();
+52 −7

File changed.

Preview size limit exceeded, changes collapsed.

+2 −0
Original line number Diff line number Diff line
@@ -213,6 +213,8 @@ Empty SparseBlockMatrix...
    # diagonal matrix blocks: 1
# off-diagonal matrix blocks: 1
           # matrix elements: 18
# leading columns for block2: 3
   # leading rows for block1: 0
Printing SparseBlockMatrix...
Empty SparseBlockColumnMatrix...
Printing SparseBlockColumnMatrix...
+25 −23

File changed.

Preview size limit exceeded, changes collapsed.

+7 −7
Original line number Diff line number Diff line
@@ -1394,7 +1394,7 @@ namespace Isis {
    int t = m_nNumImagePartials * nImageIndex;

    // insert submatrix at column, row
    m_SparseNormals.InsertMatrixBlock(nImageIndex, nImageIndex,
    m_SparseNormals.insertMatrixBlock(nImageIndex, nImageIndex,
        m_nNumImagePartials, m_nNumImagePartials );

    (*(*m_SparseNormals[nImageIndex])[nImageIndex]) += N11;
@@ -1417,7 +1417,7 @@ namespace Isis {
//    for (i = 0; i < m_nNumImagePartials; i++)
//      for (j = 0; j < 3; j++)
//        N12(i + t, j) += N12_Image(i, j);
    N12.InsertMatrixBlock(nImageIndex, m_nNumImagePartials, 3);
    N12.insertMatrixBlock(nImageIndex, m_nNumImagePartials, 3);
    *N12[nImageIndex] += N12_Image;

//    printf("N12\n");
@@ -2103,7 +2103,7 @@ namespace Isis {
      int ncol = iN12.key();

      // insert submatrix in Q at block "ncol"
      Q.InsertMatrixBlock(ncol, 3, m_nNumImagePartials);
      Q.insertMatrixBlock(ncol, 3, m_nNumImagePartials);

      *(Q[ncol]) = prod(N22,trans(*(iN12.value())));
    }
@@ -2144,7 +2144,7 @@ namespace Isis {
          continue;

        // insert submatrix at column, row
        m_SparseNormals.InsertMatrixBlock(ncol, nrow,
        m_SparseNormals.insertMatrixBlock(ncol, nrow,
            m_nNumImagePartials, m_nNumImagePartials );

        (*(*m_SparseNormals[ncol])[nrow]) -= prod(*a,*(iQ.value()));
@@ -5694,13 +5694,13 @@ namespace Isis {
      if (i == 0) {
        ncolsCurrentBlockColumn = normalsColumn->numberOfColumns();
        int nRows = m_SparseNormals.at(i)->numberOfRows();
        sbcMatrix.InsertMatrixBlock(i, nRows, ncolsCurrentBlockColumn);
        sbcMatrix.insertMatrixBlock(i, nRows, ncolsCurrentBlockColumn);
        sbcMatrix.zeroBlocks();
      }
      else {
        if (normalsColumn->numberOfColumns() == ncolsCurrentBlockColumn) {
          int nRows = m_SparseNormals.at(i)->numberOfRows();
          sbcMatrix.InsertMatrixBlock(i, nRows, ncolsCurrentBlockColumn);
          sbcMatrix.insertMatrixBlock(i, nRows, ncolsCurrentBlockColumn);
          sbcMatrix.zeroBlocks();
        }
        else {
@@ -5714,7 +5714,7 @@ namespace Isis {
            SparseBlockColumnMatrix* normalsRow = m_SparseNormals.at(j);
            int nRows = normalsRow->numberOfRows();

            sbcMatrix.InsertMatrixBlock(j, nRows, ncolsCurrentBlockColumn);
            sbcMatrix.insertMatrixBlock(j, nRows, ncolsCurrentBlockColumn);
          }
        }
      }