Loading...
Searching...
No Matches
Operators.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25// ================================================================================== //
26// OPERATORS //
27// //
28// Operators for standard template library containers. //
29// ================================================================================== //
30// INFO //
31// ================================================================================== //
32// Author : Alessandro Alaia //
33// Version : v3.0 //
34// //
35// All rights reserved. //
36// ================================================================================== //
37#ifndef __BITPIT_OPERATORS_HPP__
38#define __BITPIT_OPERATORS_HPP__
39
40// ================================================================================== //
41// INCLUDES //
42// ================================================================================== //
43
44// Standard Template Library
45# include <cmath>
46# include <array>
47# include <vector>
48# include <sstream>
49# include <fstream>
50# include <iomanip>
51# include <iostream>
52# include <algorithm>
53# include <functional>
54
55// bitpit
56# include "bitpit_common.hpp"
57
58// ================================================================================== //
59// FUNCTION PROTOTYPES //
60// ================================================================================== //
61
62// STL vectors ====================================================================== //
63
64// Operator "+" --------------------------------------------------------------------- //
65template <class T>
66std::vector< T > operator+ ( // ELEMENT-WISE SUM BETWEEN TWO VECTORS
67 const std::vector< T > &, // 1st argument (std::vector)
68 const std::vector< T > & // 2nd argument (std::vector)
69 );
70template <class T>
71std::vector< T > operator+ ( // ELEMENT-WISE SUM BETWEEN VECTOR AND CONSTANT
72 const std::vector< T > &, // 1st argument (std::vector)
73 const T & // 2nd argument (constant)
74 );
75template <class T>
76std::vector< T > operator+ ( // ELEMENT-WISE SUM BETWEEN CONSTANT AND VECTOR
77 const T &, // 1st argument (constant)
78 const std::vector< T > & // 2nd argument (std::vector)
79 );
80template <class T>
81std::vector< std::vector< T > > operator+ ( // ELEMENT-WISE SUM BETWEEN CONSTANT AND VECTOR
82 const T &, // 1st argument (constant)
83 const std::vector< std::vector< T > > & // 2nd argument (std::vector)
84 );
85template <class T>
86std::vector< std::vector< T > > operator+ ( // ELEMENT-WISE SUM BETWEEN CONSTANT AND VECTOR
87 const std::vector< std::vector< T > > &, // 1st argument (std::vector)
88 const T & // 2nd argument (constant)
89 );
90
91// Operator "+=" -------------------------------------------------------------------- //
92template <class T>
93std::vector< T >& operator+= ( // ELEMENT-WISE INCREMENT OF A VECTOR
94 std::vector< T > &, // 1st argument (std::vector)
95 const std::vector< T > & // 2nd argument (std::vector)
96 );
97template <class T>
98std::vector< T >& operator+= ( // ELEMENT-WISE INCREMENT OF A VECTOR
99 std::vector< T > &, // 1st argument (std::vector)
100 const T & // 2nd argument (constant)
101 );
102template <class T>
103std::vector< std::vector< T > >& operator+= ( // ELEMENT-WISE INCREMENT OF A VECTOR
104 std::vector< std::vector< T > > &, // 1st argument (std::vector)
105 const T & // 2nd argument (constant)
106 );
107
108// Operator "-" --------------------------------------------------------------------- //
109template <class T>
110std::vector< T > operator- ( // ELEMENT-WISE DIFFERENCE BETWEEN TWO VECTORS
111 const std::vector< T > &, // 1st argument (std::vector)
112 const std::vector< T > & // 2nd argument (std::vector)
113 );
114template <class T>
115std::vector< T > operator- ( // ELEMENT-WISE DIFFERENCE BETWEEN VECTOR AND CONSTANT
116 const std::vector< T > &, // 1st argument (std::vector)
117 const T & // 2nd argument (constant)
118 );
119template <class T>
120std::vector< T > operator- ( // ELEMENT-WISE DIFFERENCE BETWEEN CONSTANT AND VECTOR
121 const T &, // 1st argument (constant)
122 const std::vector< T > & // 2nd argument (std::vector)
123 );
124template <class T>
125std::vector< std::vector< T > > operator- ( // ELEMENT-WISE DIFFERENCE BETWEEN CONSTANT AND VECTOR
126 const T &, // 1st argument (constant)
127 const std::vector< std::vector< T > > & // 2nd argument (std::vector)
128 );
129template <class T>
130std::vector< std::vector< T > > operator- ( // ELEMENT-WISE DIFFERENCE BETWEEN CONSTANT AND VECTOR
131 const std::vector< std::vector< T > > &, // 1st argument (std::vector)
132 const T & // 2nd argument (constant)
133 );
134
135// Operator "-=" -------------------------------------------------------------------- //
136template <class T>
137std::vector< T >& operator-= ( // ELEMENT-WISE DECREMENT OF A VECTOR
138 std::vector< T > &, // 1st argument (std::vector)
139 const std::vector< T > & // 2nd argument (std::vector)
140 );
141template <class T>
142std::vector< T >& operator-= ( // ELEMENT-WISE DECREMENT OF A VECTOR
143 std::vector< T > &, // 1st argument (std::vector)
144 const T & // 2nd argument (constant)
145 );
146template <class T>
147std::vector< std::vector< T > >& operator-= ( // ELEMENT-WISE DECREMENT OF A VECTOR
148 std::vector< std::vector< T > > &, // 1st argument (std::vector)
149 const T & // 2nd argument (constant)
150 );
151
152// Operator "*" --------------------------------------------------------------------- //
153template <class T>
154std::vector< T > operator* ( // ELEMENT-WISE PRODUCT BETWEEN TWO VECTORS
155 const std::vector< T > &, // 1st argument (std::vector)
156 const std::vector< T > & // 2nd argument (std::vector)
157 );
158template <class T>
159std::vector< T > operator* ( // ELEMENT-WISE PRODUCT BETWEEN VECTOR AND CONSTANT
160 const std::vector< T > &, // 1st argument (std::vector)
161 const T & // 2nd argument (constant)
162 );
163template <class T>
164std::vector< T > operator* ( // ELEMENT-WISE PRODUCT BETWEEN CONSTANT AND VECTOR
165 const T &, // 1st argument (constant)
166 const std::vector< T > & // 2nd argument (std::vector)
167 );
168template <class T>
169std::vector< std::vector < T > > operator* ( // ELEMENT-WISE PRODUCT BETWEEN CONSTANT AND VECTOR
170 const T &, // 1st argument (constant)
171 const std::vector< std::vector< T > > & // 2nd argument (std::vector)
172 );
173template <class T>
174std::vector< std::vector< T > > operator* ( // ELEMENT-WISE PRODUCT BETWEEN CONSTANT AND VECTOR
175 const std::vector< std::vector< T > > &, // 1st argument (std::vector)
176 const T & // 2nd argument (constant)
177 );
178
179// Operator "*=" -------------------------------------------------------------------- //
180template <class T>
181std::vector<T>& operator*= (
182 std::vector<T> &,
183 const std::vector<T> &
184 );
185template <class T>
186std::vector<T>& operator*= (
187 std::vector<T> &,
188 const T &
189 );
190template <class T>
191std::vector< std::vector<T> >& operator*= (
192 std::vector< std::vector<T> > &,
193 const T &
194 );
195
196// Operator "/" --------------------------------------------------------------------- //
197template <class T>
198std::vector< T > operator/ ( // ELEMENT-WISE DIVISION BETWEEN VECTORS
199 const std::vector< T > &, // 1st argument (std::vector)
200 const std::vector< T > & // 2nd argument (std::vector)
201 );
202template <class T>
203std::vector< T > operator/ ( // ELEMENT-WISE DIVISION BETWEEN VECTOR AND CONSTANT
204 const std::vector< T > &, // 1st argument (std::vector)
205 const T & // 2nd argument (constant)
206 );
207template <class T>
208std::vector< T > operator/ ( // ELEMENT-WISE DIVISION BETWEEN CONSTANT AND VECTOR
209 const T &, // 1st argument (constant)
210 const std::vector< T > & // 2nd argument (std::vector)
211 );
212template <class T>
213std::vector< std::vector< T > > operator/ ( // ELEMENT-WISE DIVISION BETWEEN CONSTANT AND VECTOR
214 const T &, // 1st argument (constant)
215 const std::vector< std::vector< T > > & // 2nd argument (std::vector)
216 );
217template <class T>
218std::vector< std::vector< T > > operator/ ( // ELEMENT-WISE DIVISION BETWEEN CONSTANT AND VECTOR
219 const std::vector< std::vector< T > > &, // 1st argument (std::vector)
220 const T & // 2nd argument (constant)
221 );
222
223// Operator "/=" -------------------------------------------------------------------- //
224template <class T>
225std::vector<T>& operator/= (
226 std::vector<T> &,
227 const std::vector<T> &
228 );
229template <class T>
230std::vector<T>& operator/= (
231 std::vector<T> &,
232 const T &
233 );
234template <class T>
235std::vector< std::vector<T> >& operator/= (
236 std::vector< std::vector<T> > &,
237 const T &
238 );
239// Output operator ------------------------------------------------------------------ //
240template <class T>
241std::ostream& operator<< ( // INSERTION OPERATOR
242 std::ostream &, // (input) output stream
243 const std::vector< T > & // (input) std::vector to be streamed
244 );
245template <class T>
246std::ofstream& operator<< ( // INSERTION OPERATOR
247 std::ofstream &, // (input) output file stream
248 const std::vector< T > & // (input) std::vector to be streamed
249 );
250
251namespace bitpit {
252
253using ::operator<<;
254
255template <class T>
256Logger& operator<< ( // INSERTION OPERATOR
257 Logger &, // (input) output file stream
258 const std::vector< T > & // (input) std::vector to be streamed
259 );
260
261}
262
263// Input operators ------------------------------------------------------------------ //
264template <class T>
265std::istream& operator>> ( // EXTRACTION OPERATOR
266 std::istream &, // (input) input stream
267 std::vector< T > & // (input/output) std::vector to be streamed
268 );
269template <class T>
270std::ifstream& operator>> ( // EXTRACTION OPERATOR
271 std::ifstream &, // (input) input file stream
272 std::vector< T > & // (input/output) std::vector to be streamed
273 );
274
275// Operator "min" ------------------------------------------------------------------- //
276template <class T>
277std::vector< T > min( // RETURNS THE MINIMUM BETWEEN VECTOR X AND VECTOR Y
278 const std::vector< T > &, // (input) 1st argument of comparison (std::vector)
279 const std::vector< T > & // (input) 2nd argument of comparison (std::vector)
280 );
281template <class T>
282std::vector< T > min( // RETURNS THE MINIMUM BETWEEN VECTOR X AND SCALAR Y
283 const std::vector< T > &, // (input) 1st argument of comparison (std::vector)
284 const T & // (input) 2nd argument of comparison (scalar)
285 );
286template <class T>
287std::vector< T > min( // RETURNS THE MINIMUM BETWEEN VECTOR X AND SCALAR Y
288 const T &, // (input) 1st argument of comparison (scalar)
289 const std::vector< T > & // (input) 2nd argument of comparison (std::vector)
290 );
291template <class T>
292std::vector< std::vector< T > > min( // RETURNS THE MINIMUM BETWEEN VECTOR X AND SCALAR Y
293 const std::vector< std::vector< T > > &, // (input) 1st argument of comparison (std::vector)
294 const T & // (input) 2nd argument of comparison (scalar)
295 );
296template <class T>
297std::vector< std::vector< T > > min( // RETURNS THE MINIMUM BETWEEN VECTOR X AND SCALAR Y
298 const T &, // (input) 1st argument of comparison (scalar)
299 const std::vector< std::vector< T > > & // (input) 2nd argument of comparison (std::vector)
300 );
301
302// Operator "minval" ---------------------------------------------------------------- //
303template<typename T, typename std::enable_if< std::is_scalar< T >::value>::type* = nullptr>
304void inline minval( // DUMMY ROUTINE FOR MINVAL SEARCH
305 const T &, // (dummy input) 1st argument
306 T & // (dummy input/output) 2nd argument
307 );
308template <class T, class T1>
309void minval( // RETURNS THE MINIMUM ELEMENT OF A VECTOR
310 const std::vector<T> &, // (input) input std::vector
311 T1 & // (input/output) minimum element
312 );
313
314// Operator "max" ------------------------------------------------------------------- //
315template <class T>
316std::vector< T > max( // RETURNS THE MAXIMUM BETWEEN X AND Y
317 const std::vector< T > &, // (input) 1st argument of comparison
318 const std::vector< T > & // (input) 2nd argument of comparison
319 );
320template <class T>
321std::vector< T > max( // RETURNS THE MAXIMUM BETWEEN X AND Y
322 const std::vector< T > &, // (input) 1st argument of comparison
323 const T & // (input) 2nd argument of comparison
324 );
325template <class T>
326std::vector< T > max( // RETURNS THE MAXIMUM BETWEEN X AND Y
327 const T &, // (input) 1st argument of comparison
328 const std::vector< T > & // (input) 2nd argument of comparison
329 );
330template <class T>
331std::vector< std::vector< T > > max( // RETURNS THE MAXIMUM BETWEEN X AND Y
332 const std::vector< std::vector< T > > &, // (input) 1st argument of comparison
333 const T & // (input) 2nd argument of comparison
334 );
335template <class T>
336std::vector< std::vector< T > > max( // RETURNS THE MAXIMUM BETWEEN X AND Y
337 const T &, // (input) 1st argument of comparison
338 const std::vector< std::vector< T > > & // (input) 2nd argument of comparison
339 );
340
341// Operator "maxval" ---------------------------------------------------------------- //
342template<typename T, typename std::enable_if< std::is_scalar< T >::value>::type* = nullptr>
343void inline maxval( // DUMMY ROUTINE FOR MAXVAL SEARCH
344 const T &, // (dummy input) 1st argument
345 T & // (dummy input/output) 2nd argument
346 );
347template <class T, class T1>
348void maxval( // RETURNS THE MAXIMUM ELEMENT OF A VECTOR
349 const std::vector<T> &, // (input) input std::vector
350 T1 & // (input/output) maximum element
351 );
352
353// Operator "sum" ------------------------------------------------------------------- //
354template <class T, typename std::enable_if< std::is_scalar< T >::value>::type* = nullptr>
355void inline sum( // DUMMY ROUTINE FOR SUM OPERATOR
356 const T &, // (dummy input) 1st argument
357 T & // (dummy input/output) 2nd argument
358 );
359template <class T, class T1>
360void sum( // RETURNS THE SUM OF ELEMENT OF A VECTOR
361 const std::vector< T > &, // (input) input std::vector
362 T1 & // (input/output) sum of std::vector's element
363 );
364
365// Operator "abs" ------------------------------------------------------------------- //
366template <class T>
367std::vector<T> abs( // RETURNS THE ABSOLUTE VALUE OF A VECTOR
368 const std::vector< T > & // (input) input std::vector
369 );
370
371// Operator "sign" ------------------------------------------------------------------ //
372template <class T>
373T sign( // SIGN FUNCTION
374 const T & // (input) input value
375 );
376
377// Operator "pow with unsigned integer exponential" -------------------------------- //
378template <class T>
379T uipow( // POWER WITH UNSIGNED INTEGER EXPONENTIAL
380 const T &, // (input) input argument
381 unsigned int // (input) power
382 );
383
384// Operator "pow" ------------------------------------------------------------------- //
385template <class T>
386std::vector< T > pow( // RETURNS THE ELEMENTWISE POWER OF VECTOR
387 std::vector< T > &, // (input) input std::vector
388 double // (input) power
389 );
390
391// Operator "norm" ------------------------------------------------------------------ //
392template <class T>
393double norm1( // RETURNS THE 1-NORM OF A VECTOR
394 const std::vector< T > & // (input) input std::vector
395 );
396template <class T>
397double norm2( // RETURNS THE 2-NORM OF A VECTOR
398 const std::vector< T > & // (input) input std::vector
399 );
400template <class T>
401double norm( // RETURNS THE P-NORM OF A VECTOR
402 const std::vector< T > &, // (input) input std::vector
403 int // (input) norm index
404 );
405template <class T>
406double normInf( // RETURNS THE inf-NORM OF A VECTOR
407 const std::vector< T > & // (input) input std::vector
408 );
409
410// Operator "dotProduct" ----------------------------------------------------------- //
411template <class T>
412T dotProduct( // COMPUTE THE DOT PRODUCT OF TWO VECTORS
413 const std::vector< T > &, // (input) 1st argument of dot product
414 const std::vector< T > & // (input) 2nd argument of dot product
415 );
416
417// Operator crossProduct ----------------------------------------------------------- //
418template <class T>
419std::vector<T> crossProduct( // COMPUTE THE CROSS-PRODUCT OF TWO VECTORS
420 std::vector<T> const &, // (input) 1st argument of cross product
421 std::vector<T> const & // (input) 2nd argument of cross product
422 );
423
424// Various -------------------------------------------------------------------------- //
425template<typename T, typename std::enable_if< std::is_scalar< T >::value>::type* = nullptr>
426std::ostream& display( // DUMMY ROUTINE FOR RECURSIVE TEMPLATED FUNCTION display
427 std::ostream &, // (input/output) output stream
428 const T & // (input) std::vector to be displayed
429 );
430template<class T>
431std::ostream& display( // DISPLAY VECTOR IN A NICELY FORMATTED FORM
432 std::ostream &, // (input/output) output stream
433 const std::vector<T> &, // (input) std::vector to be displayed
434 unsigned int padding = 0 // (input/optional) number of trailing spaces
435 );
436template<typename T, typename std::enable_if< std::is_scalar< T >::value>::type* = nullptr>
437std::ofstream& display( // DUMMY ROUTINE FOR RECURSIVE TEMPLATED FUNCTION display
438 std::ofstream &, // (input/output) output stream
439 const T & // (input) std::vector to be displayed
440 );
441template<class T>
442std::ofstream& display( // DISPLAY VECTOR IN A NICELY FORMATTED FORM
443 std::ofstream &, // (input/output) output stream
444 const std::vector<T> &, // (input) std::vector to be displayed
445 unsigned int padding = 0 // (input/optional) number of trailing spaces
446 );
447
448// C++ v10.0 arrays ================================================================= //
449
450// Operator "+" --------------------------------------------------------------------- //
451template <class T, size_t d>
452std::array<T, d> operator+ ( // ELEMENT-WISE SUM BETWEEN ARRAYS
453 const std::array<T, d> &, // 1st argument (std::array)
454 const std::array<T, d> & // 2nd argument (std::array)
455 );
456template <class T, size_t d>
457std::array<T, d> operator+ ( // ELEMENT-WISE SUM BETWEEN ARRAY AND CONSTANT
458 const std::array<T, d> &, // 1st argument (std::array)
459 const T & // 2nd argument (constant)
460 );
461template <class T, size_t d>
462std::array<T, d> operator+ ( // ELEMENT-WISE SUM BETWEEN CONSTANT AND ARRAY
463 const T &, // 1st argument (constant)
464 const std::array<T, d> & // 2nd argument (std::array)
465 );
466template <class T, size_t d, size_t e>
467std::array<std::array<T, e>, d> operator+ ( // ELEMENT-WISE SUM BETWEEN CONSTANT AND 2D ARRAY
468 const T &, // 1st argument (constant)
469 const std::array<std::array<T, e>, d> & // 2nd argument (std::array)
470 );
471template <class T, size_t d, size_t e>
472std::array<std::array<T, e>, d> operator+ ( // ELEMENT-WISE SUM BETWEEN 2D ARRAY AND CONSTANT
473 const std::array<std::array<T, e>, d> &, // 1st argument (constant)
474 const T & // 2nd argument (std::array)
475 );
476
477// Operator "+=" -------------------------------------------------------------------- //
478template <class T, size_t d>
479std::array< T, d >& operator+= ( // ELEMENT-WISE INCREMENT OF A ARRAY
480 std::array< T, d > &, // 1st argument (std::array)
481 const std::array< T, d > & // 2nd argument (std::array)
482 );
483template <class T, size_t d>
484std::array< T, d >& operator+= ( // ELEMENT-WISE INCREMENT OF A ARRAY
485 std::array< T, d > &, // 1st argument (std::array)
486 const T & // 2nd argument (constant)
487 );
488template <class T, size_t d, size_t e>
489std::array< std::array< T, e >, d >& operator+= ( // ELEMENT-WISE INCREMENT OF A ARRAY
490 std::array< std::array< T, e >, d > &, // 1st argument (std::array)
491 const T & // 2nd argument (constant)
492 );
493
494// Operator "-" --------------------------------------------------------------------- //
495template <class T, size_t d>
496std::array<T, d> operator- ( // ELEMENT-WISE DIFFERENCE BETWEEN TWO ARRAYS
497 const std::array<T, d> &, // 1st argument (std::array)
498 const std::array<T, d> & // 2nd argument (std::array)
499 );
500template <class T, size_t d>
501std::array<T, d> operator- ( // ELEMENT-WISE DIFFERENCE BETWEEN ARRAY AND CONSTANT
502 const std::array<T, d> &, // 1st argument (std::array)
503 const T & // 2nd argument (constant)
504 );
505template <class T, size_t d>
506std::array<T, d> operator- ( // ELEMENT-WISE DIFFERENCE BETWEEN CONSTANT AND ARRAY
507 const T &, // 1st argument (constant)
508 const std::array<T, d> & // 2nd argument (std::array)
509 );
510template <class T, size_t d, size_t e>
511std::array<std::array<T, e>, d> operator- ( // ELEMENT-WISE DIFFERENCE BETWEEN CONSTANT AND 2D ARRAY
512 const T &, // 1st argument (constant)
513 const std::array<std::array<T, e>, d> & // 2nd argument (std::array)
514 );
515template <class T, size_t d, size_t e>
516std::array<std::array<T, e>, d> operator- ( // ELEMENT-WISE DIFFERENCE BETWEEN 2D ARRAY AND CONSTANT
517 const std::array<std::array<T, e>, d> &, // 1st argument (std::array)
518 const T & // 2nd argument (constant)
519 );
520
521// Operator "-=" -------------------------------------------------------------------- //
522template <class T, size_t d>
523std::array< T, d >& operator-= ( // ELEMENT-WISE DECREMENT OF A ARRAY
524 std::array< T, d > &, // 1st argument (std::array)
525 const std::array< T, d > & // 2nd argument (std::array)
526 );
527template <class T, size_t d>
528std::array< T, d >& operator-= ( // ELEMENT-WISE DECREMENT OF A ARRAY
529 std::array< T, d > &, // 1st argument (std::array)
530 const T & // 2nd argument (constant)
531 );
532template <class T, size_t d, size_t e>
533std::array< std::array< T, e >, d >& operator-= ( // ELEMENT-WISE DECREMENT OF A ARRAY
534 std::array< std::array< T, e >, d > &, // 1st argument (std::array)
535 const T & // 2nd argument (constant)
536 );
537
538// Operator "*" --------------------------------------------------------------------- //
539template <class T, size_t d>
540std::array<T, d> operator* ( // ELEMENT-WISE PRODUCT BETWEEN TWO ARRAYS
541 const std::array<T, d> &, // 1st argument (std::array)
542 const std::array<T, d> & // 2nd argument (std::array)
543 );
544template <class T, size_t d>
545std::array<T, d> operator* ( // ELEMENT-WISE PRODUCT BETWEEN ARRAY AND CONSTANT
546 const std::array<T, d> &, // 1st argument (std::array)
547 const T & // 2nd argument (constant)
548 );
549template <class T, size_t d>
550std::array<T, d> operator* ( // ELEMENT-WISE PRODUCT BETWEEN CONSTANT AND ARRAY
551 const T &, // 1st argument (constant)
552 const std::array<T, d> & // 2nd argument (std::array)
553 );
554template <class T, size_t d, size_t e>
555std::array<std::array<T, e>, d> operator* ( // ELEMENT-WISE PRODUCT BETWEEN CONSTANT AND 2D ARRAY
556 const T &, // 1st argument (constant)
557 const std::array<std::array<T, e>, d> & // 2nd argument (std::array)
558 );
559template <class T, size_t d, size_t e>
560std::array<std::array<T, e>, d> operator* ( // ELEMENT-WISE PRODUCT BETWEEN 2D ARRAY AND CONSTANT
561 const std::array<std::array<T, e>, d> &, // 1st argument (std::array)
562 const T & // 2nd argument (constant)
563 );
564
565// Operator "*=" -------------------------------------------------------------------- //
566template <class T, size_t d>
567std::array< T, d >& operator*= ( // ELEMENT-WISE INCREMENT OF A ARRAY
568 std::array< T, d > &, // 1st argument (std::array)
569 const std::array< T, d > & // 2nd argument (std::array)
570 );
571template <class T, size_t d>
572std::array< T, d >& operator*= ( // ELEMENT-WISE INCREMENT OF A ARRAY
573 std::array< T, d > &, // 1st argument (std::array)
574 const T & // 2nd argument (constant)
575 );
576template <class T, size_t d, size_t e>
577std::array< std::array< T, e >, d >& operator*= ( // ELEMENT-WISE INCREMENT OF A ARRAY
578 std::array< std::array< T, e >, d > &, // 1st argument (std::array)
579 const T & // 2nd argument (constant)
580 );
581
582// Operator "/" --------------------------------------------------------------------- //
583template <class T, size_t d>
584std::array<T, d> operator/ ( // ELEMENT-WISE DIVISION BETWEEN ARRAYS
585 const std::array<T, d> &, // 1st argument (std::array)
586 const std::array<T, d> & // 2nd argument (std::array)
587 );
588template <class T, size_t d>
589std::array<T, d> operator/ ( // ELEMENT-WISE DIVISION BETWEEN ARRAY AND CONSTANT
590 const std::array<T, d> &, // 1st argument (std::array)
591 const T & // 2nd argument (constant)
592 );
593template <class T, size_t d>
594std::array<T, d> operator/ ( // ELEMENT-WISE DIVISION BETWEEN CONSTANT AND ARRAY
595 const T &, // 1st argument (constant)
596 const std::array<T, d> & // 2nd argument (std::array)
597 );
598template <class T, size_t d, size_t e>
599std::array<std::array<T, e>, d> operator/ ( // ELEMENT-WISE DIVISION BETWEEN CONSTANT AND 2D ARRAY
600 const T &, // 1st argument (constant)
601 const std::array<std::array<T, e>, d> & // 2nd argument (std::array)
602 );
603template <class T, size_t d, size_t e>
604std::array<std::array<T, e>, d> operator/ ( // ELEMENT-WISE PRODUCT BETWEEN 2D ARRAY AND CONSTANT
605 const std::array<std::array<T, e>, d> &, // 1st argument (std::array)
606 const T & // 2nd argument (constant)
607 );
608
609// Operator "/=" -------------------------------------------------------------------- //
610template <class T, size_t d>
611std::array< T, d >& operator/= ( // ELEMENT-WISE INCREMENT OF A ARRAY
612 std::array< T, d > &, // 1st argument (std::array)
613 const std::array< T, d > & // 2nd argument (std::array)
614 );
615template <class T, size_t d>
616std::array< T, d >& operator/= ( // ELEMENT-WISE INCREMENT OF A ARRAY
617 std::array< T, d > &, // 1st argument (std::array)
618 const T & // 2nd argument (constant)
619 );
620template <class T, size_t d, size_t e>
621std::array< std::array< T, e >, d >& operator/= ( // ELEMENT-WISE INCREMENT OF A ARRAY
622 std::array< std::array< T, e >, d > &, // 1st argument (std::array)
623 const T & // 2nd argument (constant)
624 );
625
626// Output operator ------------------------------------------------------------------ //
627template <class T, size_t d>
628std::ostream& operator<< ( // INSERTION OPERATOR
629 std::ostream &, // (input) output stream
630 const std::array<T, d> & // (input) std::array to be streamed
631 );
632template <class T, size_t d>
633std::ofstream& operator<< ( // INSERTION OPERATOR
634 std::ofstream &, // (input) output file stream
635 const std::array<T, d> & // (input) std::array to be streamed
636 );
637
638namespace bitpit {
639
640using ::operator<<;
641
642template <class T, size_t d>
643Logger& operator<< ( // INSERTION OPERATOR
644 Logger &, // (input) logger
645 const std::array<T, d> & // (input) std::array to be streamed
646 );
647
648}
649
650// Input operators ------------------------------------------------------------------ //
651template <class T, size_t d>
652std::istream& operator>> ( // EXTRACTION OPERATOR
653 std::istream &, // (input) input stream
654 std::array< T, d > & // (input/output) std::array to be streamed
655 );
656template <class T, size_t d>
657std::ifstream& operator>> ( // EXTRACTION OPERATOR
658 std::ifstream &, // (input) input file stream
659 std::array<T, d> & // (input) std::array to be streamed
660 );
661
662// Operator "min" ------------------------------------------------------------------- //
663template <class T, size_t d>
664std::array<T, d> min( // RETURNS THE MINIMUM BETWEEN ARRAY X AND ARRAY Y
665 const std::array<T, d> &, // (input) 1st argument of comparison (std::array)
666 const std::array<T, d> & // (input) 2nd argument of comparison (std::array)
667 );
668template <class T, size_t d>
669std::array<T, d> min( // RETURNS THE MINIMUM BETWEEN ARRAY X AND SCALAR Y
670 const std::array<T, d> &, // (input) 1st argument of comparison (std::array)
671 const T & // (input) 2nd argument of comparison (scalar)
672 );
673template <class T, size_t d>
674std::array<T, d> min( // RETURNS THE MINIMUM BETWEEN SCALAR X AND SCALAR Y
675 const T &, // (input) 1st argument of comparison (scalar)
676 const std::array<T, d> & // (input) 2nd argument of comparison (std::array)
677 );
678template <class T, size_t d, size_t n>
679std::array<std::array<T, n>, d> min( // RETURNS THE MINIMUM BETWEEN 2D ARRAY X AND SCALAR Y
680 const std::array<std::array<T, n>, d> &, // (input) 1st argument of comparison (std::array)
681 const T & // (input) 2nd argument of comparison (scalar)
682 );
683template <class T, size_t d, size_t n>
684std::array<std::array<T, n>, d> min( // RETURNS THE MINIMUM BETWEEN SCALAR X AND 2D ARRAY Y
685 const T &, // (input) 1st argument of comparison (scalar)
686 const std::array<std::array<T, n>, d> & // (input) 2nd argument of comparison (std::array)
687 );
688
689// Operator "minval" ---------------------------------------------------------------- //
690template <class T, size_t d, class T1>
691void minval( // RETURNS THE MINIMUM ELEMENT OF A ARRAY
692 const std::array<T, d> &, // (input) input std::array
693 T1 & // (input/output) minimum element
694 );
695
696// Operator "max" ------------------------------------------------------------------- //
697template <class T, size_t d>
698std::array<T, d> max( // RETURNS THE MAXIMUM BETWEEN TWO ARRAYS
699 const std::array<T, d> &, // (input) 1st argument of comparison (std::array)
700 const std::array<T, d> & // (input) 2nd argument of comparison (std::array)
701 );
702template <class T, size_t d>
703std::array<T, d> max( // RETURNS THE MAXIMUM BETWEEN ARRAY AND SCALAR
704 const std::array<T, d> &, // (input) 1st argument of comparison (std::array)
705 const T & // (input) 2nd argument of comparison (scalar)
706 );
707template <class T, size_t d>
708std::array<T, d> max( // RETURNS THE MAXIMUM BETWEEN ARRAY AND SCALAR
709 const T &, // (input) 1st argument of comparison (scalar)
710 const std::array<T, d> & // (input) 2nd argument of comparison (std::array)
711 );
712template <class T, size_t d, size_t n>
713std::array<std::array<T, n>, d> max( // RETURNS THE MAXIMUM BETWEEN ARRAY AND SCALAR
714 const std::array<std::array<T, n>, d> &, // (input) 1st argument of comparison (std::array)
715 const T & // (input) 2nd argument of comparison (scalar)
716 );
717template <class T, size_t d, size_t n>
718std::array<std::array<T, n>, d> max( // RETURNS THE MAXIMUM BETWEEN ARRAY AND SCALAR
719 const T &, // (input) 1st argument of comparison (scalar)
720 const std::array<std::array<T, n>, d> & // (input) 2nd argument of comparison (std::array)
721 );
722
723// Operator "maxval" ---------------------------------------------------------------- //
724template <class T, size_t d, class T1>
725void maxval( // RETURNS THE MAXIMUM ELEMENT OF A ARRAY
726 const std::array<T, d> &, // (input) input std::array
727 T1 & // (input/output) maximum element
728 );
729
730// Operator "sum" ------------------------------------------------------------------- //
731template <class T, size_t d, class T1>
732void sum( // RETURNS THE SUM OF ARRAY ELEMENTS
733 const std::array<T, d> &, // (input) input std::array
734 T1 & // (input/output) sum of std::array's elements
735 );
736
737// Operator "abs" ------------------------------------------------------------------- //
738template <class T, size_t d>
739std::array<T, d> abs( // RETURNS THE ABSOLUTE VALUE OF A ARRAY
740 const std::array<T, d> & // (input) input std::array
741 );
742
743// Operator "pow" ------------------------------------------------------------------- //
744template <class T, size_t d>
745std::array<T, d> pow( // RETURNS THE ELEMENTWISE POWER OF ARRAY
746 std::array<T, d> &, // (input) input std::array
747 double // (input) power
748 );
749
750// Operator "norm" ------------------------------------------------------------------ //
751template <class T, size_t d>
752double norm1( // RETURNS THE 1-NORM OF ARRAY
753 const std::array<T, d> & // (input) input std::array
754 );
755template <class T, size_t d>
756double norm2( // RETURNS THE 2-NORM OF ARRAY
757 const std::array<T, d> & // (input) input std::array
758 );
759template <class T, size_t d>
760double norm( // RETURNS THE p-NORM OF ARRAY
761 const std::array<T, d> &, // (input) input std::array
762 int // (input) norm index
763 );
764template <class T, size_t d>
765double normInf( // RETURNS THE inf NORM OF ARRAY
766 const std::array<T, d> & // (input) input std::array
767 );
768
769// Operator "dotProduct" ----------------------------------------------------------- //
770template <class T, size_t d>
771T dotProduct( // COMPUTE THE DOT PRODUCT OF TWO ARRAYS
772 const std::array<T, d> &, // (input) 1st argument of dot product
773 const std::array<T, d> & // (input) 2nd argument of dot product
774 );
775
776// Operator crossProduct ----------------------------------------------------------- //
777template <class T, size_t d>
778T crossProduct( // COMPUTE THE CROSS-PRODUCT OF TWO ARRAYS
779 std::array<T, 2> const &, // (input) 1st argument of cross product
780 std::array<T, 2> const & // (input) 2nd argument of cross product
781 );
782
783template <class T, size_t d>
784std::array<T, 3> crossProduct( // COMPUTE THE CROSS-PRODUCT OF TWO ARRAYS
785 std::array<T, 3> const &, // (input) 1st argument of cross product
786 std::array<T, 3> const & // (input) 2nd argument of cross product
787 );
788
789// Various -------------------------------------------------------------------------- //
790template<class T, size_t d>
791std::ostream& display( // DISPLAY ARRAY IN A NICELY FORMATTED FORM
792 std::ostream &, // (input/output) output stream
793 const std::array<T, d> &, // (input) std::array to be displayed
794 unsigned int padding = 0 // (input/optional) number of trailing spaces
795 );
796template<class T, size_t d>
797std::ofstream& display( // DISPLAY ARRAY IN A NICELY FORMATTED FORM
798 std::ofstream &, // (input/output) output stream
799 const std::array<T, d> &, // (input) std::array to be displayed
800 unsigned int padding = 0 // (input/optional) number of trailing spaces
801 );
802
803
804// ================================================================================== //
805// TEMPLATES //
806// ================================================================================== //
807# include "Operators.tpp"
808# include "Operators_vector.tpp"
809# include "MathOperators_vector.tpp"
810# include "Operators_array.tpp"
811# include "MathOperators_array.tpp"
812
813#endif
: Basic operator for (C++11) std::array
std::ostream & display(std::ostream &, const T &)
std::array< T, d > abs(const std::array< T, d > &x)
void sum(const std::array< T, d > &x, T1 &s)
double norm(const std::array< T, d > &x, int p)
std::array< T, 3 > crossProduct(const std::array< T, 3 > &x, const std::array< T, 3 > &y)
void maxval(const std::array< T, d > &x, T1 &max_value)
T sign(const T &)
Definition Operators.tpp:38
void minval(const std::array< T, d > &x, T1 &min_value)
T dotProduct(const std::array< T, d > &x, const std::array< T, d > &y)
double norm1(const std::array< T, d > &x)
double norm2(const std::array< T, d > &x)
std::array< T, d > max(const std::array< T, d > &x, const std::array< T, d > &y)
double normInf(const std::array< T, d > &x)
std::vector< T > min(const std::vector< T > &, const std::vector< T > &)
std::array< T, d > pow(std::array< T, d > &x, double p)
T uipow(const T &, unsigned int)
Definition Operators.tpp:55
std::vector< T > operator+(const std::vector< T > &, const std::vector< T > &)
std::ostream & operator<<(std::ostream &, const std::vector< T > &)
--- layout: doxygen_footer ---