CEPS  24.01
Cardiac ElectroPhysiology Simulator
CepsPolynomial.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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
30 #pragma once
31 
33 
39 template <CepsUInt _ArgsDim>
40 class Monomial : public ceps::Function<CepsReal (const CepsArray<CepsReal, _ArgsDim> &)>
41 {
42  public:
43 
52 
54  Monomial (const ExponentType &exponent = {});
55 
57  Monomial (const Monomial &that);
58 
60  Monomial &
61  operator= (const Monomial &that);
62 
65 
68  getExponents() const;
69 
71  void
72  setExponents (const ExponentType &exponent);
73 
75  CepsReal
76  eval (const ArgType &x) override;
77 
80  gradient (const ArgType &x) const;
81 
83  CepsBool
84  operator== (const Monomial &other) const;
85 
87  CepsBool
88  operator== (const ExponentType &other) const;
89 
91  Monomial
92  operator* (const Monomial &other) const;
93 
98  Monomial
99  operator/ (const Monomial &other) const;
100 
101  protected:
104 
105 };
106 
107 
112 template <CepsUInt _ArgsDim>
113 class Polynomial : public ceps::Function<CepsReal (const CepsArray<CepsReal, _ArgsDim> &)>
114 {
115 
116  public:
117 
128 
131 
133  Polynomial (const Polynomial &that);
134 
136  Polynomial &
137  operator= (const Polynomial &that);
138 
141 
143  void
144  add (CepsReal coeff, ExponentType exponent);
145 
147  void
148  add (const CepsVector<CepsReal> &coeffs, const CepsVector<ExponentType> &exponents);
149 
151  void
152  add (const Eigen::Matrix<CepsReal, 1, -1> &coeffs, const CepsVector<ExponentType> &exponents);
153 
155  void
156  setCoeff (CepsReal coeff, const ExponentType &exponent);
157 
159  CepsBool
160  contains (const MonomialType &other);
161 
163  CepsBool
164  contains (const ExponentType &other);
165 
167  CepsReal &
168  coeffAt (const ExponentType &other);
169 
171  CepsReal
172  eval (const ArgType &x) override;
173 
176  gradient (const ArgType &x) const;
177 
179  CepsUInt
181 
183  void
184  reset ();
185 
187  void
189 
191  Polynomial
193 
194  protected:
199 };
200 
201 // Template member definitions
std::array< _Type, _N > CepsArray
C++ arrays.
Definition: CepsTypes.hpp:159
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
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
#define FLOATING_POINT_EPSILON
Definition: CepsTypes.hpp:117
A class that describes a monomial of N variables It contains exponents and coefficients for each dime...
Monomial operator/(const Monomial &other) const
Return this/other. There is no check that the resulting exponents are positive.
CepsReal eval(const ArgType &x) override
Evaluate at x (x in )
GradientType gradient(const ArgType &x) const
Evaluate gradient at x (x in )
Monomial(const ExponentType &exponent={})
Constructor with given exponent (or default)
Monomial(const Monomial &that)
Copy constructor.
CepsArray< CepsReal, _ArgsDim > GradientType
convenience typedef
Monomial operator*(const Monomial &other) const
Return this*other.
void setExponents(const ExponentType &exponent)
Sets all the exponents.
CepsArray< CepsInt, _ArgsDim > ExponentType
convenience typedef
~Monomial()
destructor
ExponentType m_exponent
The exponents for each dimension.
CepsArray< CepsReal, _ArgsDim > ArgType
convenience typedef
CepsBool operator==(const Monomial &other) const
Check equality of monomes (ie same exponents)
ExponentType getExponents() const
get the exponents
Monomial & operator=(const Monomial &that)
Assignment operator.
A class to represent polynomials, as a collection of Monomial and coefficients.
Polynomial operator*(const Polynomial &b)
Returns this*b.
CepsVector< MonomialType > m_mono
The monomes.
Polynomial()
Default constructor, empty polynomial.
typename Monomial< _ArgsDim >::ArgType ArgType
convenience typedef
void add(const Eigen::Matrix< CepsReal, 1, -1 > &coeffs, const CepsVector< ExponentType > &exponents)
Adds several new monomials to the polynomial, Eigen format.
CepsUInt getNumberOfMonomials() const
Returns "size" of polynomial.
void setCoeff(CepsReal coeff, const ExponentType &exponent)
Change the coefficient of a given monomial.
void add(CepsReal coeff, ExponentType exponent)
Adds a new monomial to the polynomial.
~Polynomial()
destructor
GradientType gradient(const ArgType &x) const
Evaluate gradient at x (x in )
CepsReal eval(const ArgType &x) override
Evaluate at x (x in )
CepsBool contains(const MonomialType &other)
Tells if polynomial contains the given monomial.
typename Monomial< _ArgsDim >::ExponentType ExponentType
convenience typedef
typename Monomial< _ArgsDim >::FunctionType FunctionType
convenience typedef
CepsReal & coeffAt(const ExponentType &other)
Get the coefficient of the associated monomial. 0 if missing.
Polynomial & operator=(const Polynomial &that)
Assignment operator.
Polynomial(const Polynomial &that)
Copy constructor.
void pruneZeroCoeffs(CepsReal epsilon=FLOATING_POINT_EPSILON)
Removes monomial with 0 coefficient.
typename Monomial< _ArgsDim >::GradientType GradientType
convenience typedef
CepsBool contains(const ExponentType &other)
Tells if polynomial contains the given monomial.
CepsVector< CepsReal > m_coeffs
Coefficients for all monomes.
void reset()
Wipes the content.
void add(const CepsVector< CepsReal > &coeffs, const CepsVector< ExponentType > &exponents)
Adds several new monomials to the polynomial.
function caller : abstract base, only contains an variadic operator()