@@ -45,75 +45,20 @@ class Function : public FunctionBase<TScalar, TDim, TDifferentiability> {
4545 using state_t = State<Function<TScalar, TDim, TDifferentiability>>;
4646};
4747
48- template <class TScalar , int TDim>
49- struct State <FunctionBase<TScalar, TDim, Differentiability::None>> {
50- using base_t = FunctionBase<TScalar, TDim, Differentiability::None>;
51- using state_t = State<base_t >;
52-
53- typename base_t ::scalar_t value = 0 ;
54- typename base_t ::vector_t x;
55-
56- State () = default ;
57-
58- State (const state_t &rhs) : value(rhs.value), x(rhs.x.eval()) {}
59-
60- state_t &operator =(const state_t &rhs) {
61- if (this != &rhs) {
62- value = rhs.value ;
63- x = rhs.x .eval ();
64- }
65- return *this ;
66- }
67- };
68-
69- template <class TScalar , int TDim>
70- struct State <FunctionBase<TScalar, TDim, Differentiability::First>> {
71- using base_t = FunctionBase<TScalar, TDim, Differentiability::First>;
72- using state_t = State<base_t >;
73-
74- typename base_t ::scalar_t value = 0 ;
75- typename base_t ::vector_t x;
76- typename base_t ::vector_t gradient;
77-
78- State () = default ;
79-
80- State (const state_t &rhs)
81- : value(rhs.value), x(rhs.x.eval()), gradient(rhs.gradient.eval()) {}
82-
83- state_t &operator =(const state_t &rhs) {
84- if (this != &rhs) {
85- value = rhs.value ;
86- x = rhs.x .eval ();
87- gradient = rhs.gradient .eval ();
88- }
89- return *this ;
90- }
91- };
92-
93- template <class TScalar , int TDim>
94- struct State <FunctionBase<TScalar, TDim, Differentiability::Second>> {
95- using base_t = FunctionBase<TScalar, TDim, Differentiability::Second>;
48+ template <class TScalar , int TDim, Differentiability TDifferentiability>
49+ struct State <FunctionBase<TScalar, TDim, TDifferentiability>> {
50+ using base_t = FunctionBase<TScalar, TDim, TDifferentiability>;
9651 using state_t = State<base_t >;
9752
98- typename base_t ::scalar_t value = 0 ;
9953 typename base_t ::vector_t x;
100- typename base_t ::vector_t gradient;
101- typename base_t ::matrix_t hessian;
10254
10355 State () = default ;
10456
105- State (const state_t &rhs)
106- : value(rhs.value),
107- x (rhs.x.eval()),
108- gradient(rhs.gradient.eval()),
109- hessian(rhs.hessian.eval()) {}
57+ State (const state_t &rhs) : x(rhs.x.eval()) {}
11058
11159 state_t &operator =(const state_t &rhs) {
11260 if (this != &rhs) {
113- value = rhs.value ;
11461 x = rhs.x .eval ();
115- gradient = rhs.gradient .eval ();
116- hessian = rhs.hessian .eval ();
11762 }
11863 return *this ;
11964 }
@@ -141,7 +86,6 @@ class Function<TScalar, TDim, Differentiability::None>
14186 state_t GetState (const typename base_t ::vector_t &x) const {
14287 state_t state;
14388 state.x = x;
144- state.value = this ->operator ()(x);
14589 return state;
14690 }
14791};
@@ -168,7 +112,6 @@ class Function<TScalar, TDim, Differentiability::First>
168112 state_t GetState (const typename base_t ::vector_t &x) const {
169113 state_t state;
170114 state.x = x;
171- state.value = this ->operator ()(x, &state.gradient );
172115 return state;
173116 }
174117};
@@ -196,7 +139,6 @@ class Function<TScalar, TDim, Differentiability::Second>
196139 state_t GetState (const typename base_t ::vector_t &x) const {
197140 state_t state;
198141 state.x = x;
199- state.value = this ->operator ()(x, &state.gradient , &state.hessian );
200142 return state;
201143 }
202144};
0 commit comments