/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to src/utility/valarray

  • Committer: Tim Marston
  • Date: 2012-03-21 21:24:17 UTC
  • Revision ID: tim@ed.am-20120321212417-dnba5l1oheddeyxw
fixed time centring and display in settings mode

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      Copyright (C) 2004 Garrett A. Kajmowicz
2
 
 
3
 
        This file is part of the uClibc++ Library.
4
 
 
5
 
        This library is free software; you can redistribute it and/or
6
 
        modify it under the terms of the GNU Lesser General Public
7
 
        License as published by the Free Software Foundation; either
8
 
        version 2.1 of the License, or (at your option) any later version.
9
 
 
10
 
        This library is distributed in the hope that it will be useful,
11
 
        but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
        Lesser General Public License for more details.
14
 
 
15
 
        You should have received a copy of the GNU Lesser General Public
16
 
        License along with this library; if not, write to the Free Software
17
 
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
*/
19
 
 
20
 
#include <basic_definitions>
21
 
 
22
 
#ifndef __HEADER_STD_VALARRAY
23
 
#define __HEADER_STD_VALARRAY 1
24
 
 
25
 
#include <cstddef>
26
 
#include <cmath>
27
 
 
28
 
#pragma GCC visibility push(default)
29
 
 
30
 
namespace std{
31
 
 
32
 
        template<class T> class valarray;
33
 
        class slice;
34
 
        template<class T> class slice_array;
35
 
        class gslice;
36
 
        template<class T> class gslice_array;
37
 
        template<class T> class mask_array;
38
 
        template<class T> class indirect_array;
39
 
 
40
 
        //Actual class definitions
41
 
 
42
 
 
43
 
        class _UCXXEXPORT slice {
44
 
        protected:
45
 
                size_t sta;
46
 
                size_t siz;
47
 
                size_t str;
48
 
 
49
 
        public:
50
 
                slice() : sta(0), siz(0), str(0){  }
51
 
                slice(size_t a, size_t b, size_t c) : sta(a), siz(b), str(c) {  }
52
 
                slice(const slice& s) : sta(s.sta), siz(s.siz), str(s.str) {  }
53
 
                ~slice() {  }
54
 
                size_t start() const{
55
 
                        return sta;
56
 
                }
57
 
                size_t size() const{
58
 
                        return siz;
59
 
                }
60
 
                size_t stride() const{
61
 
                        return str;
62
 
                }
63
 
        };
64
 
 
65
 
 
66
 
 
67
 
        template<class T> class _UCXXEXPORT valarray {
68
 
                friend class slice_array<T>;
69
 
        protected:
70
 
                T * data;
71
 
                size_t length;
72
 
 
73
 
        public:
74
 
                typedef T value_type;
75
 
 
76
 
                valarray() : data(0), length(0) {  }
77
 
 
78
 
                explicit valarray(size_t t) : data(0), length(t){
79
 
                        data = new T[length];
80
 
                }
81
 
 
82
 
                valarray(const T& v, size_t t) : data(0), length(t){
83
 
                        data = new T[length];
84
 
                        for(size_t i = 0; i < length; ++i){
85
 
                                data[i] = v;
86
 
                        }
87
 
                }
88
 
                valarray(const T* p, size_t t) : data(0), length(t) {
89
 
                        data = new T[length];
90
 
                        for(size_t i = 0; i < length; ++i){
91
 
                                data[i] = p[i];
92
 
                        }
93
 
                }
94
 
                valarray(const valarray& v) : data(0), length(v.length){
95
 
                        data = new T[length];
96
 
                        for(size_t i = 0; i < length; ++i){
97
 
                                data[i] = v.data[i];
98
 
                        }
99
 
                }
100
 
                valarray(const slice_array<T> & sa) : data(0), length(sa.s.size()){
101
 
                        data = new T[length];
102
 
                        for(unsigned int i = 0; i < length; ++i){
103
 
                                data[i] = sa.array->data[sa.s.start() + i * sa.s.stride()];
104
 
                        }
105
 
                }
106
 
                valarray(const gslice_array<T>&);
107
 
                valarray(const mask_array<T>&);
108
 
                valarray(const indirect_array<T>&);
109
 
                ~valarray(){
110
 
                        delete [] data;
111
 
                        data = 0;
112
 
                        length = 0;
113
 
                }
114
 
 
115
 
                valarray<T>& operator=(const valarray<T>& v){
116
 
                        for(size_t i =0; i< length; ++i){
117
 
                                data[i] = v.data[i];
118
 
                        }
119
 
                        return *this;
120
 
                }
121
 
                valarray<T>& operator=(const T& t){
122
 
                        for(size_t i = 0; i < length; ++i){
123
 
                                data[i] = t;
124
 
                        }
125
 
                        return *this;
126
 
                }
127
 
                valarray<T>& operator=(const slice_array<T>& sa){
128
 
                        for(size_t i =0; i < length; ++i){
129
 
                                data[i] = sa.data[sa.s.start() + i * sa.s.stride()];
130
 
                        }
131
 
                        return *this;
132
 
                }
133
 
                valarray<T>& operator=(const gslice_array<T>&);
134
 
                valarray<T>& operator=(const mask_array<T>&);
135
 
                valarray<T>& operator=(const indirect_array<T>&);
136
 
 
137
 
                T operator[](size_t t) const{
138
 
                        return data[t];
139
 
                }
140
 
                T& operator[](size_t t){
141
 
                        return data[t];
142
 
                }
143
 
 
144
 
                valarray<T> operator[](slice s) const{
145
 
                        valarray<T> retval(s.size());
146
 
                        for(unsigned int i = 0; i< s.size(); ++i){
147
 
                                retval.data[i] = data[s.start() + i * s.stride()];
148
 
                        }
149
 
                        return retval;
150
 
                }
151
 
 
152
 
                slice_array<T> operator[](slice sl){
153
 
                        slice_array<T> retval;
154
 
                        retval.s = sl;
155
 
                        retval.array = this;
156
 
                        return retval;
157
 
                }
158
 
 
159
 
                valarray<T> operator[](const gslice&) const;
160
 
                gslice_array<T> operator[](const gslice&);
161
 
                valarray<T> operator[](const valarray<bool>&) const;
162
 
                mask_array<T> operator[](const valarray<bool>&);
163
 
                valarray<T> operator[](const valarray<size_t>&) const;
164
 
                indirect_array<T> operator[](const valarray<size_t>&);
165
 
 
166
 
                valarray<T> operator+() const{
167
 
                        valarray<T> retval(length);
168
 
                        for(size_t i = 0; i< length ; ++i){
169
 
                                retval.data[i] = +data[i];
170
 
                        }
171
 
                        return retval;
172
 
                }
173
 
                valarray<T> operator-() const{
174
 
                        valarray<T> retval(length);
175
 
                        for(size_t i = 0; i< length; ++i){
176
 
                                retval.data[i] = -data[i];
177
 
                        }
178
 
                        return retval;
179
 
                }
180
 
                valarray<T> operator~() const{
181
 
                        valarray<T> retval(length);
182
 
                        for(size_t i = 0; i< length ; ++i){
183
 
                                retval.data[i] = ~data[i];
184
 
                        }
185
 
                        return retval;
186
 
                }
187
 
                valarray<T> operator!() const{
188
 
                        valarray<T> retval(length);
189
 
                        for(size_t i = 0; i< length ; ++i){
190
 
                                retval.data[i] = !data[i];
191
 
                        }
192
 
                        return retval;
193
 
                }
194
 
                valarray<T>& operator*= (const T& t){
195
 
                        for(size_t i=0;i<length;++i){
196
 
                                data[i] *= t;
197
 
                        }
198
 
                        return *this;
199
 
                }
200
 
                valarray<T>& operator/= (const T& t){
201
 
                        for(size_t i=0;i<length;++i){
202
 
                                data[i] /= t;
203
 
                        }
204
 
                        return *this;
205
 
                }
206
 
                valarray<T>& operator%= (const T& t){
207
 
                        for(size_t i=0;i<length;++i){
208
 
                                data[i] %= t;
209
 
                        }
210
 
                        return *this;
211
 
                }
212
 
                valarray<T>& operator+= (const T& t){
213
 
                        for(size_t i=0;i<length;++i){
214
 
                                data[i] += t;
215
 
                        }
216
 
                        return *this;
217
 
                }
218
 
                valarray<T>& operator-= (const T& t){
219
 
                        for(size_t i=0;i<length;++i){
220
 
                                data[i] -= t;
221
 
                        }
222
 
                        return *this;
223
 
                }
224
 
                valarray<T>& operator^= (const T& t){
225
 
                        for(size_t i=0;i<length;++i){
226
 
                                data[i] ^= t;
227
 
                        }
228
 
                        return *this;
229
 
                }
230
 
                valarray<T>& operator&= (const T& t){
231
 
                        for(size_t i=0;i<length;++i){
232
 
                                data[i] &= t;
233
 
                        }
234
 
                        return *this;
235
 
                }
236
 
                valarray<T>& operator|= (const T& t){
237
 
                        for(size_t i=0;i<length; ++i){
238
 
                                data[i] != t;
239
 
                        }
240
 
                        return *this;
241
 
                }
242
 
                valarray<T>& operator<<=(const T& t){
243
 
                        for(size_t i=0;i<length;++i){
244
 
                                data[i] <<= t;
245
 
                        }
246
 
                        return *this;
247
 
                }
248
 
                valarray<T>& operator>>=(const T& t){
249
 
                        for(size_t i=0;i<length;++i){
250
 
                                data[i] >>= t;
251
 
                        }
252
 
                        return *this;
253
 
                }
254
 
                valarray<T>& operator*= (const valarray<T>& a){
255
 
                        for(size_t i=0;i<length;++i){
256
 
                                data[i] *= a.data[i];
257
 
                        }
258
 
                        return *this;
259
 
                }
260
 
                valarray<T>& operator/= (const valarray<T>& a){
261
 
                        for(size_t i=0;i<length;++i){
262
 
                                data[i] /= a.data[i];
263
 
                        }
264
 
                        return *this;
265
 
                }
266
 
                valarray<T>& operator%= (const valarray<T>& a){
267
 
                        for(size_t i=0;i<length;++i){
268
 
                                data[i] %= a.data[i];
269
 
                        }
270
 
                        return *this;
271
 
                }
272
 
                valarray<T>& operator+= (const valarray<T>& a){
273
 
                        for(size_t i=0;i<length;++i){
274
 
                                data[i] += a.data[i];
275
 
                        }
276
 
                        return *this;
277
 
                }
278
 
                valarray<T>& operator-= (const valarray<T>& a){
279
 
                        for(size_t i=0;i<length ;++i){
280
 
                                data[i] -= a.data[i];
281
 
                        }
282
 
                        return *this;
283
 
                }
284
 
                valarray<T>& operator^= (const valarray<T>& a){
285
 
                        for(size_t i=0;i<length;++i){
286
 
                                data[i] ^= a.data[i];
287
 
                        }
288
 
                        return *this;
289
 
                }
290
 
                valarray<T>& operator|= (const valarray<T>& a){
291
 
                        for(size_t i=0;i<length ;++i){
292
 
                                data[i] |= a.data[i];
293
 
                        }
294
 
                        return *this;
295
 
                }
296
 
                valarray<T>& operator&= (const valarray<T>& a){
297
 
                        for(size_t i=0;i<length;++i){
298
 
                                data[i] &= a.data[i];
299
 
                        }
300
 
                        return *this;
301
 
                }
302
 
                valarray<T>& operator<<=(const valarray<T>& a){
303
 
                        for(size_t i=0;i<length;++i){
304
 
                                data[i] <<= a.data[i];
305
 
                        }
306
 
                        return *this;
307
 
                }
308
 
                valarray<T>& operator>>=(const valarray<T>& a){
309
 
                        for(size_t i=0;i<length;++i){
310
 
                                data[i] >>= a.data[i];
311
 
                        }
312
 
                        return *this;
313
 
                }
314
 
 
315
 
                size_t size() const{
316
 
                        return length;
317
 
                }
318
 
 
319
 
                T sum() const{
320
 
                        T retval(data[0]);
321
 
                        for(size_t i = 1; i< length; ++i){
322
 
                                retval += data[i];
323
 
                        }
324
 
                        return retval;
325
 
                }
326
 
 
327
 
                T min() const{
328
 
                        T retval(data[0]);
329
 
                        for(size_t i = 1; i< length; ++i){
330
 
                                if(data[i] < retval){
331
 
                                        retval = data[i];
332
 
                                }
333
 
                        }
334
 
                        return retval;
335
 
                }
336
 
 
337
 
                T max() const{
338
 
                        T retval(data[0]);
339
 
                        for(size_t i = 1; i< length; ++i){
340
 
                                if(retval < data[i]){
341
 
                                        retval = data[i];
342
 
                                }
343
 
                        }
344
 
                        return retval;
345
 
                }
346
 
 
347
 
                valarray<T> shift (int n) const{
348
 
                        valarray<T> retval(length);
349
 
                        for(size_t i = 0; i < length ; ++i){
350
 
                                if(i + n > 0  && i + n < length){
351
 
                                        retval.data[i] = data[i + n];
352
 
                                }
353
 
                        }
354
 
                        return retval;
355
 
                }
356
 
                valarray<T> cshift(int n) const{
357
 
                        valarray<T> retval(length);
358
 
                        for(size_t i = 0; i < length ; ++i){
359
 
                                retval.data[i] = data[ (i + n) % length ];
360
 
                        }
361
 
                        return retval;
362
 
                }
363
 
                valarray<T> apply(T func(T) ) const{
364
 
                        valarray<T> retval(length);
365
 
                        for(size_t i = 0; i< length; ++i){
366
 
                                retval.data[i] = func(data[i]);
367
 
                        }
368
 
                        return retval;
369
 
                }
370
 
                valarray<T> apply(T func(const T&)) const{
371
 
                        valarray<T> retval(length);
372
 
                        for(size_t i = 0; i< length; ++i){
373
 
                                retval.data[i] = func(data[i]);
374
 
                        }
375
 
                        return retval;
376
 
                }
377
 
                void resize(size_t sz, T c = T()){
378
 
                        delete [] data;
379
 
                        data = 0;
380
 
                        if(sz > 0){
381
 
                                data = new T[sz];
382
 
                                for(size_t i = 0; i < sz; ++i){
383
 
                                        data[i] = c;
384
 
                                }
385
 
                        }
386
 
                        length = sz;
387
 
                }
388
 
        };
389
 
 
390
 
 
391
 
 
392
 
        template <class T> class _UCXXEXPORT slice_array {
393
 
                friend class valarray<T>;
394
 
        public:
395
 
                typedef T value_type;
396
 
 
397
 
                void operator=  (const valarray<T>& v) const{
398
 
                        for(unsigned int i = 0; i < s.size(); ++i){
399
 
                                array->data[s.start() + i * s.stride()] = v[i];
400
 
                        }
401
 
                }
402
 
                void operator=  (const T & v){
403
 
                        for(unsigned int i = 0; i < s.size(); ++i){
404
 
                                array->data[s.start() + i * s.stride()] = v;
405
 
                        }
406
 
                }
407
 
                void fill(const T & v){
408
 
                        for(unsigned int i = 0; i < s.size(); ++i){
409
 
                                array->data[s.start() + i * s.stride()] = v;
410
 
                        }
411
 
                }
412
 
                void operator*= (const valarray<T>& v) const{
413
 
                        for(unsigned int i = 0; i < s.size(); ++i){
414
 
                                array->data[s.start() + i * s.stride()] *= v[i];
415
 
                        }
416
 
                }
417
 
                void operator/= (const valarray<T>& v) const{
418
 
                        for(unsigned int i = 0; i < s.size(); ++i){
419
 
                                array->data[s.start() + i * s.stride()] /= v[i];
420
 
                        }
421
 
                }
422
 
                void operator%= (const valarray<T>& v) const{
423
 
                        for(unsigned int i = 0; i < s.size(); ++i){
424
 
                                array->data[s.start() + i * s.stride()] %= v[i];
425
 
                        }
426
 
                }
427
 
                void operator+= (const valarray<T>& v) const{
428
 
                        for(unsigned int i = 0; i < s.size(); ++i){
429
 
                                array->data[s.start() + i * s.stride()] += v[i];
430
 
                        }
431
 
                }
432
 
                void operator-= (const valarray<T>& v) const{
433
 
                        for(unsigned int i = 0; i < s.size(); ++i){
434
 
                                array->data[s.start() + i * s.stride()] -= v[i];
435
 
                        }
436
 
                }
437
 
                void operator^= (const valarray<T>& v) const{
438
 
                        for(unsigned int i = 0; i < s.size(); ++i){
439
 
                                array->data[s.start() + i * s.stride()] ^= v[i];
440
 
                        }
441
 
                }
442
 
                void operator&= (const valarray<T>& v) const{
443
 
                        for(unsigned int i = 0; i < s.size(); ++i){
444
 
                                array->data[s.start() + i * s.stride()] &= v[i];
445
 
                        }
446
 
                }
447
 
                void operator|= (const valarray<T>& v) const{
448
 
                        for(unsigned int i = 0; i < s.size(); ++i){
449
 
                                array->data[s.start() + i * s.stride()] |= v[i];
450
 
                        }
451
 
                }
452
 
                void operator<<=(const valarray<T>& v) const{
453
 
                        for(unsigned int i = 0; i < s.size(); ++i){
454
 
                                array->data[s.start() + i * s.stride()] <<= v[i];
455
 
                        }
456
 
                }
457
 
                void operator>>=(const valarray<T>& v) const{
458
 
                        for(unsigned int i = 0; i < s.size(); ++i){
459
 
                                array->data[s.start() + i * s.stride()] >>= v[i];
460
 
                        }
461
 
                }
462
 
                ~slice_array(){
463
 
                        array = 0;
464
 
                }
465
 
 
466
 
        private:
467
 
                slice_array() : array(0){  }
468
 
 
469
 
        public:
470
 
                slice_array(const slice_array& sa) : array(sa.array), s(sa.s){  }
471
 
                slice_array& operator=(const slice_array& sa){
472
 
                        array = sa.array;
473
 
                        s = sa.s;
474
 
                }
475
 
 
476
 
        private:
477
 
                valarray<T> * array;
478
 
                slice s;
479
 
        };
480
 
 
481
 
 
482
 
        class _UCXXEXPORT gslice {
483
 
        private:
484
 
                size_t sta;
485
 
                valarray<size_t> siz;
486
 
                valarray<size_t> str;
487
 
 
488
 
        public:
489
 
                gslice() : sta(0) { }
490
 
                gslice(size_t s, const valarray<size_t>& l, const valarray<size_t>& d)
491
 
                        : sta(s), siz(l), str(d) {  }
492
 
 
493
 
                size_t start() const{
494
 
                        return sta;
495
 
                }
496
 
                valarray<size_t> size() const{
497
 
                        return siz;
498
 
                }
499
 
                valarray<size_t> stride() const{
500
 
                        return str;
501
 
                }
502
 
        };
503
 
 
504
 
        template <class T> class gslice_array {
505
 
        private:
506
 
                friend class valarray<T>;
507
 
 
508
 
        public:
509
 
                ~gslice_array();
510
 
 
511
 
                void operator=(const valarray<T>& array) const;
512
 
                void operator*=(const valarray<T>& array) const;
513
 
                void operator/=(const valarray<T>& array) const;
514
 
                void operator%=(const valarray<T>& array) const;
515
 
                void operator+=(const valarray<T>& array) const;
516
 
                void operator-=(const valarray<T>& array) const;
517
 
                void operator^=(const valarray<T>& array) const;
518
 
                void operator&=(const valarray<T>& array) const;
519
 
                void operator|=(const valarray<T>& array) const;
520
 
                void operator<<=(const valarray<T>& array) const;
521
 
                void operator>>=(const valarray<T>& array) const;
522
 
 
523
 
                void operator=(const T&);  
524
 
 
525
 
        private:
526
 
                gslice_array();
527
 
                gslice_array(const gslice_array<T>&);
528
 
                gslice_array<T>& operator= (const gslice_array<T>& array);
529
 
        };
530
 
 
531
 
 
532
 
 
533
 
        template<class T> valarray<T> operator* (const valarray<T>& lhs, const valarray<T>& rhs){
534
 
                valarray<T> retval(lhs);
535
 
                retval *= rhs;
536
 
                return retval;
537
 
        }
538
 
 
539
 
        template<class T> valarray<T> operator* (const valarray<T>& lhs, const T& rhs){
540
 
                valarray<T> retval(lhs);
541
 
                retval *= rhs;
542
 
                return retval;
543
 
        }
544
 
        template<class T> valarray<T> operator* (const T& lhs, const valarray<T>& rhs){
545
 
                valarray<T> retval(rhs);
546
 
                retval *= lhs;
547
 
                return retval;
548
 
        }
549
 
        template<class T> valarray<T> operator/ (const valarray<T>& lhs, const valarray<T>& rhs){
550
 
                valarray<T> retval(lhs);
551
 
                retval /= rhs;
552
 
                return retval;
553
 
        }
554
 
        template<class T> valarray<T> operator/ (const valarray<T>& lhs, const T& rhs){
555
 
                valarray<T> retval(lhs);
556
 
                retval /= rhs;
557
 
                return retval;
558
 
        }
559
 
        template<class T> valarray<T> operator/ (const T& lhs, const valarray<T>& rhs){
560
 
                valarray<T> retval(lhs, rhs.size());
561
 
                retval /= rhs;
562
 
                return retval;
563
 
        }
564
 
        template<class T> valarray<T> operator% (const valarray<T>& lhs, const valarray<T>& rhs){
565
 
                valarray<T> retval(lhs);
566
 
                retval %= rhs;
567
 
                return retval;
568
 
        }
569
 
        template<class T> valarray<T> operator% (const valarray<T>& lhs, const T& rhs){
570
 
                valarray<T> retval(lhs);
571
 
                retval %= rhs;
572
 
                return retval;
573
 
        }
574
 
        template<class T> valarray<T> operator% (const T& lhs, const valarray<T>& rhs){
575
 
                valarray<T> retval(lhs, rhs.size());
576
 
                retval %= rhs;
577
 
                return retval;
578
 
        }
579
 
        template<class T> valarray<T> operator+ (const valarray<T>& lhs, const valarray<T>& rhs){
580
 
                valarray<T> retval(lhs);
581
 
                retval += rhs;
582
 
                return retval;
583
 
        }
584
 
        template<class T> valarray<T> operator+ (const valarray<T>& lhs, const T& rhs){
585
 
                valarray<T> retval(lhs);
586
 
                retval += rhs;
587
 
                return retval;
588
 
        }
589
 
        template<class T> valarray<T> operator+ (const T& lhs, const valarray<T>& rhs){
590
 
                valarray<T> retval(lhs, rhs.size());
591
 
                retval += rhs;
592
 
                return retval;
593
 
        }
594
 
        template<class T> valarray<T> operator- (const valarray<T>& lhs, const valarray<T>& rhs){
595
 
                valarray<T> retval(lhs);
596
 
                retval -= rhs;
597
 
                return retval;
598
 
        }
599
 
        template<class T> valarray<T> operator- (const valarray<T>& lhs, const T& rhs){
600
 
                valarray<T> retval(lhs);
601
 
                retval-= rhs;
602
 
                return retval;
603
 
        }
604
 
        template<class T> valarray<T> operator- (const T& lhs, const valarray<T>& rhs){
605
 
                valarray<T> retval(lhs, rhs.size());
606
 
                retval -= rhs;
607
 
                return retval;
608
 
        }
609
 
        template<class T> valarray<T> operator^ (const valarray<T>& lhs, const valarray<T>& rhs){
610
 
                valarray<T> retval(lhs);
611
 
                retval ^= rhs;
612
 
                return retval;
613
 
        }
614
 
        template<class T> valarray<T> operator^ (const valarray<T>& lhs, const T& rhs){
615
 
                valarray<T> retval(lhs);
616
 
                retval ^= rhs;
617
 
                return retval;
618
 
        }
619
 
        template<class T> valarray<T> operator^ (const T& lhs, const valarray<T>& rhs){
620
 
                valarray<T> retval(lhs, rhs.size());
621
 
                retval ^= rhs;
622
 
                return retval;
623
 
        }
624
 
        template<class T> valarray<T> operator& (const valarray<T>& lhs, const valarray<T>& rhs){
625
 
                valarray<T> retval(lhs);
626
 
                retval &= rhs;
627
 
                return retval;
628
 
        }
629
 
        template<class T> valarray<T> operator& (const valarray<T>& lhs, const T& rhs){
630
 
                valarray<T> retval(lhs);
631
 
                retval &= rhs;
632
 
                return retval;
633
 
        }
634
 
        template<class T> valarray<T> operator& (const T& lhs, const valarray<T>& rhs){
635
 
                valarray<T> retval(lhs, rhs.size());
636
 
                retval &= rhs;
637
 
                return retval;
638
 
        }
639
 
        template<class T> valarray<T> operator| (const valarray<T>& lhs, const valarray<T>& rhs){
640
 
                valarray<T> retval(lhs);
641
 
                retval |= rhs;
642
 
                return retval;
643
 
        }
644
 
        template<class T> valarray<T> operator| (const valarray<T>& lhs, const T& rhs){
645
 
                valarray<T> retval(lhs);
646
 
                retval |= rhs;
647
 
                return retval;
648
 
        }
649
 
        template<class T> valarray<T> operator| (const T& lhs, const valarray<T>& rhs){
650
 
                valarray<T> retval(lhs, rhs.size());
651
 
                retval |= rhs;
652
 
                return retval;
653
 
        }
654
 
        template<class T> valarray<T> operator<<(const valarray<T>& lhs, const valarray<T>& rhs){
655
 
                valarray<T> retval(lhs);
656
 
                retval <<= rhs;
657
 
                return retval;
658
 
        }
659
 
        template<class T> valarray<T> operator<<(const valarray<T>& lhs, const T& rhs){
660
 
                valarray<T> retval(lhs);
661
 
                retval <<= rhs;
662
 
                return retval;
663
 
        }
664
 
        template<class T> valarray<T> operator<<(const T& lhs, const valarray<T>& rhs){
665
 
                valarray<T> retval(lhs, rhs.size());
666
 
                retval <<= rhs;
667
 
                return retval;
668
 
        }
669
 
        template<class T> valarray<T> operator>>(const valarray<T>& lhs, const valarray<T>& rhs){
670
 
                valarray<T> retval(lhs);
671
 
                retval >>= rhs;
672
 
                return retval;
673
 
        }
674
 
        template<class T> valarray<T> operator>>(const valarray<T>& lhs, const T& rhs){
675
 
                valarray<T> retval(lhs);
676
 
                retval >>= rhs;
677
 
                return retval;
678
 
        }
679
 
        template<class T> valarray<T> operator>>(const T& lhs, const valarray<T>& rhs){
680
 
                valarray<T> retval(lhs, rhs.size());
681
 
                retval >>= rhs;
682
 
                return retval;
683
 
        }
684
 
 
685
 
        template<class T> valarray<bool> operator&&(const valarray<T>& lhs, const valarray<T>& rhs){
686
 
                valarray<bool> retval(lhs.size());
687
 
                for(size_t i = 0; i < retval.size(); ++i){
688
 
                        retval[i] = lhs[i] && rhs[i];
689
 
                }
690
 
                return retval;
691
 
        }
692
 
        template<class T> valarray<bool> operator&&(const valarray<T>& lhs, const T& rhs){
693
 
                valarray<bool> retval(lhs.size());
694
 
                for(size_t i = 0; i <retval.size(); ++i){
695
 
                        retval[i] = lhs[i] && rhs;
696
 
                }
697
 
                return retval;
698
 
        }
699
 
        template<class T> valarray<bool> operator&&(const T& lhs, const valarray<T>& rhs){
700
 
                valarray<bool> retval(rhs.size());
701
 
                for(size_t i = 0; i <retval.size(); ++i){
702
 
                        retval[i] = lhs && rhs[i];
703
 
                }
704
 
                return retval;
705
 
        }
706
 
        template<class T> valarray<bool> operator||(const valarray<T>&lhs, const valarray<T>& rhs){
707
 
                valarray<bool> retval(lhs.size());
708
 
                for(size_t i = 0; i <retval.size(); ++i){
709
 
                        retval[i] = lhs[i] || rhs[i];
710
 
                }
711
 
                return retval;
712
 
        }
713
 
        template<class T> valarray<bool> operator||(const valarray<T>& lhs, const T& rhs){
714
 
                valarray<bool> retval(lhs.size());
715
 
                for(size_t i = 0; i <retval.size(); ++i){
716
 
                        retval[i] = lhs[i] || rhs;
717
 
                }
718
 
                return retval;
719
 
        }
720
 
        template<class T> valarray<bool> operator||(const T& lhs, const valarray<T>& rhs){
721
 
                valarray<bool> retval(rhs.size());
722
 
                for(size_t i = 0; i < retval.size(); ++i){
723
 
                        retval[i] = lhs || rhs[i];
724
 
                }
725
 
                return retval;
726
 
        }
727
 
 
728
 
        template<class T> valarray<bool> operator==(const valarray<T>& lhs, const valarray<T>& rhs){
729
 
                valarray<bool> retval(lhs.size());
730
 
                for(size_t i = 0; i <retval.size(); ++i){
731
 
                        retval[i] = lhs[i] == rhs[i];
732
 
                }
733
 
                return retval;
734
 
        }
735
 
        template<class T> valarray<bool> operator==(const valarray<T>& lhs, const T& rhs){
736
 
                valarray<bool> retval(lhs.size());
737
 
                for(size_t i = 0; i < retval.size(); ++i){
738
 
                        retval[i] = lhs[i] == rhs;
739
 
                }
740
 
                return retval;
741
 
        }
742
 
        template<class T> valarray<bool> operator==(const T& lhs, const valarray<T>& rhs){
743
 
                valarray<bool> retval(rhs.size());
744
 
                for(size_t i = 0; i < retval.size(); ++i){
745
 
                        retval[i] = lhs == rhs[i];
746
 
                }
747
 
                return retval;
748
 
        }
749
 
        template<class T> valarray<bool> operator!=(const valarray<T>& lhs, const valarray<T>& rhs){
750
 
                valarray<bool> retval(lhs.size());
751
 
                for(size_t i = 0; i <retval.size(); ++i){
752
 
                        retval[i] = lhs[i] != rhs[i];
753
 
                }
754
 
                return retval;
755
 
        }
756
 
        template<class T> valarray<bool> operator!=(const valarray<T>& lhs, const T& rhs){
757
 
                valarray<bool> retval(lhs.size());
758
 
                for(size_t i = 0; i <retval.size(); ++i){
759
 
                        retval[i] = lhs[i] != rhs;
760
 
                }
761
 
                return retval;
762
 
        }
763
 
        template<class T> valarray<bool> operator!=(const T& lhs, const valarray<T>& rhs){
764
 
                valarray<bool> retval(rhs.size());
765
 
                for(size_t i = 0; i <retval.size(); ++i){
766
 
                        retval[i] = lhs != rhs[i];
767
 
                }
768
 
                return retval;
769
 
        }
770
 
        template<class T> valarray<bool> operator< (const valarray<T>& lhs, const valarray<T>& rhs){
771
 
                valarray<bool> retval(lhs.size());
772
 
                for(size_t i = 0; i <retval.size(); ++i){
773
 
                        retval[i] = lhs[i] < rhs[i];
774
 
                }
775
 
                return retval;
776
 
        }
777
 
        template<class T> valarray<bool> operator< (const valarray<T>& lhs, const T& rhs){
778
 
                valarray<bool> retval(lhs.size());
779
 
                for(size_t i = 0; i <retval.size(); ++i){
780
 
                        retval[i] = lhs[i] < rhs;
781
 
                }
782
 
                return retval;
783
 
        }
784
 
        template<class T> valarray<bool> operator< (const T& lhs, const valarray<T>& rhs){
785
 
                valarray<bool> retval(rhs.size());
786
 
                for(size_t i = 0; i <retval.size(); ++i){
787
 
                        retval[i] = lhs < rhs[i];
788
 
                }
789
 
                return retval;
790
 
        }
791
 
        template<class T> valarray<bool> operator> (const valarray<T>& lhs, const valarray<T>& rhs){
792
 
                valarray<bool> retval(lhs.size());
793
 
                for(size_t i = 0; i <retval.size(); ++i){
794
 
                        retval[i] = lhs[i] > rhs[i];
795
 
                }
796
 
                return retval;
797
 
        }
798
 
        template<class T> valarray<bool> operator> (const valarray<T>& lhs, const T& rhs){
799
 
                valarray<bool> retval(lhs.size());
800
 
                for(size_t i = 0; i <retval.size(); ++i){
801
 
                        retval[i] = lhs[i] > rhs;
802
 
                }
803
 
                return retval;
804
 
        }
805
 
        template<class T> valarray<bool> operator> (const T& rhs, const valarray<T>& lhs){
806
 
                valarray<bool> retval(rhs.size());
807
 
                for(size_t i = 0; i <retval.size(); ++i){
808
 
                        retval[i] = lhs > rhs[i];
809
 
                }
810
 
                return retval;
811
 
        }
812
 
        template<class T> valarray<bool> operator<=(const valarray<T>& lhs, const valarray<T>& rhs){
813
 
                valarray<bool> retval(lhs.size());
814
 
                for(size_t i = 0; i <retval.size(); ++i){
815
 
                        retval[i] = lhs[i] <= rhs[i];
816
 
                }
817
 
                return retval;
818
 
        }
819
 
        template<class T> valarray<bool> operator<=(const valarray<T>& lhs, const T& rhs){
820
 
                valarray<bool> retval(lhs.size());
821
 
                for(size_t i = 0; i <retval.size(); ++i){
822
 
                        retval[i] = lhs[i] <= rhs;
823
 
                }
824
 
                return retval;
825
 
        }
826
 
        template<class T> valarray<bool> operator<=(const T& lhs, const valarray<T>& rhs){
827
 
                valarray<bool> retval(rhs.size());
828
 
                for(size_t i = 0; i <retval.size(); ++i){
829
 
                        retval[i] = lhs <= rhs[i];
830
 
                }
831
 
                return retval;
832
 
        }
833
 
        template<class T> valarray<bool> operator>=(const valarray<T>& lhs, const valarray<T>& rhs){
834
 
                valarray<bool> retval(lhs.size());
835
 
                for(size_t i = 0; i <retval.size(); ++i){
836
 
                        retval[i] = lhs[i] >= rhs[i];
837
 
                }
838
 
                return retval;
839
 
        }
840
 
        template<class T> valarray<bool> operator>=(const valarray<T>& lhs, const T& rhs){
841
 
                valarray<bool> retval(lhs.size());
842
 
                for(size_t i = 0; i <retval.size(); ++i){
843
 
                        retval[i] = lhs[i] >= rhs;
844
 
                }
845
 
                return retval;
846
 
        }
847
 
        template<class T> valarray<bool> operator>=(const T& lhs, const valarray<T>& rhs){
848
 
                valarray<bool> retval(rhs.size());
849
 
                for(size_t i = 0; i <retval.size(); ++i){
850
 
                        retval[i] = lhs >= rhs[i];
851
 
                }
852
 
                return retval;
853
 
        }
854
 
        template<class T> T min(const valarray<T>& x){
855
 
                T retval(x[0]);
856
 
                for(size_t i = 1; i < x.size(); ++i){
857
 
                        if(x[i] < retval){
858
 
                                retval = x[i];
859
 
                        }
860
 
                }
861
 
        }
862
 
        template<class T> T max(const valarray<T>& x){
863
 
                T retval(x[0]);
864
 
                for(size_t i = 1; i < x.size(); ++i){
865
 
                        if(x[i] > retval){
866
 
                                retval = x[i];
867
 
                        }
868
 
                }
869
 
        }
870
 
 
871
 
        template<class T> valarray<T> abs  (const valarray<T>& x){
872
 
                valarray<T> retval(x.size());
873
 
                for(size_t i = 0; i < retval.size(); ++i){
874
 
                        retval[i] = abs(x[i]);
875
 
                }
876
 
        }
877
 
        template<class T> valarray<T> acos (const valarray<T>& x){
878
 
                valarray<T> retval(x.size());
879
 
                for(size_t i = 0; i < retval.size(); ++i){
880
 
                        retval[i] = acos(x[i]);
881
 
                }
882
 
        }
883
 
        template<class T> valarray<T> asin (const valarray<T>& x){
884
 
                valarray<T> retval(x.size());
885
 
                for(size_t i = 0; i < retval.size(); ++i){
886
 
                        retval[i] = asin(x[i]);
887
 
                }
888
 
        }
889
 
        template<class T> valarray<T> atan (const valarray<T>& x){
890
 
                valarray<T> retval(x.size());
891
 
                for(size_t i = 0; i < retval.size(); ++i){
892
 
                        retval[i] = atan(x[i]);
893
 
                }
894
 
        }
895
 
        template<class T> valarray<T> atan2(const valarray<T>& y, const valarray<T>& x){
896
 
                valarray<T> retval(y.size());
897
 
                for(size_t i = 0; i < retval.size(); ++i){
898
 
                        retval[i] = atan2(y[i], x[i]);
899
 
                }
900
 
        }
901
 
        template<class T> valarray<T> atan2(const valarray<T>& y, const T& x){
902
 
                valarray<T> retval(y.size());
903
 
                for(size_t i = 0; i < retval.size(); ++i){
904
 
                        retval[i] = atan2(y[i], x);
905
 
                }
906
 
        }
907
 
        template<class T> valarray<T> atan2(const T& y, const valarray<T>& x){
908
 
                valarray<T> retval(x.size());
909
 
                for(size_t i = 0; i < retval.size(); ++i){
910
 
                        retval[i] = abs(y, x[i]);
911
 
                }
912
 
        }
913
 
        template<class T> valarray<T> cos  (const valarray<T>& x){
914
 
                valarray<T> retval(x.size());
915
 
                for(size_t i = 0; i < retval.size(); ++i){
916
 
                        retval[i] = cos(x[i]);
917
 
                }
918
 
        }
919
 
        template<class T> valarray<T> cosh (const valarray<T>& x){
920
 
                valarray<T> retval(x.size());
921
 
                for(size_t i = 0; i < retval.size(); ++i){
922
 
                        retval[i] = cosh(x[i]);
923
 
                }
924
 
        }
925
 
        template<class T> valarray<T> exp  (const valarray<T>& x){
926
 
                valarray<T> retval(x.size());
927
 
                for(size_t i = 0; i < retval.size(); ++i){
928
 
                        retval[i] = exp(x[i]);
929
 
                }
930
 
        }
931
 
        template<class T> valarray<T> log  (const valarray<T>& x){
932
 
                valarray<T> retval(x.size());
933
 
                for(size_t i = 0; i < retval.size(); ++i){
934
 
                        retval[i] = log(x[i]);
935
 
                }
936
 
        }
937
 
        template<class T> valarray<T> log10(const valarray<T>& x){
938
 
                valarray<T> retval(x.size());
939
 
                for(size_t i = 0; i < retval.size(); ++i){
940
 
                        retval[i] = log10(x[i]);
941
 
                }
942
 
        }
943
 
        template<class T> valarray<T> pow (const valarray<T>& x, const valarray<T>& y){
944
 
                valarray<T> retval(x.size());
945
 
                for(size_t i = 0; i < retval.size(); ++i){
946
 
                        retval[i] = pow(x[i], y[i]);
947
 
                }
948
 
        }
949
 
        template<class T> valarray<T> pow  (const valarray<T>& x, const T& y){
950
 
                valarray<T> retval(x.size());
951
 
                for(size_t i = 0; i < retval.size(); ++i){
952
 
                        retval[i] = pow(x[i], y);
953
 
                }
954
 
        }
955
 
        template<class T> valarray<T> pow  (const T& x, const valarray<T>& y){
956
 
                valarray<T> retval(x.size());
957
 
                for(size_t i = 0; i < retval.size(); ++i){
958
 
                        retval[i] = pow(x, y[i]);
959
 
                }
960
 
        }
961
 
        template<class T> valarray<T> sin  (const valarray<T>& x){
962
 
                valarray<T> retval(x.size());
963
 
                for(size_t i = 0; i < retval.size(); ++i){
964
 
                        retval[i] = sin(x[i]);
965
 
                }
966
 
        }
967
 
        template<class T> valarray<T> sinh (const valarray<T>& x){
968
 
                valarray<T> retval(x.size());
969
 
                for(size_t i = 0; i < retval.size(); ++i){
970
 
                        retval[i] = sinh(x[i]);
971
 
                }
972
 
        }
973
 
        template<class T> valarray<T> sqrt (const valarray<T>& x){
974
 
                valarray<T> retval(x.size());
975
 
                for(size_t i = 0; i < retval.size(); ++i){
976
 
                        retval[i] = sqrt(x[i]);
977
 
                }
978
 
        }
979
 
        template<class T> valarray<T> tan  (const valarray<T>& x){
980
 
                valarray<T> retval(x.size());
981
 
                for(size_t i = 0; i < retval.size(); ++i){
982
 
                        retval[i] = tan(x[i]);
983
 
                }
984
 
        }
985
 
        template<class T> valarray<T> tanh (const valarray<T>& x){
986
 
                valarray<T> retval(x.size());
987
 
                for(size_t i = 0; i < retval.size(); ++i){
988
 
                        retval[i] = tanh(x[i]);
989
 
                }
990
 
        }
991
 
        
992
 
}
993
 
 
994
 
#pragma GCC visibility pop
995
 
 
996
 
#endif