File indexing completed on 2026-06-02 08:17:14
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "apfel/convolutionmap.h"
0010 #include "apfel/distribution.h"
0011
0012 #include <functional>
0013
0014 namespace apfel
0015 {
0016
0017
0018
0019
0020
0021 template<class T>
0022 class Set
0023 {
0024 public:
0025
0026
0027
0028
0029
0030 Set(ConvolutionMap const& Map = ConvolutionMap{"UNDEFINED"}, std::map<int, T> const& in = std::map<int, T> {});
0031
0032
0033
0034
0035
0036
0037
0038 Set(std::map<int, T> const& in);
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 template<class V> Set<V> operator *= (Set<V> const& d) const;
0050
0051 Set<T>& operator *= (double const& s);
0052 Set<T>& operator *= (std::function<double(double const&)> f);
0053 Set<T>& operator *= (std::function<std::vector<double>(double const&)> f);
0054 Set<T>& operator *= (std::vector<double> const& v);
0055 Set<T>& operator *= (std::map<int, double> const& v);
0056 Set<T>& operator /= (double const& s);
0057 Set<T>& operator += (Set<T> const& d);
0058 Set<T>& operator -= (Set<T> const& d);
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 T const& at(int const& id) const { return _objects.at(id); }
0070
0071
0072
0073 ConvolutionMap const& GetMap() const { return _map; }
0074
0075
0076
0077 std::map<int, T> const& GetObjects() const { return _objects; }
0078
0079
0080
0081
0082
0083 void SetMap(ConvolutionMap const& map) { _map = map; }
0084
0085
0086
0087
0088
0089 void SetObjects(std::map<int, T> const& objects) { _objects = objects; }
0090
0091
0092
0093
0094
0095 T Combine() const;
0096
0097
0098
0099
0100
0101
0102 T Combine(std::vector<double> const& weigths) const;
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 Set<T> Transform(std::map<int, std::function<double(double const&)>> const& TranformationFuncs) const;
0113
0114
0115
0116
0117
0118
0119
0120
0121 Set<T> Transform(std::map<int, std::map<int, std::function<double(double const&)>>> const& TranformationFuncs) const;
0122
0123
0124
0125
0126
0127
0128
0129
0130 Set<T> Transform(std::map<int, std::function<double(std::map<int, double> const&)>> const& TranformationFuncs) const;
0131
0132
0133
0134
0135
0136
0137
0138
0139 Set<Distribution> Evaluate(double const& x) const;
0140
0141
0142
0143
0144
0145 std::map<int, double> Squash() const;
0146
0147
0148
0149
0150 void Print() const { std::cout << *this << std::endl; }
0151
0152 private:
0153 ConvolutionMap _map;
0154 std::map<int, T> _objects;
0155
0156 template<class U>
0157 friend std::ostream& operator << (std::ostream& os, Set<U> const& s);
0158 };
0159
0160
0161
0162
0163
0164 template<class A, class B>
0165 Set<B> operator * (Set<A> lhs, Set<B> const& rhs) { return lhs *= rhs; }
0166
0167
0168 template<class T>
0169 Set<T> operator * (double const& s, Set<T> rhs) { return rhs *= s; }
0170
0171 template<class T>
0172 Set<T> operator * (Set<T> lhs, double const& s) { return lhs *= s; }
0173
0174 template<class T>
0175 Set<T> operator * (std::function<double(double const&)> f, Set<T> rhs) { return rhs *= f; }
0176
0177 template<class T>
0178 Set<T> operator * (std::function<std::vector<double>(double const&)> f, Set<T> rhs) { return rhs *= f; }
0179
0180 template<class T>
0181 Set<T> operator * (Set<T> lhs, std::function<double(double const&)> f) { return lhs *= f; }
0182
0183 template<class T>
0184 Set<T> operator * (std::vector<double> const& v, Set<T> rhs) { return rhs *= v; }
0185
0186 template<class T>
0187 Set<T> operator * (Set<T> lhs, std::vector<double> const& v) { return lhs *= v; }
0188
0189 template<class T>
0190 Set<T> operator * (std::map<int, double> const& v, Set<T> rhs) { return rhs *= v; }
0191
0192 template<class T>
0193 Set<T> operator * (Set<T> lhs, std::map<int, double> const& v) { return lhs *= v; }
0194
0195 template<class T>
0196 Set<T> operator / (Set<T> lhs, double const& s) { return lhs /= s; }
0197
0198 template<class T>
0199 Set<T> operator * (Set<T> lhs, Set<T> const& rhs) { return lhs *= rhs; }
0200
0201 template<class T>
0202 Set<T> operator + (Set<T> lhs, Set<T> const& rhs) { return lhs += rhs; }
0203
0204 template<class T>
0205 Set<T> operator - (Set<T> lhs, Set<T> const& rhs) { return lhs -= rhs; }
0206
0207 }