NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
statslogic.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2021 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef STATSLOGIC_HPP
20#define STATSLOGIC_HPP
21
22#include "../ParserLib/muParserDef.h"
23
30{
32 {
40 };
41
45
46 StatsLogic(OperationType type, double baseVal = 0.0, mu::value_type compVal = 0.0)
47 : m_val(baseVal), m_compval(compVal), m_type(type) {}
48
56 void operator()(const mu::value_type& newVal)
57 {
58 if (mu::isnan(newVal))
59 return;
60
61 switch (m_type)
62 {
63 case OPERATION_ADD:
64 m_val += newVal;
65 return;
66 case OPERATION_MULT:
67 m_val *= newVal;
68 return;
69 case OPERATION_ADDSQ:
70 m_val += newVal * conj(newVal);
71 return;
73 m_val += (newVal - m_compval)*std::conj(newVal - m_compval);
74 return;
75 case OPERATION_MAX:
76 m_val = newVal.real() > m_val.real() || isnan(m_val.real()) ? newVal.real() : m_val.real();
77 return;
78 case OPERATION_MIN:
79 m_val = newVal.real() < m_val.real() || isnan(m_val.real()) ? newVal.real() : m_val.real();
80 return;
81 case OPERATION_NUM:
82 m_val += 1.0;
83 return;
84 }
85 }
86
95 void combine(const StatsLogic& other)
96 {
97 if (mu::isnan(other.m_val))
98 return;
99
100 switch (m_type)
101 {
102 case OPERATION_ADD:
103 case OPERATION_NUM:
104 case OPERATION_ADDSQ:
106 m_val += other.m_val;
107 return;
108 case OPERATION_MULT:
109 m_val *= other.m_val;
110 return;
111 case OPERATION_MAX:
112 m_val = other.m_val.real() > m_val.real() || isnan(m_val.real()) ? other.m_val.real() : m_val.real();
113 return;
114 case OPERATION_MIN:
115 m_val = other.m_val.real() < m_val.real() || isnan(m_val.real()) ? other.m_val.real() : m_val.real();
116 return;
117 }
118 }
119};
120
121
122#endif // STATSLOGIC_HPP
123
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
bool isnan(const value_type &v)
Definition: muParserDef.h:379
Simplify the creation of some statistics by externalizing the operation code and unifying the driver ...
Definition: statslogic.hpp:30
mu::value_type m_val
Definition: statslogic.hpp:42
OperationType m_type
Definition: statslogic.hpp:44
StatsLogic(OperationType type, double baseVal=0.0, mu::value_type compVal=0.0)
Definition: statslogic.hpp:46
mu::value_type m_compval
Definition: statslogic.hpp:43
void combine(const StatsLogic &other)
Combines results from different StatsLogic instances into a single result.
Definition: statslogic.hpp:95
@ OPERATION_ADDSQSUB
Definition: statslogic.hpp:36
void operator()(const mu::value_type &newVal)
Implements the statistics logic.
Definition: statslogic.hpp:56