Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals

diagonal_matrix.h

Go to the documentation of this file.
00001 
00005 template<class T, class S> class diagonal_matrix : public matrix<T, S>
00006 {
00007 private:
00008         vector<S> _val;         
00009 public:
00014         diagonal_matrix(const vector<S> &_val)
00015         {
00016                 this->_val = _val;
00017         }
00023         void multiply(const packed_vector<S> &_x, packed_vector<S> &_b) const
00024         {
00025                 const S *a = &_val[0];
00026                 const S *x = &_x[0];
00027                 S *b = &_b[0];
00028                 int m = (int)_val.size();
00029                 int n = _x.numrhs();
00030                 switch(n)
00031                 {
00032                 case 0:
00033                         break;
00034                 case 1:
00035                         for(int i = 0; i < m; i++)
00036                         {
00037                                 S val = a[i];
00038                                 b[i] = val * x[i];
00039                         }
00040                         break;
00041                 case 2:
00042                         for(int i = 0; i < m; i++)
00043                         {
00044                                 T k = 2 * i;
00045                                 S val = a[i];
00046                                 b[k + 0] = val * x[k + 0];
00047                                 b[k + 1] = val * x[k + 1];
00048                         }
00049                         break;
00050                 case 3:
00051                         for(int i = 0; i < m; i++)
00052                         {
00053                                 T k = 3 * i;
00054                                 S val = a[i];
00055                                 b[k + 0] = val * x[k + 0];
00056                                 b[k + 1] = val * x[k + 1];
00057                                 b[k + 2] = val * x[k + 2];
00058                         }
00059                         break;
00060                 case 4:
00061                         for(int i = 0; i < m; i++)
00062                         {
00063                                 T k = 4 * i;
00064                                 S val = a[i];
00065                                 b[k + 0] = val * x[k + 0];
00066                                 b[k + 1] = val * x[k + 1];
00067                                 b[k + 2] = val * x[k + 2];
00068                                 b[k + 3] = val * x[k + 3];
00069                         }
00070                         break;
00071                 default:
00072                         for(int i = 0; i < m; i++)
00073                         {
00074                                 T k = n * i;
00075                                 S val = a[i];
00076                                 for(int j = 0; j < n; j++)
00077                                 {
00078                                         b[k + j] = val * x[k + j];
00079                                 }
00080                         }
00081                 }
00082         }
00083 };

Generated on Wed Apr 26 17:41:45 2006 for Parallel Toolbox by  doxygen 1.4.2