Lapack++
|
00001 // -*-C++-*- 00002 00003 // Copyright (C) 2004 00004 // Christian Stimming <stimming@tuhh.de> 00005 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public License as 00008 // published by the Free Software Foundation; either version 2, or (at 00009 // your option) any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU Lesser General Public License for more details. 00015 00016 // You should have received a copy of the GNU Lesser General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00019 // USA. 00020 00021 // LAPACK++ (V. 1.1) 00022 // (C) 1992-1996 All Rights Reserved. 00023 00028 #ifndef _LA_VECTOR_INT_H_ 00029 #define _LA_VECTOR_INT_H_ 00030 00031 #include "lafnames.h" 00032 00033 #include LA_GEN_MAT_INT_H 00034 00041 class LaVectorInt: public LaGenMatInt 00042 { 00043 public: 00044 00048 inline LaVectorInt(); 00049 00051 inline LaVectorInt(int n); 00052 00055 inline LaVectorInt(int m, int n); 00056 00059 inline LaVectorInt(int* v, int n); 00060 00064 inline LaVectorInt(int* v, int m, int n); 00065 00069 inline LaVectorInt(const LaGenMatInt&); 00070 00073 LaVectorInt (const LaIndex& ind); 00075 00076 00080 inline int size() const; 00081 00087 inline int inc() const; 00088 00093 inline int start() const; 00094 00099 inline int end() const; 00100 00105 inline LaIndex index() const; 00107 00123 inline int& operator()(int i); 00124 00138 inline const int& operator()(int i) const ; 00139 00151 inline LaVectorInt operator()(const LaIndex&); 00153 00160 inline LaVectorInt& operator=(int); 00161 00169 inline LaVectorInt& operator=(const LaGenMatInt&); 00170 00171 00180 inline LaVectorInt& inject(const LaGenMatInt &); 00181 00186 inline LaVectorInt& copy(const LaGenMatInt &); 00187 00195 inline LaVectorInt& ref(const LaGenMatInt &); 00197 00198 }; 00199 00200 // NOTE: we default to column vectors, since matrices are column 00201 // oriented. 00202 00203 inline LaVectorInt::LaVectorInt() : LaGenMatInt(0, 1) {} 00204 inline LaVectorInt::LaVectorInt(int i) : LaGenMatInt(i, 1) {} 00205 00206 // NOTE: one shouldn't be using this method to initalize, but 00207 // it is here so that the constructor can be overloaded with 00208 // a runtime test. 00209 // 00210 inline LaVectorInt::LaVectorInt(int m, int n) : LaGenMatInt(m, n) 00211 { 00212 assert(n == 1 || m == 1); 00213 } 00214 00215 inline LaVectorInt::LaVectorInt(int *d, int n) : 00216 LaGenMatInt(d, n, 1) {} 00217 00218 inline LaVectorInt::LaVectorInt(int *d, int n, int m) : 00219 LaGenMatInt(d, n, m) {} 00220 00221 inline LaVectorInt::LaVectorInt(const LaGenMatInt &G) 00222 { 00223 assert(G.size(0) == 1 || G.size(1) == 1); 00224 00225 (*this).ref(G); 00226 } 00227 00228 00229 //note that vectors can be either stored columnwise, or row-wise 00230 00231 // this will handle the 0x0 case as well. 00232 00233 inline int LaVectorInt::size() const 00234 { 00235 return LaGenMatInt::size(0) * LaGenMatInt::size(1); 00236 } 00237 00238 inline int& LaVectorInt::operator()(int i) 00239 { 00240 if (LaGenMatInt::size(0) == 1 ) 00241 return LaGenMatInt::operator()(0, i); 00242 else 00243 return LaGenMatInt::operator()(i, 0); 00244 } 00245 00246 inline const int& LaVectorInt::operator()(int i) const 00247 { 00248 if (LaGenMatInt::size(0) == 1 ) 00249 return LaGenMatInt::operator()(0, i); 00250 else 00251 return LaGenMatInt::operator()(i, 0); 00252 } 00253 00254 inline LaVectorInt LaVectorInt::operator()(const LaIndex& I) 00255 { 00256 if (LaGenMatInt::size(0) == 1) 00257 return LaGenMatInt::operator()(LaIndex(0, 0), I).shallow_assign(); 00258 else 00259 return LaGenMatInt::operator()(I, LaIndex(0, 0)).shallow_assign(); 00260 } 00261 00262 00263 inline LaVectorInt& LaVectorInt::copy(const LaGenMatInt &A) 00264 { 00265 assert(A.size(0) == 1 || A.size(1) == 1); //make sure rhs is a 00266 // a vector. 00267 LaGenMatInt::copy(A); 00268 return *this; 00269 } 00270 00271 inline LaVectorInt& LaVectorInt::operator=(const LaGenMatInt &A) 00272 { 00273 return inject(A); 00274 } 00275 00276 inline LaVectorInt& LaVectorInt::ref(const LaGenMatInt &A) 00277 { 00278 assert(A.size(0) == 1 || A.size(1) == 1); 00279 LaGenMatInt::ref(A); 00280 return *this; 00281 } 00282 00283 inline LaVectorInt& LaVectorInt::operator=(int d) 00284 { 00285 LaGenMatInt::operator=(d); 00286 return *this; 00287 } 00288 00289 inline LaVectorInt& LaVectorInt::inject(const LaGenMatInt &A) 00290 { 00291 assert(A.size(0) == 1 || A.size(1) == 1); 00292 LaGenMatInt::inject(A); 00293 return *this; 00294 } 00295 00296 inline int LaVectorInt::inc() const 00297 { 00298 if (LaGenMatInt::size(1) == 1 ) 00299 return LaGenMatInt::inc(0); 00300 else 00301 return LaGenMatInt::inc(1) * LaGenMatInt::gdim(0); 00302 // NOTE: This was changed on 2005-03-04 because without the dim[0] 00303 // this gives wrong results on non-unit-stride submatrix views. 00304 } 00305 00306 inline LaIndex LaVectorInt::index() const 00307 { 00308 if (LaGenMatInt::size(1) == 1 ) 00309 return LaGenMatInt::index(0); 00310 else 00311 return LaGenMatInt::index(1); 00312 } 00313 00314 inline int LaVectorInt::start() const 00315 { 00316 if (LaGenMatInt::size(1) == 1 ) 00317 return LaGenMatInt::start(0); 00318 else 00319 return LaGenMatInt::start(1); 00320 } 00321 00322 inline int LaVectorInt::end() const 00323 { 00324 if (LaGenMatInt::size(1) == 1 ) 00325 return LaGenMatInt::end(0); 00326 else 00327 return LaGenMatInt::end(1); 00328 } 00329 00330 #endif 00331 // _LA_VECTOR_INT_H_