Lapack++
bmd.h
Go to the documentation of this file.
00001 //      LAPACK++ (V. 1.1)
00002 //      (C) 1992-1996 All Rights Reserved.
00003 
00004 
00005 #ifndef _LA_BAND_MAT_DOUBLE_H_
00006 #define _LA_BAND_MAT_DOUBLE_H_
00007 
00008 #include "arch.h"
00009 #ifndef _LA_GEN_MAT_DOUBLE_H_
00010 #include LA_GEN_MAT_DOUBLE_H
00011 #endif
00012 
00013 
00014 #define BOUNDS_CHK
00015 //#define SPARSE_CHK
00016 #ifdef LA_NO_BOUNDS_CHECK
00017 #undef BOUNDS_CHK
00018 #endif
00019 #ifdef LA_NO_SPARSE_CHECK
00020 #undef SPARSE_CHK
00021 #endif
00022 
00023 class DLLIMPORT LaBandMatDouble
00024 {
00025     LaGenMatDouble data_;  // internal storage.
00026 
00027     int N_;       // N_ is (NxN)
00028     int kl_;      // kl_ = # subdiags
00029     int ku_;      // ku_ = # superdiags
00030     static double outofbounds_; // value returned if index is out of range.
00031     static int debug_;         // print debug info.
00032     static int *info_;         // print matrix info only, not values
00033     //   originally 0, set to 1, and then
00034     //   reset to 0 after use.
00035 
00036 
00037 public:
00038 
00039     // constructors
00040 
00041     LaBandMatDouble();
00042     LaBandMatDouble(int, int, int);
00043     LaBandMatDouble(const LaBandMatDouble &);
00044 
00045     // destructor
00046 
00047     ~LaBandMatDouble();
00048 
00049     // operators
00050 
00051     LaBandMatDouble& operator=(double);
00052     LaBandMatDouble& operator=(const LaBandMatDouble&);
00053     inline double& operator()(int, int);
00054     inline const double& operator()(int, int) const;
00055     friend std::ostream& operator<<(std::ostream &, const LaBandMatDouble &);
00056 
00057 
00058     // member functions
00059 
00060     inline int size(int) const;           // submatrix size
00061     inline int inc(int d) const;          // explicit increment
00062     inline int gdim(int d) const;         // global dimensions
00063 
00064     inline LaBandMatDouble& ref(LaBandMatDouble &);
00065     LaBandMatDouble copy(const LaBandMatDouble &);
00066     inline double* addr() const          // return address of matrix.
00067     {
00068         return data_.addr();
00069     }
00070     inline int ref_count() const          // return ref_count of matrix.
00071     {
00072         return data_.ref_count();
00073     }
00074     inline LaIndex index(int d) const       // return indices of matrix.
00075     {
00076         return data_.index(d);
00077     }
00078     inline int superdiags()       // return # of superdiags of matrix.
00079     {
00080         return (ku_);
00081     }
00082     inline int superdiags() const   // return # of superdiags of const matrix.
00083     {
00084         return (ku_);
00085     }
00086     inline int subdiags()       // return # of subdiags of matrix.
00087     {
00088         return (kl_);
00089     }
00090     inline int subdiags() const    // return # of subdiags of const matrix.
00091     {
00092         return (kl_);
00093     }
00094     inline int shallow() const        // return shallow flag.
00095     {
00096         return data_.shallow();
00097     }
00098     inline int debug() const      // return debug flag.
00099     {
00100         return debug_;
00101     }
00102     inline int debug(int d)   // set debug flag for lagenmat.
00103     {
00104         return debug_ = d;
00105     }
00106 
00107     LaBandMatDouble& resize(const LaBandMatDouble&);
00108 
00109     inline const LaBandMatDouble& info() const
00110     {
00111         int *t = info_;
00112         *t = 1;
00113         return *this;
00114     };
00115 
00116     inline LaBandMatDouble print_data() const
00117     {
00118         std::cout << data_;
00119         return *this;
00120     }
00121 
00122 };
00123 
00124 
00125 
00126 // member functions and operators
00127 
00128 inline LaBandMatDouble& LaBandMatDouble::ref(LaBandMatDouble &ob)
00129 {
00130 
00131     data_.ref(ob.data_);
00132     N_ = ob.N_;
00133     kl_ = ob.kl_;
00134     ku_ = ob.ku_;
00135 
00136     return *this;
00137 }
00138 
00139 inline int LaBandMatDouble::size(int d) const
00140 {
00141     return(data_.size(d));
00142 }
00143 
00144 inline int LaBandMatDouble::inc(int d) const
00145 {
00146     return(data_.inc(d));
00147 }
00148 
00149 inline int LaBandMatDouble::gdim(int d) const
00150 {
00151     return(data_.gdim(d));
00152 }
00153 
00154 inline double& LaBandMatDouble::operator()(int i, int j)
00155 {
00156 #ifdef LA_BOUNDS_CHECK
00157     assert(i >= 0);
00158     assert(i < N_);
00159     assert(j >= 0);
00160     assert(j < N_);
00161 #endif
00162 
00163     if (i < 0)
00164     {
00165         if (-i <= kl_)
00166             return data_(kl_ + i - j, j);
00167         else
00168         {
00169 #ifdef LA_BOUNDS_CHECK
00170             assert(0);
00171 #else
00172             return outofbounds_;
00173 #endif
00174         }
00175     }
00176 
00177     if (i >= j)
00178     {
00179         if (i - j <= kl_)
00180             return data_(kl_ + ku_ + i - j, j);
00181         else
00182         {
00183 #ifdef LA_BOUNDS_CHECK
00184             assert(0);
00185 #else
00186             return outofbounds_;
00187 #endif
00188         }
00189     }
00190 
00191     else //  (j>i)
00192     {
00193         if (j - i <= ku_)
00194             return data_(kl_ + ku_ + i - j, j); // kl_ is factorization storage here.
00195         else
00196         {
00197 #ifdef LA_BOUNDS_CHECK
00198             assert(0);
00199 #else
00200             return outofbounds_;
00201 #endif
00202         }
00203     }
00204 }
00205 
00206 
00207 inline const double& LaBandMatDouble::operator()(int i, int j) const
00208 {
00209 #ifdef LA_BOUNDS_CHECK
00210     assert(i >= 0);
00211     assert(i < N_);
00212     assert(j >= 0);
00213     assert(j < N_);
00214 #endif
00215 
00216     if (i < 0)
00217     {
00218         if (-i <= kl_)
00219             return data_(kl_ + i - j, j);
00220         else
00221         {
00222 #ifdef LA_BOUNDS_CHECK
00223             assert(0);
00224 #else
00225             return outofbounds_;
00226 #endif
00227         }
00228     }
00229 
00230     if (i >= j)
00231     {
00232         if (i - j <= kl_)
00233             return data_(kl_ + ku_ + i - j, j);
00234         else
00235         {
00236 #ifdef LA_BOUNDS_CHECK
00237             assert(0);
00238 #else
00239             return outofbounds_;
00240 #endif
00241         }
00242     }
00243 
00244     else // (j>i)
00245     {
00246         if (j - i <= ku_)
00247             return data_(kl_ + ku_ + i - j, j); // kl_ is factorization storage here.
00248         else
00249         {
00250 #ifdef LA_BOUNDS_CHECK
00251             assert(0);
00252 #else
00253             return outofbounds_;
00254 #endif
00255         }
00256     }
00257 }
00258 
00259 #endif // _LA_BAND_MAT_DOUBLE_H_