sparvec.h

Go to the documentation of this file.
00001 
00039 #ifndef ABA_SPARVEC_H
00040 #define ABA_SPARVEC_H
00041 #include <stdlib.h>
00042 
00043 #include "abacus/array.h"
00044 #include "abacus/buffer.h"
00045 
00046 #ifdef ABACUS_PARALLEL
00047 class ABA_MESSAGE;
00048 #endif
00049 
00050   class  ABA_SPARVEC :  public ABA_ABACUSROOT  {
00051     public:
00052 
00067       ABA_SPARVEC(ABA_GLOBAL *glob, 
00068                   int size, 
00069                   double reallocFac = 10.0);
00070 
00093       ABA_SPARVEC(ABA_GLOBAL *glob, 
00094                   int size, 
00095                   const ABA_ARRAY<int> &s, 
00096                   const ABA_ARRAY<double> &c, 
00097                   double reallocFac = 10.0);
00098 
00103       ABA_SPARVEC(ABA_GLOBAL *glob, 
00104                   int size, 
00105                   int *s, 
00106                   double *c, 
00107                   double reallocFac = 10.0);
00108 
00113       ABA_SPARVEC(const ABA_SPARVEC& rhs);
00114 
00116       ~ABA_SPARVEC();
00117 #ifdef ABACUS_PARALLEL
00118 
00126       ABA_SPARVEC(const ABA_GLOBAL *glob, ABA_MESSAGE &msg);
00127 
00133       void pack(ABA_MESSAGE &msg) const;
00134 #endif
00135 
00145       const ABA_SPARVEC& operator=(const ABA_SPARVEC& rhs);
00146 
00156       friend ostream& operator<<(ostream& out, const ABA_SPARVEC& rhs);
00157 
00165       int support(int i) const; 
00166 
00174       double coeff(int i) const;
00175 
00180       double origCoeff(int i) const;
00181 
00190       void insert(int s, double c);
00191 
00201       void leftShift(ABA_BUFFER<int> &del);
00202 
00210       void copy (const ABA_SPARVEC &vec);
00211 
00214       void clear();
00215 
00223       void rename(ABA_ARRAY<int> &newName);
00224 
00227       int size() const;
00228 
00234       int nnz() const;
00235 
00238       double norm();
00239 
00245       void realloc();
00246 
00256       void realloc(int newSize);
00257     protected:
00258 
00269       void rangeCheck(int i) const;
00270 
00273       ABA_GLOBAL *glob_;
00274 
00278       int size_;
00279 
00282       int nnz_;
00283 
00288       double reallocFac_;
00289 
00292       int *support_;
00293 
00296       double *coeff_;
00297   };
00298 
00299 
00300 inline int ABA_SPARVEC::support(int i) const
00301   {
00302 #ifdef ABACUSSAFE
00303     rangeCheck(i);
00304 #endif    
00305     return support_[i];
00306   }
00307 
00308 inline double ABA_SPARVEC::coeff(int i) const
00309   {
00310 #ifdef ABACUSSAFE
00311     rangeCheck(i);
00312 #endif    
00313     return coeff_[i];
00314   }
00315 
00316 inline void ABA_SPARVEC::insert(int s, double c)
00317   {
00318 
00319     if (nnz_ == size_) realloc();
00320 
00321     support_[nnz_] = s;
00322     coeff_[nnz_]   = c;
00323     ++nnz_;
00324 
00325   }
00326 
00327 inline void ABA_SPARVEC::clear()
00328   {
00329     nnz_ = 0;
00330   }
00331 
00332 inline int ABA_SPARVEC::size() const
00333   {
00334     return size_;
00335   }
00336 
00337 inline int ABA_SPARVEC::nnz() const
00338   {
00339     return nnz_;
00340   }
00341 
00342 
00343 #endif  // ABA_SPARVEC_H
00344 

Generated on Tue Aug 14 18:09:54 2007 for ABACUS by  doxygen 1.5.1