CEPS  24.01
Cardiac ElectroPhysiology Simulator
CepsArray.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 #pragma once
32 
33 #include <array>
34 #include <ostream>
35 
37 
38 template <class _Type, CepsSize _N>
39 std::ostream&
40 operator<<(std::ostream& os, const CepsArray<_Type, _N>& a)
41 {
42  for (CepsUInt i=0; i<_N-1; ++i)
43  os << a[i] << ", " << std::flush;
44  os << a[_N-1] << std::flush;
45  return os;
46 }
47 
49 template <class _Type, CepsSize _N>
52 {
53 
54  CepsReal amax = std::abs(std::min(a[0],b[0]));
55  for (CepsUInt i=1; i<_N; ++i)
56  amax = std::max(amax,std::abs(std::min(a[i],b[i])));
57 
58  CepsReal errN = std::numeric_limits<CepsReal>::epsilon()*error*amax;
59 
60  for (CepsUInt i=0; i<_N; ++i)
61  if (not (std::fabs(a[i]-b[i]) <= errN))
62  return false;
63  return true;
64 }
65 
67 template <class _Factor, class _Type, CepsSize _N>
69 operator*(_Factor f, const CepsArray<_Type, _N>& a)
70 {
71  CepsArray<_Type, _N> res(a);
72  for (CepsUInt i = 0U; i < _N; i++)
73  res[i] *= f;
74  return res;
75 }
76 
78 template <class _Factor, class _Type, CepsSize _N>
80 operator*(const CepsArray<_Type, _N>& a, _Factor f)
81 {
82  return f * a;
83 }
84 
86 template <class _Type, CepsSize _N>
89 {
90  for (CepsUInt i=0U; i<_N; i++)
91  a[i] += b[i];
92  return a;
93 }
94 
96 template <class _Type, CepsSize _N>
99 {
100  CepsArray<_Type, _N> res(a);
101  res += b;
102  return res;
103 }
104 
106 template <class _Type, CepsSize _N>
109 {
110  for (CepsUInt i=0U; i<_N; i++)
111  a[i] -= b[i];
112  return a;
113 }
114 
116 template <class _Type, CepsSize _N>
119 {
120  CepsArray<_Type, _N> res(a);
121  res -= b;
122  return res;
123 }
124 
126 template <class _Type, CepsSize _N>
129 {
130  return -1*a;
131 }
std::ostream & operator<<(std::ostream &os, const CepsArray< _Type, _N > &a)
Definition: CepsArray.hpp:40
CepsArray< _Type, _N > operator+(const CepsArray< _Type, _N > &a, const CepsArray< _Type, _N > &b)
Overloaded addition for CepsArray.
Definition: CepsArray.hpp:98
CepsArray< _Type, _N > operator-(const CepsArray< _Type, _N > &a, const CepsArray< _Type, _N > &b)
Overloaded substraction for CepsArray.
Definition: CepsArray.hpp:118
CepsArray< _Type, _N > operator*(_Factor f, const CepsArray< _Type, _N > &a)
Overloaded multiplication by scalar for CepsArray.
Definition: CepsArray.hpp:69
CepsArray< _Type, _N > & operator+=(CepsArray< _Type, _N > &a, const CepsArray< _Type, _N > &b)
Overloaded addition for CepsArray.
Definition: CepsArray.hpp:88
CepsArray< _Type, _N > & operator-=(CepsArray< _Type, _N > &a, const CepsArray< _Type, _N > &b)
Overloaded substraction for CepsArray.
Definition: CepsArray.hpp:108
CepsBool areSameArray(const CepsArray< _Type, _N > &a, const CepsArray< _Type, _N > &b, const CepsReal error=1.)
Test equality of arrays, suitable for real numbers.
Definition: CepsArray.hpp:51
std::array< _Type, _N > CepsArray
C++ arrays.
Definition: CepsTypes.hpp:159
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
const _Type & max(const CepsVector< _Type, _Alloc > &vec)
Returns the maximum of the vector, const version.
Definition: CepsVector.hpp:464
const _Type & min(const CepsVector< _Type, _Alloc > &vec)
Returns the minimum of the vector, const version.
Definition: CepsVector.hpp:448