C-XSC - A C++ Class Library for Extended Scientific Computing 2.5.4
intvector.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: intvector.inl,v 1.19 2014/01/30 17:23:45 cxsc Exp $ */
25
26#ifndef _CXSC_INTVECTOR_INL_INCLUDED
27#define _CXSC_INTVECTOR_INL_INCLUDED
28
29#include "intvector.hpp"
30
31namespace cxsc {
32
33 INLINE intvector::intvector () noexcept:dat(NULL),l(1),u(0),size(0)
34 {
35 }
36
37 INLINE intvector::intvector(const int &i) noexcept:l(1),u(i),size(i)
38 {
39 dat=new int[i];
40 }
41
42#ifdef OLD_CXSC
43 INLINE intvector::intvector(const class index &i) noexcept:l(1),u(i._int()),size(i._int())
44 {
45 dat=new int[i._int()];
46 }
47#endif
48
49 INLINE intvector::intvector(const int &i1,const int &i2)
50#if(CXSC_INDEX_CHECK)
51 :l(i1),u(i2),size(i2-i1+1)
52#else
53 noexcept:l(i1),u(i2),size(i2-i1+1)
54#endif
55 {
56#if(CXSC_INDEX_CHECK)
57 if(i1>i2) cxscthrow(ERROR_INTVECTOR_WRONG_BOUNDARIES("intvector::intvector(const int &i1,const int &i2)"));
58#endif
59 dat=new int[size];
60 }
61
62 INLINE intvector::intvector(const intvector_slice &rs) noexcept:l(rs.start),u(rs.end),size(rs.end-rs.start+1)
63 {
64 dat=new int[size];
65 for(int i=0, j=l-rs.l;i<size;i++,j++)
66 dat[i]=rs.dat[j];
67 }
68
69 INLINE intvector::intvector(const intvector &v) noexcept:l(v.l),u(v.u),size(v.size)
70 {
71 dat=new int[size];
72 for (int i=0;i<size;i++)
73 dat[i]=v.dat[i];
74 }
75
76 INLINE int & intvector_slice::operator [](const int &i)
77#if(CXSC_INDEX_CHECK)
78
79#else
80 noexcept
81#endif
82 {
83#if(CXSC_INDEX_CHECK)
84 if(i<start||i>end) cxscthrow(ERROR_INTVECTOR_ELEMENT_NOT_IN_VEC("int & intvector_slice::operator [](const int &i)"));
85#endif
86 return dat[i-l];
87 }
88
89 INLINE const int & intvector_slice::operator [](const int &i) const
90#if(CXSC_INDEX_CHECK)
91
92#else
93 noexcept
94#endif
95 {
96#if(CXSC_INDEX_CHECK)
97 if(i<start||i>end) cxscthrow(ERROR_INTVECTOR_ELEMENT_NOT_IN_VEC("int & intvector_slice::operator [](const int &i)"));
98#endif
99 return dat[i-l];
100 }
101
102 INLINE const int & intvector::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_INTVECTOR_ELEMENT_NOT_IN_VEC("int & intvector::operator [](const int &i)"));
111#endif
112 return dat[i-l];
113 }
114
115 INLINE int & intvector::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_INTVECTOR_ELEMENT_NOT_IN_VEC("int & intvector::operator [](const int &i)"));
124#endif
125 return dat[i-l];
126 }
127
135#if(CXSC_INDEX_CHECK)
136
137#else
138 noexcept
139#endif
140 {
141#if(CXSC_INDEX_CHECK)
142 if(1<l||i>u) cxscthrow(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG("intvector_slice intvector::operator ()(const int &i)"));
143#endif
144 return intvector_slice(*this,1,i);
145 }
146
154 INLINE intvector_slice intvector::operator ()(const int &i1,const int &i2)
155#if(CXSC_INDEX_CHECK)
156
157#else
158 noexcept
159#endif
160 {
161#if(CXSC_INDEX_CHECK)
162 if(i1<l||i2>u) cxscthrow(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG("intvector_slice intvector::operator ()(const int &i1,const int &i2)"));
163#endif
164 return intvector_slice(*this,i1,i2);
165 }
166
168#if(CXSC_INDEX_CHECK)
169
170#else
171 noexcept
172#endif
173 {
174#if(CXSC_INDEX_CHECK)
175 if(1<start||i>end) cxscthrow(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG("intvector_slice intvector_slice::operator ()(const int &i)"));
176#endif
177 return intvector_slice(*this,1,i);
178 }
179
180 INLINE intvector_slice intvector_slice::operator ()(const int &i1,const int &i2)
181#if(CXSC_INDEX_CHECK)
182
183#else
184 noexcept
185#endif
186 {
187#if(CXSC_INDEX_CHECK)
188 if(i1<start||i2>end) cxscthrow(ERROR_INTVECTOR_SUB_ARRAY_TOO_BIG("intvector_slice intvector_slice::operator ()(const int &i1,const int &i2)"));
189#endif
190 return intvector_slice(*this,i1,i2);
191 }
192
193 INLINE intvector &intvector::operator =(const intvector &rv) noexcept { return _vvassign<intvector,intvector,int>(*this,rv); }
194 INLINE intvector &intvector::operator =(const int &r) noexcept { return _vsassign<intvector,int>(*this,r); }
195 INLINE intvector::operator void*() noexcept { return _vvoid(*this); }
196
198#if(CXSC_INDEX_CHECK)
199
200#else
201 noexcept
202#endif
203 { return _vsvsassign<intvector_slice,intvector_slice>(*this,sl); }
205#if(CXSC_INDEX_CHECK)
206
207#else
208 noexcept
209#endif
210 { return _vsvassign<intvector_slice,intvector>(*this,rv); }
211 INLINE intvector_slice & intvector_slice::operator =(const int &r) noexcept { return _vssassign<intvector_slice,int>(*this,r); }
212 INLINE intvector_slice::operator void*() noexcept { return _vsvoid(*this); }
213
214//======================== Vector Functions =============================
220 INLINE intvector _intvector(const int &r) noexcept { return intvector(r); }
221
222 INLINE void Resize(intvector &rv) noexcept { _vresize(rv); }
223 INLINE void Resize(intvector &rv, const int &len)
224#if(CXSC_INDEX_CHECK)
225
226#else
227 noexcept
228#endif
229 { _vresize<intvector,int>(rv,len); }
230 INLINE void Resize(intvector &rv, const int &lb, const int &ub)
231#if(CXSC_INDEX_CHECK)
232
233#else
234 noexcept
235#endif
236 { _vresize<intvector,int>(rv,lb,ub); }
237
238 INLINE intvector abs(const intvector &rv) noexcept { return _vabs<intvector,intvector>(rv); }
239 INLINE intvector abs(const intvector_slice &sl) noexcept { return _vsabs<intvector_slice,intvector>(sl); }
240 INLINE bool operator !(const intvector &rv) noexcept { return _vnot(rv); }
241 INLINE bool operator !(const intvector_slice &sl) noexcept { return _vsnot(sl); }
242
243//======================= Vector / Scalar ===============================
244
245 INLINE intvector operator *(const intvector &rv, const int &s) noexcept { return _vsmult<intvector,int,intvector>(rv,s); }
246 INLINE intvector operator *(const intvector_slice &sl, const int &s) noexcept { return _vssmult<intvector_slice,int,intvector>(sl,s); }
247 INLINE intvector operator *(const int &s, const intvector &rv) noexcept { return _vsmult<intvector,int,intvector>(rv,s); }
248 INLINE intvector operator *(const int &s, const intvector_slice &sl) noexcept { return _vssmult<intvector_slice,int,intvector>(sl,s); }
249 INLINE intvector &operator *=(intvector &rv,const int &r) noexcept { return _vsmultassign(rv,r); }
250 INLINE intvector_slice &intvector_slice::operator *=(const int &r) noexcept { return _vssmultassign(*this,r); }
251
252 INLINE intvector operator /(const intvector &rv, const int &s) noexcept { return _vsdiv<intvector,int,intvector>(rv,s); }
253 INLINE intvector operator /(const intvector_slice &sl, const int &s) noexcept { return _vssdiv<intvector_slice,int,intvector>(sl,s); }
254 INLINE intvector &operator /=(intvector &rv,const int &r) noexcept { return _vsdivassign(rv,r); }
255 INLINE intvector_slice &intvector_slice::operator /=(const int &r) noexcept { return _vssdivassign(*this,r); }
256
257//======================= Vector / Vector ===============================
258
259 INLINE intvector &intvector::operator =(const intvector_slice &sl) noexcept { return _vvsassign<intvector,intvector_slice,int>(*this,sl); }
260
261
262 INLINE void accumulate(dotprecision &dp, const intvector & rv1, const intvector &rv2)
263#if(CXSC_INDEX_CHECK)
264
265#else
266 noexcept
267#endif
268 { _vvaccu(dp,rv1,rv2); }
269// INLINE void accumulate(dotprecision &dp, const intvector & rv1, const intmatrix_subv &rv2);
270// INLINE void accumulate(dotprecision &dp, const intmatrix_subv & rv1, const intvector &rv2);
271 INLINE void accumulate(dotprecision &dp,const intvector_slice &sl,const intvector &rv)
272#if(CXSC_INDEX_CHECK)
273
274#else
275 noexcept
276#endif
277 { _vsvaccu(dp,sl,rv); }
278 INLINE void accumulate(dotprecision &dp,const intvector &rv,const intvector_slice &sl)
279#if(CXSC_INDEX_CHECK)
280
281#else
282 noexcept
283#endif
284 { _vsvaccu(dp,sl,rv); }
285 INLINE void accumulate(dotprecision &dp, const intvector_slice & sl1, const intvector_slice &sl2)
286#if(CXSC_INDEX_CHECK)
287
288#else
289 noexcept
290#endif
291 { _vsvsaccu(dp,sl1,sl2); }
292
293 INLINE const intvector &operator +(const intvector &rv) noexcept { return rv; }
294 INLINE intvector operator +(const intvector_slice &sl) noexcept { return sl; }
295 INLINE intvector operator +(const intvector &rv1, const intvector &rv2)
296#if(CXSC_INDEX_CHECK)
297
298#else
299 noexcept
300#endif
301 { return _vvplus<intvector,intvector,intvector>(rv1,rv2); }
302 INLINE intvector operator +(const intvector &rv, const intvector_slice &sl)
303#if(CXSC_INDEX_CHECK)
304
305#else
306 noexcept
307#endif
308 { return _vvsplus<intvector,intvector_slice,intvector>(rv,sl); }
309 INLINE intvector operator +(const intvector_slice &sl, const intvector &rv)
310#if(CXSC_INDEX_CHECK)
311
312#else
313 noexcept
314#endif
315 { return _vvsplus<intvector,intvector_slice,intvector>(rv,sl); }
316 INLINE intvector operator +(const intvector_slice &sl1, const intvector_slice &sl2)
317#if(CXSC_INDEX_CHECK)
318
319#else
320 noexcept
321#endif
322 { return _vsvsplus<intvector_slice,intvector_slice,intvector>(sl1,sl2); }
323 INLINE intvector & operator +=(intvector &rv1, const intvector &rv2)
324#if(CXSC_INDEX_CHECK)
325
326#else
327 noexcept
328#endif
329 { return _vvplusassign(rv1,rv2); }
331#if(CXSC_INDEX_CHECK)
332
333#else
334 noexcept
335#endif
336 { return _vvsplusassign(rv,sl); }
338#if(CXSC_INDEX_CHECK)
339
340#else
341 noexcept
342#endif
343 { return _vsvplusassign(*this,rv); }
345#if(CXSC_INDEX_CHECK)
346
347#else
348 noexcept
349#endif
350 { return _vsvsplusassign(*this,sl2); }
351
352 INLINE intvector operator -(const intvector &rv) noexcept { return _vminus(rv); }
353 INLINE intvector operator -(const intvector_slice &sl) noexcept { return _vsminus<intvector_slice,intvector>(sl); }
354 INLINE intvector operator -(const intvector &rv1, const intvector &rv2)
355#if(CXSC_INDEX_CHECK)
356
357#else
358 noexcept
359#endif
360 { return _vvminus<intvector,intvector,intvector>(rv1,rv2); }
361 INLINE intvector operator -(const intvector &rv, const intvector_slice &sl)
362#if(CXSC_INDEX_CHECK)
363
364#else
365 noexcept
366#endif
367 { return _vvsminus<intvector,intvector_slice,intvector>(rv,sl); }
368 INLINE intvector operator -(const intvector_slice &sl, const intvector &rv)
369#if(CXSC_INDEX_CHECK)
370
371#else
372 noexcept
373#endif
374 { return _vsvminus<intvector_slice,intvector,intvector>(sl,rv); }
375 INLINE intvector operator -(const intvector_slice &sl1, const intvector_slice &sl2)
376#if(CXSC_INDEX_CHECK)
377
378#else
379 noexcept
380#endif
381 { return _vsvsminus<intvector_slice,intvector_slice,intvector>(sl1,sl2); }
382 INLINE intvector & operator -=(intvector &rv1, const intvector &rv2)
383#if(CXSC_INDEX_CHECK)
384
385#else
386 noexcept
387#endif
388 { return _vvminusassign(rv1,rv2); }
389 INLINE intvector &operator -=(intvector &rv, const intvector_slice &sl)
390#if(CXSC_INDEX_CHECK)
391
392#else
393 noexcept
394#endif
395 { return _vvsminusassign(rv,sl); }
397#if(CXSC_INDEX_CHECK)
398
399#else
400 noexcept
401#endif
402 { return _vsvminusassign(*this,rv); }
404#if(CXSC_INDEX_CHECK)
405
406#else
407 noexcept
408#endif
409 { return _vsvsminusassign(*this,sl2); }
410
411 INLINE bool operator ==(const intvector &rv1, const intvector &rv2) noexcept { return _vveq(rv1,rv2); }
412 INLINE bool operator ==(const intvector_slice &sl1, const intvector_slice &sl2) noexcept { return _vsvseq(sl1,sl2); }
413 INLINE bool operator ==(const intvector_slice &sl, const intvector &rv) noexcept { return _vsveq(sl,rv); }
414 INLINE bool operator ==(const intvector &rv, const intvector_slice &sl) noexcept { return _vsveq(sl,rv); }
415 INLINE bool operator !=(const intvector &rv1, const intvector &rv2) noexcept { return _vvneq(rv1,rv2); }
416 INLINE bool operator !=(const intvector_slice &sl1, const intvector_slice &sl2) noexcept { return _vsvsneq(sl1,sl2); }
417 INLINE bool operator !=(const intvector_slice &sl, const intvector &rv) noexcept { return _vsvneq(sl,rv); }
418 INLINE bool operator !=(const intvector &rv, const intvector_slice &sl) noexcept { return _vsvneq(sl,rv); }
419 INLINE bool operator <(const intvector &rv1, const intvector &rv2) noexcept { return _vvless(rv1,rv2); }
420 INLINE bool operator <(const intvector_slice &sl1, const intvector_slice &sl2) noexcept { return _vsvsless(sl1,sl2); }
421 INLINE bool operator < (const intvector_slice &sl, const intvector &rv) noexcept { return _vsvless(sl,rv); }
422 INLINE bool operator < (const intvector &rv, const intvector_slice &sl) noexcept { return _vvsless(rv,sl); }
423 INLINE bool operator <=(const intvector &rv1, const intvector &rv2) noexcept { return _vvleq(rv1,rv2); }
424 INLINE bool operator <=(const intvector_slice &sl1, const intvector_slice &sl2) noexcept { return _vsvsleq(sl1,sl2); }
425 INLINE bool operator <=(const intvector_slice &sl, const intvector &rv) noexcept { return _vsvleq(sl,rv); }
426 INLINE bool operator <=(const intvector &rv, const intvector_slice &sl) noexcept { return _vvsleq(rv,sl); }
427 INLINE bool operator >(const intvector &rv1, const intvector &rv2) noexcept { return _vvless(rv2,rv1); }
428 INLINE bool operator >(const intvector_slice &sl1, const intvector_slice &sl2) noexcept { return _vsvsless(sl2,sl1); }
429 INLINE bool operator >(const intvector_slice &sl, const intvector &rv) noexcept { return _vvsless(rv,sl); }
430 INLINE bool operator >(const intvector &rv, const intvector_slice &sl) noexcept { return _vsvless(sl,rv); }
431 INLINE bool operator >=(const intvector &rv1, const intvector &rv2) noexcept { return _vvleq(rv2,rv1); }
432 INLINE bool operator >=(const intvector_slice &sl1, const intvector_slice &sl2) noexcept { return _vsvsleq(sl2,sl1); }
433 INLINE bool operator >=(const intvector_slice &sl, const intvector &rv) noexcept { return _vvsleq(rv,sl); }
434 INLINE bool operator >=(const intvector &rv, const intvector_slice &sl) noexcept { return _vsvleq(sl,rv); }
435
436 INLINE std::ostream &operator <<(std::ostream &s, const intvector &rv) noexcept { return _vout(s,rv); }
437 INLINE std::ostream &operator <<(std::ostream &o, const intvector_slice &sl) noexcept { return _vsout(o,sl); }
438 INLINE std::istream &operator >>(std::istream &s, intvector &rv) noexcept { return _vin(s,rv); }
439 INLINE std::istream &operator >>(std::istream &s, intvector_slice &rv) noexcept { return _vsin(s,rv); }
440
441 INLINE intvector perminv(const intvector& x) {
442 intvector p(0,VecLen(x));
443 for(int i=0 ; i<VecLen(x) ; i++)
444 p[x[i+Lb(x)]] = i;
445 return p;
446 }
447
448
449} // namespace cxsc
450
451#endif
452
The Data Type dotprecision.
Definition dot.hpp:112
The Data Type intvector_slice.
intvector_slice & operator-=(const intvector &rv) noexcept
Implementation of subtraction and allocation operation.
intvector_slice & operator+=(const intvector &rv) noexcept
Implementation of addition and allocation operation.
intvector_slice & operator/=(const int &r) noexcept
Implementation of division and allocation operation.
int & operator[](const int &i) noexcept
Operator for accessing the single elements of the vector.
Definition intvector.inl:76
intvector_slice & operator()() noexcept
Operator for accessing the whole vector.
intvector_slice & operator*=(const int &r) noexcept
Implementation of multiplication and allocation operation.
intvector_slice & operator=(const intvector_slice &sl) noexcept
Constructor of class intvector_slice.
The Data Type intvector.
Definition intvector.hpp:52
intvector() noexcept
Constructor of class intvector.
Definition intvector.inl:33
int & operator[](const int &i) noexcept
Operator for accessing the single elements of the vector.
intvector & operator()() noexcept
Operator for accessing the whole vector.
intvector & operator=(const intvector &rv) noexcept
Implementation of standard assigning operator.
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
civector operator/(const cimatrix_subv &rv, const cinterval &s) noexcept
Implementation of division operation.
Definition cimatrix.inl:730
intvector _intvector(const int &r) noexcept
Deprecated typecast, which only exist for the reason of compatibility with older versions of C-XSC.
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.