00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef HxVector_h
00013 #define HxVector_h
00014
00015 #include "HxIoFwd.h"
00016 #include "HxStd.h"
00017
00018 #include "HxEnvironment.h"
00019
00020 template<class C> class L_HXBASIS HxTMatrix ;
00021 L_HXBASIS typedef HxTMatrix<double> HxMatrix ;
00022
00027 class L_HXBASIS HxVector {
00028 public:
00029
00031
00033 HxVector();
00034
00036 HxVector(int n);
00037
00039 HxVector(int n, double* data);
00040
00042 HxVector(double a0, double a1);
00043
00045 HxVector(double a0, double a1, double a2);
00046
00048 HxVector(double a0, double a1, double a2, double a3);
00049
00051 HxVector(const HxVector& v);
00052
00054 HxVector(const HxMatrix& m);
00056
00057 ~HxVector();
00058
00059
00061
00063 int nElem() const;
00064
00066 int valid() const;
00068
00070
00072 HxVector& operator=(double a);
00073
00075 HxVector& operator=(const HxVector& v);
00076
00078 double& operator[](int i) const;
00079
00081 HxVector operator-() const;
00082
00084 friend L_HXBASIS double operator*(const HxVector& a, const HxVector& b);
00085
00087 friend HxVector operator*(const double a, const HxVector& b);
00088
00090 friend HxVector operator*(const HxVector& a, const double b);
00091
00093 friend HxVector operator/(const HxVector& a, double b);
00094
00096 friend HxVector operator/(double a, const HxVector& b);
00097
00099 friend L_HXBASIS HxVector operator+(const HxVector& a, const HxVector& b);
00100
00102 friend HxVector operator+(const HxVector& a, double b);
00103
00105 friend HxVector operator+(double a, const HxVector& b);
00106
00108 friend L_HXBASIS HxVector operator-(const HxVector& a, const HxVector& b);
00109
00111 friend HxVector operator-(const HxVector& a, double b);
00112
00114 friend HxVector operator-(double a, const HxVector& b);
00115
00117 friend L_HXBASIS int operator==(const HxVector& a, const HxVector& b);
00118
00120 friend int operator!=(const HxVector& a, const HxVector& b);
00121
00123
00125
00127 HxMatrix t() const;
00128
00130 HxMatrix diag() const;
00131
00135 HxVector add(const HxVector& b) const;
00136
00140 HxVector add(const double val) const;
00141
00145 HxVector sub(const HxVector& b) const;
00146
00150 HxVector sub(const double val) const;
00151
00155 HxVector mul(const HxVector& b) const;
00156
00160 HxVector mul(const HxMatrix& m) const;
00161
00165 HxVector mul(const double val) const;
00166
00170 HxVector div(const double val) const;
00171
00173 HxVector sin() const;
00174
00176 HxVector cos() const;
00177
00179 HxVector tan() const;
00180
00182 HxVector sinh() const;
00183
00185 HxVector cosh() const;
00186
00188 HxVector tanh() const;
00189
00191 HxVector exp() const;
00192
00194 HxVector log() const;
00195
00197 HxVector sqrt() const;
00198
00200 HxVector abs() const;
00201
00203 HxVector sgn() const;
00204
00206 HxVector map(double (*f)(double)) const;
00208
00209 STD_OSTREAM& put(STD_OSTREAM& os) const;
00210
00211 private:
00212
00213
00214
00215
00216 int _n;
00217 double* _data;
00218 };
00219
00220 inline HxVector::HxVector()
00221 {
00222 _n = 0;
00223 _data = 0;
00224 }
00225
00226 inline HxVector::HxVector(int n)
00227 {
00228 _n = n;
00229 _data = new double[_n];
00230 }
00231
00232 inline HxVector::HxVector(int n, double* data)
00233 {
00234 _n = n;
00235 _data = data;
00236 }
00237
00238 inline HxVector::HxVector(double a0, double a1)
00239 {
00240 _n = 2;
00241 _data = new double[_n];
00242 _data[0] = a0;
00243 _data[1] = a1;
00244 }
00245
00246 inline HxVector::HxVector(double a0, double a1, double a2)
00247 {
00248 _n = 3;
00249 _data = new double[_n];
00250 _data[0] = a0;
00251 _data[1] = a1;
00252 _data[2] = a2;
00253 }
00254
00255 inline HxVector::HxVector(double a0, double a1, double a2, double a3)
00256 {
00257 _n = 4;
00258 _data = new double[_n];
00259 _data[0] = a0;
00260 _data[1] = a1;
00261 _data[2] = a2;
00262 _data[3] = a3;
00263 }
00264
00265 inline HxVector::HxVector(const HxVector& v)
00266 {
00267 _n = v.nElem();
00268 _data = new double[_n];
00269
00270 double* t = v._data;
00271 double* u = _data;
00272 int i = v.nElem();
00273 while (--i >= 0)
00274 *u++ = *t++;
00275 }
00276
00277 inline HxVector::~HxVector()
00278 {
00279 delete [] _data;
00280 }
00281
00282 inline int
00283 HxVector::nElem() const
00284 {
00285 return _n;
00286 }
00287
00288 inline int
00289 HxVector::valid() const
00290 {
00291 return (_n != 0);
00292 }
00293
00294 inline HxVector&
00295 HxVector::operator=(double a)
00296 {
00297 int i = nElem();
00298 double *t = _data;
00299 while (--i >= 0)
00300 *t++ = a;
00301 return *this;
00302 }
00303
00304 inline HxVector&
00305 HxVector::operator=(const HxVector& v)
00306 {
00307 if (this != &v) {
00308 delete [] _data;
00309 _n = v.nElem();
00310 _data = new double [_n];
00311 double *t = _data;
00312 double *u = v._data;
00313 int i = v.nElem();
00314 while (--i >= 0)
00315 *t++ = *u++;
00316 }
00317 return *this;
00318 }
00319
00320 inline double&
00321 HxVector::operator[](int i) const
00322 {
00323 return _data[i];
00324 }
00325
00326 inline HxVector
00327 HxVector::operator-() const
00328 {
00329 HxVector m(*this);
00330 double* t = m._data;
00331 double* u = _data;
00332 int i = nElem();
00333 while (--i >= 0)
00334 *t++ = -(*u++);
00335 return m;
00336 }
00337
00338 inline HxVector
00339 operator*(const HxVector& a, double b)
00340 {
00341 HxVector m(a);
00342 double* t = m._data;
00343 double* u = a._data;
00344 int i = a.nElem();
00345 while (--i >= 0)
00346 *t++ = *u++ * b;
00347 return m;
00348 }
00349
00350 inline HxVector
00351 operator*(double a, const HxVector &b)
00352 {
00353 HxVector m(b);
00354 double* t = m._data;
00355 double* u = b._data;
00356 int i = b.nElem();
00357 while (--i >= 0)
00358 *t++ = a * *u++;
00359 return m;
00360 }
00361
00362 inline HxVector
00363 operator/(const HxVector &a, double b)
00364 {
00365 HxVector m(a);
00366 double* t = m._data;
00367 double* u = a._data;
00368 int i = a.nElem();
00369 while (--i >= 0)
00370 *t++ = *u++ / b;
00371 return m;
00372 }
00373
00374 inline HxVector
00375 operator/(double a, const HxVector &b)
00376 {
00377 HxVector m(b);
00378 double* t = m._data;
00379 double* u = b._data;
00380 int i = b.nElem();
00381 while (--i >= 0)
00382 *t++ = a / *u++;
00383 return m;
00384 }
00385
00386 inline HxVector
00387 operator+(const HxVector &a, double b)
00388 {
00389 HxVector m(a);
00390 double* t = m._data;
00391 double* u = a._data;
00392 int i = a.nElem();
00393 while (--i >= 0)
00394 *t++ = *u++ + b;
00395 return m;
00396 }
00397
00398 inline HxVector
00399 operator+(double a, const HxVector &b)
00400 {
00401 HxVector m(b);
00402 double* t = m._data;
00403 double* u = b._data;
00404 int i = b.nElem();
00405 while (--i >= 0)
00406 *t++ = a + *u++;
00407 return m;
00408 }
00409
00410 inline HxVector
00411 operator-(const HxVector &a, double b)
00412 {
00413 HxVector m(a);
00414 double* t = m._data;
00415 double* u = a._data;
00416 int i = a.nElem();
00417 while (--i >= 0)
00418 *t++ = *u++ - b;
00419 return m;
00420 }
00421
00422 inline HxVector
00423 operator-(double a, const HxVector &b)
00424 {
00425 HxVector m(b);
00426 double* t = m._data;
00427 double* u = b._data;
00428 int i = b.nElem();
00429 while (--i >= 0)
00430 *t++ = a - *u++;
00431 return m;
00432 }
00433
00434 inline int
00435 operator!=(const HxVector &a, const HxVector &b)
00436 {
00437 return !(a == b);
00438 }
00439
00440
00441 inline STD_OSTREAM&
00442 operator<<(STD_OSTREAM& os, const HxVector v)
00443 {
00444 return v.put(os);
00445 }
00446
00447
00448 inline HxVector
00449 HxVector::map(double (*f)(double)) const
00450 {
00451 HxVector m(*this);
00452 double* t = m._data;
00453 double* u = _data;
00454 int i = nElem();
00455 while (--i >= 0)
00456 *t++ = f(*u++);
00457 return m;
00458 }
00459
00460 inline STD_OSTREAM&
00461 HxVector::put(STD_OSTREAM& s) const
00462 {
00463
00464 s << "( el:";
00465 s << _n << STD_ENDL ;
00466
00467 double* t = _data ;
00468
00469 for(int i=0;i<_n;i++)
00470 s << *t++ << " ";
00471
00472 s << ")" << STD_ENDL;
00473 return s;
00474 }
00475
00476
00477 L_HXBASIS double operator*(const HxVector& a, const HxVector& b);
00478 L_HXBASIS HxVector operator+(const HxVector& a, const HxVector& b);
00479 L_HXBASIS HxVector operator-(const HxVector& a, const HxVector& b);
00480 L_HXBASIS int operator==(const HxVector& a, const HxVector& b);
00481
00482 #endif