OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
PolynomialSum.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018, Martin Duy Tat
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 * 2. Redistributions in binary form must reproduce the above copyright notice,
9 * this list of conditions and the following disclaimer in the documentation
10 * and/or other materials provided with the distribution.
11 * 3. Neither the name of STFC nor the names of its contributors may be used to
12 * endorse or promote products derived from this software without specific
13 * prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef POLYNOMIAL_SUM_H
29#define POLYNOMIAL_SUM_H
30
47#include <vector>
48#include "TwoPolynomial.h"
49
50namespace polynomial {
51
53public:
60 explicit PolynomialSum(const TwoPolynomial &polynomial);
62 PolynomialSum(const PolynomialSum &polynomialSum);
68 void differentiateX();
70 void differentiateS();
74 void multiplyPolynomial(const TwoPolynomial &poly);
76 void printPolynomial() const;
78 std::size_t numberOfTerms() const;
83 bool isPolynomialZero(const std::size_t &p) const;
87 void truncate(const std::size_t &truncateOrder);
94 double evaluatePolynomial(const std::size_t &p,
95 const double &x,
96 const double &s) const;
105 void putSumTogether(const std::vector<double> &dSvalues,
106 std::vector<std::vector<double>> &finalPolynomial) const;
113 double evaluatePolynomial2(const double &x,
114 const double &s,
115 const std::vector<double> &dSvalues) const;
119 void addPolynomial(const PolynomialSum &poly);
124 std::vector<std::size_t> getdSfactors(const std::size_t &p) const;
130 void sortTerms();
131private:
132 std::vector<TwoPolynomial> polynomialSum_m;
133};
134
135inline
136 std::size_t PolynomialSum::numberOfTerms() const {
137 return polynomialSum_m.size();
138}
139inline
140 double PolynomialSum::evaluatePolynomial(const std::size_t &p,
141 const double &x,
142 const double &s) const {
143 if (p >= polynomialSum_m.size()) {
144 return 0.0;
145 }
146 return polynomialSum_m[p].evaluatePolynomial(x, s);
147}
148
149}
150
151#endif
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
Definition: PETE.h:1111
bool isPolynomialZero(const std::size_t &p) const
void addPolynomial(const PolynomialSum &poly)
void putSumTogether(const std::vector< double > &dSvalues, std::vector< std::vector< double > > &finalPolynomial) const
void truncate(const std::size_t &truncateOrder)
PolynomialSum & operator=(const PolynomialSum &sum)
void multiplyPolynomial(const TwoPolynomial &poly)
std::vector< TwoPolynomial > polynomialSum_m
std::size_t numberOfTerms() const
std::vector< std::size_t > getdSfactors(const std::size_t &p) const
double evaluatePolynomial(const std::size_t &p, const double &x, const double &s) const
double evaluatePolynomial2(const double &x, const double &s, const std::vector< double > &dSvalues) const