PlayaLoadableMatrix.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 //   
00003 /* @HEADER@ */
00004 
00005 #ifndef PLAYA_LOADABLEMATRIX_HPP
00006 #define PLAYA_LOADABLEMATRIX_HPP
00007 
00008 #include "PlayaDefs.hpp"
00009 
00010 namespace Playa
00011 {
00012   /** 
00013    * Class LoadableMatrix provides an abstract interface for 
00014    * loading elements into a matrix.
00015    */
00016   template <class Scalar>
00017   class LoadableMatrix 
00018   {
00019   public:
00020     /** Virtual dtor */
00021     virtual ~LoadableMatrix(){;}
00022 
00023     /** Insert a set of elements in a row, adding to any previously
00024      * existing values.  The nonzero structure of the matrix must have
00025      * been determined at construction time. 
00026      *
00027      * @param globalRowIndex the global index of the row to which these
00028      * elements belong.
00029      * @param nElemsToInsert the number of elements being inserted in this
00030      * step
00031      * @param globalColumnIndices array of column indices. Must 
00032      * be nElemsToInsert in length. 
00033      * @param elements array of element values. Must be nElemsToInsert in
00034      * length
00035      */
00036     virtual void addToRow(int globalRowIndex,
00037                           int nElemsToInsert,
00038                           const int* globalColumnIndices,
00039                           const Scalar* elementValues) = 0 ;
00040 
00041     /** Set all elements to zero, preserving the existing structure */
00042     virtual void zero() = 0 ;
00043 
00044     /** 
00045      * Add to a batch of elements
00046      */
00047     virtual void addToElementBatch(int numRows, 
00048                                    int rowBlockSize,
00049                                    const int* globalRowIndices,
00050                                    int numColumnsPerRow,
00051                                    const int* globalColumnIndices,
00052                                    const Scalar* values,
00053                                    const int* skipRow);
00054 
00055 
00056   };
00057 
00058 
00059   /* Default implementation of addElementBatch */
00060   template <class Scalar>
00061   void LoadableMatrix<Scalar>::addToElementBatch(int numRows, 
00062                                                  int rowBlockSize,
00063                                                  const int* globalRowIndices,
00064                                                  int numColumnsPerRow,
00065                                                  const int* globalColumnIndices,
00066                                                  const Scalar* values,
00067                                                  const int* skipRow)
00068   {
00069     int numRowBlocks = numRows/rowBlockSize;
00070     int row = 0;
00071 
00072     for (int rb=0; rb<numRowBlocks; rb++)
00073       {
00074         const int* cols = globalColumnIndices + rb*numColumnsPerRow;
00075         for (int r=0; r<rowBlockSize; r++, row++)
00076           {
00077             if (skipRow[row]) continue;
00078             const double* rowVals = values + row*numColumnsPerRow;
00079             addToRow(globalRowIndices[row], numColumnsPerRow,
00080                      cols, rowVals);
00081           }
00082       }
00083   }
00084 }
00085 
00086 #endif

Site Contact