@@ -48,44 +48,29 @@ namespace QuantLib {
48
48
const Size i_;
49
49
};
50
50
51
- // 1d implementation (arithmetic types)
52
- template <class xContainer , bool >
51
+ template <class xContainer >
53
52
class LinearFcts {
54
53
public:
55
54
typedef typename xContainer::value_type ArgumentType;
56
- LinearFcts (const xContainer &x, Real intercept) {
55
+ LinearFcts (const xContainer &x, Real intercept) {
57
56
if (intercept != 0.0 )
58
- v.push_back ([=](ArgumentType x){ return intercept; });
59
- v.push_back ([](ArgumentType x){ return x; });
57
+ v.push_back ([=](ArgumentType){ return intercept; });
58
+ if constexpr (std::is_arithmetic_v<ArgumentType>) {
59
+ v.push_back ([](ArgumentType x){ return x; });
60
+ } else {
61
+ Size m = x.begin ()->size ();
62
+ for (Size i = 0 ; i < m; ++i)
63
+ v.push_back (LinearFct<ArgumentType>(i));
64
+ }
60
65
}
61
66
62
67
const std::vector< std::function<Real(ArgumentType)> > & fcts () {
63
68
return v;
64
69
}
65
-
66
70
private:
67
71
std::vector< std::function<Real(ArgumentType)> > v;
68
72
};
69
73
70
- // multi-dimensional implementation (container types)
71
- template <class xContainer >
72
- class LinearFcts <xContainer, false > {
73
- public:
74
- typedef typename xContainer::value_type ArgumentType;
75
- LinearFcts (const xContainer &x, Real intercept) {
76
- if (intercept != 0.0 )
77
- v.push_back ([=](ArgumentType x){ return intercept; });
78
- Size m = x.begin ()->size ();
79
- for (Size i = 0 ; i < m; ++i)
80
- v.push_back (LinearFct<ArgumentType>(i));
81
- }
82
-
83
- const std::vector< std::function<Real(ArgumentType)> > & fcts () {
84
- return v;
85
- }
86
- private:
87
- std::vector< std::function<Real(ArgumentType)> > v;
88
- };
89
74
}
90
75
91
76
class LinearRegression : public GeneralLinearLeastSquares {
@@ -105,9 +90,7 @@ namespace QuantLib {
105
90
LinearRegression::LinearRegression (const xContainer& x,
106
91
const yContainer& y, Real intercept)
107
92
: GeneralLinearLeastSquares(x, y,
108
- details::LinearFcts<xContainer,
109
- std::is_arithmetic<typename xContainer::value_type>::value>
110
- (x, intercept).fcts()) {
93
+ details::LinearFcts<xContainer>(x, intercept).fcts()) {
111
94
}
112
95
113
96
template <class xContainer , class yContainer , class vContainer > inline
0 commit comments