C-XSC - A C++ Class Library for Extended Scientific Computing 2.5.4
rvector.inl
1/*
2** CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
3**
4** Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
5** Universitaet Karlsruhe, Germany
6** (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
7** Universitaet Wuppertal, Germany
8**
9** This library is free software; you can redistribute it and/or
10** modify it under the terms of the GNU Library General Public
11** License as published by the Free Software Foundation; either
12** version 2 of the License, or (at your option) any later version.
13**
14** This library is distributed in the hope that it will be useful,
15** but WITHOUT ANY WARRANTY; without even the implied warranty of
16** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17** Library General Public License for more details.
18**
19** You should have received a copy of the GNU Library General Public
20** License along with this library; if not, write to the Free
21** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22*/
23
24/* CVS $Id: rvector.inl,v 1.26 2014/01/30 17:23:48 cxsc Exp $ */
25
26#ifndef _CXSC_RVECTOR_INL_INCLUDED
27#define _CXSC_RVECTOR_INL_INCLUDED
28
29#include "rvector.hpp"
30#include "intvector.hpp"
31
32namespace cxsc {
33
37 INLINE rvector::rvector () noexcept:dat(NULL),l(1),u(0),size(0)
38 {
39 }
40
46 INLINE rvector::rvector(const int &i) noexcept:l(1),u(i),size(i)
47 {
48 dat=new real[i];
49 }
50
51#ifdef OLD_CXSC
52 INLINE rvector::rvector(const class index &i) noexcept:l(1),u(i._int()),size(i._int())
53 {
54 dat=new real[i._int()];
55 }
56#endif
63 INLINE rvector::rvector(const int &i1,const int &i2)
64#if(CXSC_INDEX_CHECK)
65 :l(i1),u(i2),size(i2-i1+1)
66#else
67 noexcept:l(i1),u(i2),size(i2-i1+1)
68#endif
69 {
70#if(CXSC_INDEX_CHECK)
71 if(i1>i2) cxscthrow(ERROR_RVECTOR_WRONG_BOUNDARIES("rvector::rvector(const int &i1,const int &i2)"));
72#endif
73 dat=new real[size];
74 }
75
76 INLINE rvector::rvector(const rvector_slice &rs) noexcept:l(rs.start),u(rs.end),size(rs.end-rs.start+1)
77 {
78 dat=new real[size];
79 for(int i=0, j=l-rs.l;i<size;i++,j++)
80 dat[i]=rs.dat[j];
81 }
82
83 INLINE rvector::rvector(const rvector &v) noexcept:l(v.l),u(v.u),size(v.size)
84 {
85 dat=new real[size];
86 for (int i=0;i<size;i++)
87 dat[i]=v.dat[i];
88 }
89
90 INLINE rvector::rvector(const real &r) noexcept:l(1),u(1),size(1)
91 {
92 dat=new real[1];
93 *dat=r;
94 }
95
96 INLINE rvector::rvector(const intvector& v) : l(Lb(v)),u(Ub(v)),size(VecLen(v)) {
97 dat=new real[size];
98 for(int i=0;i<size;i++)
99 dat[i] = v[i+l];
100 }
101
102 INLINE real & rvector::operator [](const int &i) const
103#if(CXSC_INDEX_CHECK)
104
105#else
106 noexcept
107#endif
108 {
109#if(CXSC_INDEX_CHECK)
110 if(i<l||i>u) cxscthrow(ERROR_RVECTOR_ELEMENT_NOT_IN_VEC("real & rvector::operator [](const int &i) const"));
111#endif
112 return dat[i-l];
113 }
114
115 INLINE real & rvector::operator [](const int &i)
116#if(CXSC_INDEX_CHECK)
117
118#else
119 noexcept
120#endif
121 {
122#if(CXSC_INDEX_CHECK)
123 if(i<l||i>u) cxscthrow(ERROR_RVECTOR_ELEMENT_NOT_IN_VEC("real & rvector::operator [](const int &i)"));
124#endif
125 return dat[i-l];
126 }
127
128 INLINE real & rvector_slice::operator [](const int &i)
129#if(CXSC_INDEX_CHECK)
130
131#else
132 noexcept
133#endif
134 {
135#if(CXSC_INDEX_CHECK)
136 if(i<start||i>end) cxscthrow(ERROR_RVECTOR_ELEMENT_NOT_IN_VEC("real & rvector_slice::operator [](const int &i)"));
137#endif
138 return dat[i-l];
139 }
140
141 INLINE real & rvector_slice::operator [](const int &i) const
142#if(CXSC_INDEX_CHECK)
143
144#else
145 noexcept
146#endif
147 {
148#if(CXSC_INDEX_CHECK)
149 if(i<start||i>end) cxscthrow(ERROR_RVECTOR_ELEMENT_NOT_IN_VEC("real & rvector_slice::operator [](const int &i) const"));
150#endif
151 return dat[i-l];
152 }
153
154
165#if(CXSC_INDEX_CHECK)
166
167#else
168 noexcept
169#endif
170 {
171#if(CXSC_INDEX_CHECK)
172 if(1<l||i>u) cxscthrow(ERROR_RVECTOR_SUB_ARRAY_TOO_BIG("rvector_slice rvector::operator ()(const int &i)"));
173#endif
174 return rvector_slice(*this,1,i);
175 }
176
187 INLINE rvector_slice rvector::operator ()(const int &i1,const int &i2)
188#if(CXSC_INDEX_CHECK)
189
190#else
191 noexcept
192#endif
193 {
194#if(CXSC_INDEX_CHECK)
195 if(i1<l||i2>u) cxscthrow(ERROR_RVECTOR_SUB_ARRAY_TOO_BIG("rvector_slice rvector::operator ()(const int &i1,const int &i2)"));
196#endif
197 return rvector_slice(*this,i1,i2);
198 }
199
201#if(CXSC_INDEX_CHECK)
202
203#else
204 noexcept
205#endif
206 {
207#if(CXSC_INDEX_CHECK)
208 if(1<start||i>end) cxscthrow(ERROR_RVECTOR_SUB_ARRAY_TOO_BIG("rvector_slice rvector_slice::operator ()(const int &i)"));
209#endif
210 return rvector_slice(*this,1,i);
211 }
212
213 INLINE rvector_slice rvector_slice::operator ()(const int &i1,const int &i2)
214#if(CXSC_INDEX_CHECK)
215
216#else
217 noexcept
218#endif
219 {
220#if(CXSC_INDEX_CHECK)
221 if(i1<start||i2>end) cxscthrow(ERROR_RVECTOR_SUB_ARRAY_TOO_BIG("rvector_slice rvector_slice::operator ()(const int &i1,const int &i2)"));
222#endif
223 return rvector_slice(*this,i1,i2);
224 }
225
226 INLINE real::real(const rvector &rv)
227#if(CXSC_INDEX_CHECK)
228
229#else
230 noexcept
231#endif
232 {
233#if(CXSC_INDEX_CHECK)
234 if(rv.size>1) cxscthrow(ERROR_RVECTOR_TYPE_CAST_OF_THICK_OBJ("real::real(const rvector &rv)"));
235 else if(rv.size<1) cxscthrow(ERROR_RVECTOR_USE_OF_UNINITIALIZED_OBJ("real::real(const rvector &rv)"));
236#endif
237 *this=rv.dat[0];
238 }
239
240 INLINE real::real(const rvector_slice &sl)
241#if(CXSC_INDEX_CHECK)
242
243#else
244 noexcept
245#endif
246 {
247#if(CXSC_INDEX_CHECK)
248 if(sl.size>1) cxscthrow(ERROR_RVECTOR_TYPE_CAST_OF_THICK_OBJ("real::real(const rvector_slice &sl)"));
249 else if(sl.size<1) cxscthrow(ERROR_RVECTOR_USE_OF_UNINITIALIZED_OBJ("real::real(const rvector_slice &sl)"));
250#endif
251 *this=sl.dat[sl.start-sl.l];
252 }
253
254 INLINE rvector &rvector::operator =(const rvector &rv) noexcept { return _vvassign<rvector,rvector,real>(*this,rv); }
255 INLINE rvector &rvector::operator =(const real &r) noexcept { return _vsassign<rvector,real>(*this,r); }
256 INLINE rvector::operator void*() noexcept { return _vvoid(*this); }
257
259#if(CXSC_INDEX_CHECK)
260
261#else
262 noexcept
263#endif
264 { return _vsvsassign<rvector_slice,rvector_slice>(*this,sl); }
266#if(CXSC_INDEX_CHECK)
267
268#else
269 noexcept
270#endif
271 { return _vsvassign<rvector_slice,rvector>(*this,rv); }
272 INLINE rvector_slice & rvector_slice::operator =(const real &r) noexcept { return _vssassign<rvector_slice,real>(*this,r); }
273 INLINE rvector_slice::operator void*() noexcept { return _vsvoid(*this); }
274
275//======================== Vector Functions =============================
281 INLINE rvector _rvector(const real &r) noexcept { return rvector(r); }
282
283 INLINE void Resize(rvector &rv) noexcept { _vresize(rv); }
284 INLINE void Resize(rvector &rv, const int &len)
285#if(CXSC_INDEX_CHECK)
286
287#else
288 noexcept
289#endif
290 { _vresize<class rvector,class real>(rv,len); }
291 INLINE void Resize(rvector &rv, const int &lb, const int &ub)
292#if(CXSC_INDEX_CHECK)
293
294#else
295 noexcept
296#endif
297 { _vresize<class rvector,class real>(rv,lb,ub); }
298
299 INLINE rvector abs(const rvector &rv) noexcept { return _vabs<rvector,rvector>(rv); }
300 INLINE rvector abs(const rvector_slice &sl) noexcept { return _vsabs<rvector_slice,rvector>(sl); }
301 INLINE bool operator !(const rvector &rv) noexcept { return _vnot(rv); }
302 INLINE bool operator !(const rvector_slice &sl) noexcept { return _vsnot(sl); }
303
304//======================= Vector / Scalar ===============================
305
306 INLINE rvector operator *(const rvector &rv, const real &s) noexcept { return _vsmult<rvector,real,rvector>(rv,s); }
307 INLINE rvector operator *(const rvector_slice &sl, const real &s) noexcept { return _vssmult<rvector_slice,real,rvector>(sl,s); }
308 INLINE rvector operator *(const real &s, const rvector &rv) noexcept { return _vsmult<rvector,real,rvector>(rv,s); }
309 INLINE rvector operator *(const real &s, const rvector_slice &sl) noexcept { return _vssmult<rvector_slice,real,rvector>(sl,s); }
310 INLINE rvector &operator *=(rvector &rv,const real &r) noexcept { return _vsmultassign(rv,r); }
311 INLINE rvector_slice &rvector_slice::operator *=(const real &r) noexcept { return _vssmultassign(*this,r); }
312
313 INLINE rvector operator /(const rvector &rv, const real &s) noexcept { return _vsdiv<rvector,real,rvector>(rv,s); }
314 INLINE rvector operator /(const rvector_slice &sl, const real &s) noexcept { return _vssdiv<rvector_slice,real,rvector>(sl,s); }
315 INLINE rvector &operator /=(rvector &rv,const real &r) noexcept { return _vsdivassign(rv,r); }
316 INLINE rvector_slice &rvector_slice::operator /=(const real &r) noexcept { return _vssdivassign(*this,r); }
317
318//======================= Vector / Vector ===============================
319
320 INLINE rvector &rvector::operator =(const rvector_slice &sl) noexcept { return _vvsassign<rvector,rvector_slice,real>(*this,sl); }
321
322
323
324 INLINE real operator *(const rvector & rv1, const rvector &rv2)
325#if(CXSC_INDEX_CHECK)
326
327#else
328 noexcept
329#endif
330 { return _vvmult<rvector,rvector,real>(rv1,rv2); }
331 INLINE real operator *(const rvector_slice &sl, const rvector &rv)
332#if(CXSC_INDEX_CHECK)
333
334#else
335 noexcept
336#endif
337 { return _vsvmult<rvector_slice,rvector,real>(sl,rv); }
338 INLINE real operator *(const rvector &rv, const rvector_slice &sl)
339#if(CXSC_INDEX_CHECK)
340
341#else
342 noexcept
343#endif
344 { return _vsvmult<rvector_slice,rvector,real>(sl,rv); }
345 INLINE real operator *(const rvector_slice & sl1, const rvector_slice &sl2)
346#if(CXSC_INDEX_CHECK)
347
348#else
349 noexcept
350#endif
351 { return _vsvsmult<rvector_slice,rvector_slice,real>(sl1,sl2); }
352
353 INLINE const rvector &operator +(const rvector &rv) noexcept { return rv; }
354 INLINE rvector operator +(const rvector_slice &sl) noexcept { return sl; }
355 INLINE rvector operator +(const rvector &rv1, const rvector &rv2)
356#if(CXSC_INDEX_CHECK)
357
358#else
359 noexcept
360#endif
361 { return _vvplus<rvector,rvector,rvector>(rv1,rv2); }
362 INLINE rvector operator +(const rvector &rv, const rvector_slice &sl)
363#if(CXSC_INDEX_CHECK)
364
365#else
366 noexcept
367#endif
368 { return _vvsplus<rvector,rvector_slice,rvector>(rv,sl); }
369 INLINE rvector operator +(const rvector_slice &sl, const rvector &rv)
370#if(CXSC_INDEX_CHECK)
371
372#else
373 noexcept
374#endif
375 { return _vvsplus<rvector,rvector_slice,rvector>(rv,sl); }
376 INLINE rvector operator +(const rvector_slice &sl1, const rvector_slice &sl2)
377#if(CXSC_INDEX_CHECK)
378
379#else
380 noexcept
381#endif
382 { return _vsvsplus<rvector_slice,rvector_slice,rvector>(sl1,sl2); }
383 INLINE rvector & operator +=(rvector &rv1, const rvector &rv2)
384#if(CXSC_INDEX_CHECK)
385
386#else
387 noexcept
388#endif
389 { return _vvplusassign(rv1,rv2); }
390 INLINE rvector &operator +=(rvector &rv, const rvector_slice &sl)
391#if(CXSC_INDEX_CHECK)
392
393#else
394 noexcept
395#endif
396 { return _vvsplusassign(rv,sl); }
398#if(CXSC_INDEX_CHECK)
399
400#else
401 noexcept
402#endif
403 { return _vsvplusassign(*this,rv); }
405#if(CXSC_INDEX_CHECK)
406
407#else
408 noexcept
409#endif
410 { return _vsvsplusassign(*this,sl2); }
411
412 INLINE rvector operator -(const rvector &rv) noexcept { return _vminus(rv); }
413 INLINE rvector operator -(const rvector_slice &sl) noexcept { return _vsminus<rvector_slice,rvector>(sl); }
414 INLINE rvector operator -(const rvector &rv1, const rvector &rv2)
415#if(CXSC_INDEX_CHECK)
416
417#else
418 noexcept
419#endif
420 { return _vvminus<rvector,rvector,rvector>(rv1,rv2); }
421 INLINE rvector operator -(const rvector &rv, const rvector_slice &sl)
422#if(CXSC_INDEX_CHECK)
423
424#else
425 noexcept
426#endif
427 { return _vvsminus<rvector,rvector_slice,rvector>(rv,sl); }
428 INLINE rvector operator -(const rvector_slice &sl, const rvector &rv)
429#if(CXSC_INDEX_CHECK)
430
431#else
432 noexcept
433#endif
434 { return _vsvminus<rvector_slice,rvector,rvector>(sl,rv); }
435 INLINE rvector operator -(const rvector_slice &sl1, const rvector_slice &sl2)
436#if(CXSC_INDEX_CHECK)
437
438#else
439 noexcept
440#endif
441 { return _vsvsminus<rvector_slice,rvector_slice,rvector>(sl1,sl2); }
442 INLINE rvector & operator -=(rvector &rv1, const rvector &rv2)
443#if(CXSC_INDEX_CHECK)
444
445#else
446 noexcept
447#endif
448 { return _vvminusassign(rv1,rv2); }
449 INLINE rvector &operator -=(rvector &rv, const rvector_slice &sl)
450#if(CXSC_INDEX_CHECK)
451
452#else
453 noexcept
454#endif
455 { return _vvsminusassign(rv,sl); }
457#if(CXSC_INDEX_CHECK)
458
459#else
460 noexcept
461#endif
462 { return _vsvminusassign(*this,rv); }
464#if(CXSC_INDEX_CHECK)
465
466#else
467 noexcept
468#endif
469 { return _vsvsminusassign(*this,sl2); }
470
471 INLINE bool operator ==(const rvector &rv1, const rvector &rv2) noexcept { return _vveq(rv1,rv2); }
472 INLINE bool operator ==(const rvector_slice &sl1, const rvector_slice &sl2) noexcept { return _vsvseq(sl1,sl2); }
473 INLINE bool operator ==(const rvector_slice &sl, const rvector &rv) noexcept { return _vsveq(sl,rv); }
474 INLINE bool operator ==(const rvector &rv, const rvector_slice &sl) noexcept { return _vsveq(sl,rv); }
475 INLINE bool operator !=(const rvector &rv1, const rvector &rv2) noexcept { return _vvneq(rv1,rv2); }
476 INLINE bool operator !=(const rvector_slice &sl1, const rvector_slice &sl2) noexcept { return _vsvsneq(sl1,sl2); }
477 INLINE bool operator !=(const rvector_slice &sl, const rvector &rv) noexcept { return _vsvneq(sl,rv); }
478 INLINE bool operator !=(const rvector &rv, const rvector_slice &sl) noexcept { return _vsvneq(sl,rv); }
479 INLINE bool operator <(const rvector &rv1, const rvector &rv2) noexcept { return _vvless(rv1,rv2); }
480 INLINE bool operator <(const rvector_slice &sl1, const rvector_slice &sl2) noexcept { return _vsvsless(sl1,sl2); }
481 INLINE bool operator < (const rvector_slice &sl, const rvector &rv) noexcept { return _vsvless(sl,rv); }
482 INLINE bool operator < (const rvector &rv, const rvector_slice &sl) noexcept { return _vvsless(rv,sl); }
483 INLINE bool operator <=(const rvector &rv1, const rvector &rv2) noexcept { return _vvleq(rv1,rv2); }
484 INLINE bool operator <=(const rvector_slice &sl1, const rvector_slice &sl2) noexcept { return _vsvsleq(sl1,sl2); }
485 INLINE bool operator <=(const rvector_slice &sl, const rvector &rv) noexcept { return _vsvleq(sl,rv); }
486 INLINE bool operator <=(const rvector &rv, const rvector_slice &sl) noexcept { return _vvsleq(rv,sl); }
487 INLINE bool operator >(const rvector &rv1, const rvector &rv2) noexcept { return _vvless(rv2,rv1); }
488 INLINE bool operator >(const rvector_slice &sl1, const rvector_slice &sl2) noexcept { return _vsvsless(sl2,sl1); }
489 INLINE bool operator >(const rvector_slice &sl, const rvector &rv) noexcept { return _vvsless(rv,sl); }
490 INLINE bool operator >(const rvector &rv, const rvector_slice &sl) noexcept { return _vsvless(sl,rv); }
491 INLINE bool operator >=(const rvector &rv1, const rvector &rv2) noexcept { return _vvleq(rv2,rv1); }
492 INLINE bool operator >=(const rvector_slice &sl1, const rvector_slice &sl2) noexcept { return _vsvsleq(sl2,sl1); }
493 INLINE bool operator >=(const rvector_slice &sl, const rvector &rv) noexcept { return _vvsleq(rv,sl); }
494 INLINE bool operator >=(const rvector &rv, const rvector_slice &sl) noexcept { return _vsvleq(sl,rv); }
495
496 INLINE std::ostream &operator <<(std::ostream &s, const rvector &rv) noexcept { return _vout(s,rv); }
497 INLINE std::ostream &operator <<(std::ostream &o, const rvector_slice &sl) noexcept { return _vsout(o,sl); }
498 INLINE std::istream &operator >>(std::istream &s, rvector &rv) noexcept { return _vin(s,rv); }
499 INLINE std::istream &operator >>(std::istream &s, rvector_slice &rv) noexcept { return _vsin(s,rv); }
500
503 rvector x(*this);
504 for(int i=0 ; i<VecLen(x) ; i++)
505 x[i+Lb(x)] = (*this)[p[i+Lb(p)]+Lb(*this)];
506 return x;
507 }
508
509
510
511
512} // namespace cxsc
513
514#endif
515
The Data Type intvector.
Definition intvector.hpp:52
The Scalar Type real.
Definition real.hpp:114
real(void) noexcept
Constructor of class real.
Definition real.hpp:122
The Data Type rvector_slice.
Definition rvector.hpp:1064
rvector_slice & operator+=(const rvector &rv) noexcept
Implementation of addition and allocation operation.
Definition rvector.inl:397
real & operator[](const int &i) noexcept
Operator for accessing the single elements of the vector.
Definition rvector.inl:128
rvector_slice & operator-=(const rvector &rv) noexcept
Implementation of subtraction and allocation operation.
Definition rvector.inl:456
rvector_slice & operator/=(const real &r) noexcept
Implementation of division and allocation operation.
Definition rvector.inl:316
rvector_slice & operator=(const rvector_slice &sl) noexcept
Implementation of standard assigning operator.
Definition rvector.inl:258
rvector_slice & operator()() noexcept
Operator for accessing the whole vector.
Definition rvector.hpp:1514
rvector_slice & operator*=(const real &r) noexcept
Implementation of multiplication and allocation operation.
Definition rvector.inl:311
The Data Type rvector.
Definition rvector.hpp:58
rvector & operator=(const rvector &rv) noexcept
Implementation of standard assigning operator.
Definition rvector.inl:254
friend int VecLen(const rvector &rv) noexcept
Returns the dimension of the vector.
Definition rvector.hpp:1005
real & operator[](const int &i) const noexcept
Operator for accessing the single elements of the vector (read-only)
Definition rvector.inl:102
rvector & operator()() noexcept
Operator for accessing the whole vector.
Definition rvector.hpp:1027
rvector() noexcept
Constructor of class rvector.
Definition rvector.inl:37
friend int Lb(const rvector &rv) noexcept
Returns the lower bound of the vector.
Definition rvector.hpp:1001
The namespace cxsc, providing all functionality of the class library C-XSC.
Definition cdot.cpp:29
int VecLen(const scimatrix_subv &S)
Returns the length of the subvector.
cdotprecision & operator+=(cdotprecision &cd, const l_complex &lc) noexcept
Implementation of standard algebraic addition and allocation operation.
Definition cdot.inl:251
rvector _rvector(const real &r) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
Definition rvector.inl:281
civector operator/(const cimatrix_subv &rv, const cinterval &s) noexcept
Implementation of division operation.
Definition cimatrix.inl:730
int Ub(const cimatrix &rm, const int &i) noexcept
Returns the upper bound index.
cimatrix & operator*=(cimatrix &m, const cinterval &c) noexcept
Implementation of multiplication and allocation operation.
ivector abs(const cimatrix_subv &mv) noexcept
Returns the absolute value of the matrix.
Definition cimatrix.inl:737
civector operator*(const cimatrix_subv &rv, const cinterval &s) noexcept
Implementation of multiplication operation.
Definition cimatrix.inl:731
void Resize(cimatrix &A) noexcept
Resizes the matrix.
int Lb(const cimatrix &rm, const int &i) noexcept
Returns the lower bound index.
cimatrix & operator/=(cimatrix &m, const cinterval &c) noexcept
Implementation of division and allocation operation.