PlayaLoadableMatrix.hpp

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 {
00016   template <class Scalar>
00017   class LoadableMatrix 
00018   {
00019   public:
00021     virtual ~LoadableMatrix(){;}
00022 
00036     virtual void addToRow(int globalRowIndex,
00037                           int nElemsToInsert,
00038                           const int* globalColumnIndices,
00039                           const Scalar* elementValues) = 0 ;
00040 
00042     virtual void zero() = 0 ;
00043 
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

doxygen