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 00029 #ifndef _LA_VECTOR_DOUBLE_H_ 00030 #define _LA_VECTOR_DOUBLE_H_ 00031 00032 #include "lafnames.h" 00033 #include LA_GEN_MAT_DOUBLE_H 00034 00035 00052 class DLLIMPORT LaVectorDouble: public LaGenMatDouble 00053 { 00054 public: 00055 00059 LaVectorDouble(); 00060 00062 LaVectorDouble(int n); 00063 00066 LaVectorDouble(int m, int n); 00067 00070 LaVectorDouble(double* v, int n); 00071 00075 //LaVectorDouble(double* v, int m, int n); 00076 00080 LaVectorDouble(const LaGenMatDouble& s); 00081 00090 void resize(int n); 00091 00097 void resize(int m, int n); 00098 00100 00104 inline int size() const; 00105 00111 inline int inc() const; 00112 00117 inline int start() const; 00118 00123 inline int end() const; 00124 00129 inline LaIndex index() const; 00131 00147 inline double& operator()(int i); 00148 00162 inline const double& operator()(int i) const ; 00163 00175 inline LaVectorDouble operator()(const LaIndex& i); 00176 00188 inline LaVectorDouble operator()(const LaIndex& i) const; 00190 00197 LaVectorDouble& operator=(double s); 00198 00206 LaVectorDouble& operator=(const LaGenMatDouble&s); 00207 00216 LaVectorDouble& inject(const LaGenMatDouble &s); 00217 00222 LaVectorDouble& copy(const LaGenMatDouble &s); 00223 00231 LaVectorDouble& ref(const LaGenMatDouble &); 00233 }; 00234 00235 // NOTE: we default to column vectors, since matrices are column 00236 // oriented. 00237 00238 inline LaVectorDouble::LaVectorDouble() : LaGenMatDouble(0, 1) {} 00239 inline LaVectorDouble::LaVectorDouble(int i) : LaGenMatDouble(i, 1) {} 00240 00241 // NOTE: one shouldn't be using this method to initalize, but 00242 // it is here so that the constructor can be overloaded with 00243 // a runtime test. 00244 // 00245 inline LaVectorDouble::LaVectorDouble(int m, int n) : LaGenMatDouble(m, n) 00246 { 00247 assert(n == 1 || m == 1); 00248 } 00249 00250 inline LaVectorDouble::LaVectorDouble(double *d, int m) : 00251 LaGenMatDouble(d, m, 1) {} 00252 00253 #if 0 00254 inline LaVectorDouble::LaVectorDouble(double *d, int m, int n) : 00255 LaGenMatDouble(d, m, n) {} 00256 #endif 00257 00258 inline LaVectorDouble::LaVectorDouble(const LaGenMatDouble& G) : 00259 LaGenMatDouble(G) 00260 { 00261 assert(G.size(0) == 1 || G.size(1) == 1); 00262 } 00263 00264 inline void LaVectorDouble::resize(int i) 00265 { 00266 // Always resizes to column vector, similar to the one-argument 00267 // constructor. If you want a row vector, use the two-argument 00268 // resize(). 00269 LaGenMatDouble::resize(i, 1); // column vector 00270 } 00271 00272 inline void LaVectorDouble::resize(int m, int n) 00273 { 00274 assert(n == 1 || m == 1); 00275 LaGenMatDouble::resize(m, n); 00276 } 00277 00278 00279 //note that vectors can be either stored columnwise, or row-wise 00280 00281 // this will handle the 0x0 case as well. 00282 00283 inline int LaVectorDouble::size() const 00284 { 00285 return LaGenMatDouble::size(0) * LaGenMatDouble::size(1); 00286 } 00287 00288 inline double& LaVectorDouble::operator()(int i) 00289 { 00290 if (LaGenMatDouble::size(0) == 1 ) 00291 return LaGenMatDouble::operator()(0, i); 00292 else 00293 return LaGenMatDouble::operator()(i, 0); 00294 } 00295 00296 inline const double& LaVectorDouble::operator()(int i) const 00297 { 00298 if (LaGenMatDouble::size(0) == 1 ) 00299 return LaGenMatDouble::operator()(0, i); 00300 else 00301 return LaGenMatDouble::operator()(i, 0); 00302 } 00303 00304 inline LaVectorDouble LaVectorDouble::operator()(const LaIndex& I) 00305 { 00306 if (LaGenMatDouble::size(0) == 1) 00307 return LaGenMatDouble::operator()(LaIndex(0, 0), I).shallow_assign(); 00308 else 00309 return LaGenMatDouble::operator()(I, LaIndex(0, 0)).shallow_assign(); 00310 } 00311 00312 inline LaVectorDouble LaVectorDouble::operator()(const LaIndex& I) const 00313 { 00314 if (LaGenMatDouble::size(0) == 1) 00315 return LaGenMatDouble::operator()(LaIndex(0, 0), I).shallow_assign(); 00316 else 00317 return LaGenMatDouble::operator()(I, LaIndex(0, 0)).shallow_assign(); 00318 } 00319 00320 00321 inline LaVectorDouble& LaVectorDouble::copy(const LaGenMatDouble &A) 00322 { 00323 assert(A.size(0) == 1 || A.size(1) == 1); //make sure rhs is a 00324 // a vector. 00325 LaGenMatDouble::copy(A); 00326 return *this; 00327 } 00328 00329 inline LaVectorDouble& LaVectorDouble::operator=(const LaGenMatDouble &A) 00330 { 00331 return copy(A); 00332 } 00333 00334 inline LaVectorDouble& LaVectorDouble::ref(const LaGenMatDouble &A) 00335 { 00336 assert(A.size(0) == 1 || A.size(1) == 1); 00337 LaGenMatDouble::ref(A); 00338 return *this; 00339 } 00340 00341 inline LaVectorDouble& LaVectorDouble::operator=(double d) 00342 { 00343 LaGenMatDouble::operator=(d); 00344 return *this; 00345 } 00346 00347 inline LaVectorDouble& LaVectorDouble::inject(const LaGenMatDouble &A) 00348 { 00349 assert(A.size(0) == 1 || A.size(1) == 1); 00350 LaGenMatDouble::inject(A); 00351 return *this; 00352 } 00353 00354 inline int LaVectorDouble::inc() const 00355 { 00356 if (LaGenMatDouble::size(1) == 1 ) 00357 return LaGenMatDouble::inc(0); 00358 else 00359 return LaGenMatDouble::inc(1) * LaGenMatDouble::gdim(0); 00360 // NOTE: This was changed on 2005-03-04 because without the dim[0] 00361 // this gives wrong results on non-unit-stride submatrix views. 00362 } 00363 00364 inline LaIndex LaVectorDouble::index() const 00365 { 00366 if (LaGenMatDouble::size(1) == 1 ) 00367 return LaGenMatDouble::index(0); 00368 else 00369 return LaGenMatDouble::index(1); 00370 } 00371 00372 inline int LaVectorDouble::start() const 00373 { 00374 if (LaGenMatDouble::size(1) == 1 ) 00375 return LaGenMatDouble::start(0); 00376 else 00377 return LaGenMatDouble::start(1); 00378 } 00379 00380 inline int LaVectorDouble::end() const 00381 { 00382 if (LaGenMatDouble::size(1) == 1 ) 00383 return LaGenMatDouble::end(0); 00384 else 00385 return LaGenMatDouble::end(1); 00386 } 00387 00388 #endif 00389 // _LA_VECTOR_DOUBLE_H_