File indexing completed on 2026-06-02 08:17:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef LIBOME_RPD_DISTRIBUTION_H
0013 #define LIBOME_RPD_DISTRIBUTION_H
0014
0015 #include <optional>
0016
0017 namespace apfel
0018 {
0019 namespace ome
0020 {
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 template<typename Tfuncreg,
0042 typename Tfuncplus,
0043 typename Tfuncdelta>
0044 class rpd_distribution
0045 {
0046 public:
0047
0048 using element_regular_type = Tfuncreg;
0049
0050 using element_plus_type = Tfuncplus;
0051
0052 using element_delta_type = Tfuncdelta;
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 rpd_distribution()
0063 : regular_(std::nullopt), plus_(std::nullopt), delta_(std::nullopt) {};
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 rpd_distribution(
0077 std::optional<element_regular_type> regular,
0078 std::optional<element_plus_type> plus,
0079 std::optional<element_delta_type> delta
0080 )
0081 : regular_(regular), plus_(plus), delta_(delta) {};
0082
0083
0084
0085
0086
0087
0088 bool has_regular() const
0089 {
0090 return(regular_.has_value());
0091 }
0092
0093
0094
0095
0096
0097
0098 bool has_plus() const
0099 {
0100 return(plus_.has_value());
0101 }
0102
0103
0104
0105
0106
0107
0108 bool has_delta() const
0109 {
0110 return(delta_.has_value());
0111 }
0112
0113
0114
0115
0116
0117
0118
0119
0120 const std::optional<element_regular_type>& get_regular() const
0121 {
0122 return(regular_);
0123 };
0124
0125
0126
0127
0128
0129
0130
0131
0132 const std::optional<element_plus_type>& get_plus() const
0133 {
0134 return(plus_);
0135 };
0136
0137
0138
0139
0140
0141
0142
0143
0144 const std::optional<element_delta_type>& get_delta() const
0145 {
0146 return(delta_);
0147 };
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 auto get_coefficient(int n) const
0166 {
0167 using reg_type
0168 = std::conditional_t<element_regular_type::coefficient_has_view::value,
0169 typename element_regular_type::coefficient_view_type,
0170 typename element_regular_type::coefficient_type>;
0171 using plus_type
0172 = std::conditional_t<element_plus_type::coefficient_has_view::value,
0173 typename element_plus_type::coefficient_view_type,
0174 typename element_plus_type::coefficient_type>;
0175 using delta_type
0176 = std::conditional_t<element_delta_type::coefficient_has_view::value,
0177 typename element_delta_type::coefficient_view_type,
0178 typename element_delta_type::coefficient_type>;
0179 std::optional<reg_type> reg;
0180 std::optional<plus_type> plus;
0181 std::optional<delta_type> delta;
0182
0183 if(has_regular())
0184 {
0185 if constexpr (element_regular_type::coefficient_has_view::value)
0186 reg = std::make_optional((*regular_)[n].get_view());
0187 else
0188 reg = std::make_optional((*regular_)[n]);
0189 }
0190 if(has_plus())
0191 {
0192 if constexpr (element_plus_type::coefficient_has_view::value)
0193 plus = std::make_optional((*plus_)[n].get_view());
0194 else
0195 plus = std::make_optional((*plus_)[n]);
0196 }
0197 if(has_delta())
0198 {
0199 if constexpr (element_delta_type::coefficient_has_view::value)
0200 delta = std::make_optional((*delta_)[n].get_view());
0201 else
0202 delta = std::make_optional((*delta_)[n]);
0203 }
0204
0205 return(
0206 rpd_distribution<reg_type, plus_type, delta_type> {reg, plus, delta}
0207 );
0208 };
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219 auto truncate(int n) const
0220 {
0221 using reg_type = decltype(std::declval<element_regular_type>().truncate(n));
0222 using plus_type = decltype(std::declval<element_plus_type>().truncate(n));
0223 using delta_type = decltype(std::declval<element_delta_type>().truncate(n));
0224
0225 std::optional<reg_type> reg;
0226 std::optional<plus_type> plus;
0227 std::optional<delta_type> delta;
0228
0229 if(has_regular())
0230 {
0231 reg = std::make_optional(regular_->truncate(n));
0232 }
0233 if(has_plus())
0234 {
0235 plus = std::make_optional(plus_->truncate(n));
0236 }
0237 if(has_delta())
0238 {
0239 delta = std::make_optional(delta_->truncate(n));
0240 }
0241
0242 return(
0243 rpd_distribution<reg_type, plus_type, delta_type> {reg, plus, delta}
0244 );
0245 };
0246
0247 private:
0248 std::optional<element_regular_type> regular_;
0249 std::optional<element_plus_type> plus_;
0250 std::optional<element_delta_type> delta_;
0251 };
0252
0253 }
0254 }
0255
0256 #endif