64 {
return size() + 1; }
82 for (
const auto& v: data_)
83 Valgrind::CheckDefined(v);
100 template <
class RhsValueType>
113 template <
class RhsValueType>
117 assert(0 <= varPos && varPos <
size());
122 data_[varPos +
dstart_()] = 1.0;
128 void clearDerivatives()
159 template <
class RhsValueType>
160 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
167 template <
class RhsValueType>
168 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
171 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
172 " with 7 derivatives");
179 template <
class RhsValueType>
190 template <
class RhsValueType>
191 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
194 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
195 " with 7 derivatives");
201 template <
class RhsValueType>
202 static Evaluation createConstant(
const RhsValueType& value)
209 template <
class RhsValueType>
218 assert(
size() == other.size());
220 data_[1] = other.data_[1];
221 data_[2] = other.data_[2];
222 data_[3] = other.data_[3];
223 data_[4] = other.data_[4];
224 data_[5] = other.data_[5];
225 data_[6] = other.data_[6];
226 data_[7] = other.data_[7];
233 assert(
size() == other.size());
235 data_[0] += other.data_[0];
236 data_[1] += other.data_[1];
237 data_[2] += other.data_[2];
238 data_[3] += other.data_[3];
239 data_[4] += other.data_[4];
240 data_[5] += other.data_[5];
241 data_[6] += other.data_[6];
242 data_[7] += other.data_[7];
248 template <
class RhsValueType>
249 Evaluation& operator+=(
const RhsValueType& other)
260 assert(
size() == other.size());
262 data_[0] -= other.data_[0];
263 data_[1] -= other.data_[1];
264 data_[2] -= other.data_[2];
265 data_[3] -= other.data_[3];
266 data_[4] -= other.data_[4];
267 data_[5] -= other.data_[5];
268 data_[6] -= other.data_[6];
269 data_[7] -= other.data_[7];
275 template <
class RhsValueType>
276 Evaluation& operator-=(
const RhsValueType& other)
287 assert(
size() == other.size());
298 data_[1] = data_[1] * v + other.data_[1] * u;
299 data_[2] = data_[2] * v + other.data_[2] * u;
300 data_[3] = data_[3] * v + other.data_[3] * u;
301 data_[4] = data_[4] * v + other.data_[4] * u;
302 data_[5] = data_[5] * v + other.data_[5] * u;
303 data_[6] = data_[6] * v + other.data_[6] * u;
304 data_[7] = data_[7] * v + other.data_[7] * u;
310 template <
class RhsValueType>
311 Evaluation& operator*=(
const RhsValueType& other)
328 assert(
size() == other.size());
334 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
335 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
336 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
337 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
338 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
339 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
340 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
347 template <
class RhsValueType>
348 Evaluation& operator/=(
const RhsValueType& other)
367 assert(
size() == other.size());
377 template <
class RhsValueType>
378 Evaluation operator+(
const RhsValueType& other)
const
390 assert(
size() == other.size());
400 template <
class RhsValueType>
401 Evaluation operator-(
const RhsValueType& other)
const
416 result.data_[0] = - data_[0];
417 result.data_[1] = - data_[1];
418 result.data_[2] = - data_[2];
419 result.data_[3] = - data_[3];
420 result.data_[4] = - data_[4];
421 result.data_[5] = - data_[5];
422 result.data_[6] = - data_[6];
423 result.data_[7] = - data_[7];
430 assert(
size() == other.size());
439 template <
class RhsValueType>
440 Evaluation operator*(
const RhsValueType& other)
const
451 assert(
size() == other.size());
460 template <
class RhsValueType>
461 Evaluation operator/(
const RhsValueType& other)
const
470 template <
class RhsValueType>
471 Evaluation& operator=(
const RhsValueType& other)
482 template <
class RhsValueType>
483 bool operator==(
const RhsValueType& other)
const
484 {
return value() == other; }
486 bool operator==(
const Evaluation& other)
const
488 assert(
size() == other.size());
490 for (
int idx = 0; idx <
length_(); ++idx) {
491 if (data_[idx] != other.data_[idx]) {
498 bool operator!=(
const Evaluation& other)
const
499 {
return !operator==(other); }
501 template <
class RhsValueType>
502 bool operator!=(
const RhsValueType& other)
const
503 {
return !operator==(other); }
505 template <
class RhsValueType>
506 bool operator>(RhsValueType other)
const
507 {
return value() > other; }
511 assert(
size() == other.size());
513 return value() > other.value();
516 template <
class RhsValueType>
517 bool operator<(RhsValueType other)
const
518 {
return value() < other; }
522 assert(
size() == other.size());
524 return value() < other.value();
527 template <
class RhsValueType>
528 bool operator>=(RhsValueType other)
const
529 {
return value() >= other; }
531 bool operator>=(
const Evaluation& other)
const
533 assert(
size() == other.size());
535 return value() >= other.value();
538 template <
class RhsValueType>
539 bool operator<=(RhsValueType other)
const
540 {
return value() <= other; }
542 bool operator<=(
const Evaluation& other)
const
544 assert(
size() == other.size());
546 return value() <= other.value();
554 template <
class RhsValueType>
555 void setValue(
const RhsValueType& val)
559 const ValueType& derivative(
int varIdx)
const
561 assert(0 <= varIdx && varIdx <
size());
563 return data_[
dstart_() + varIdx];
567 void setDerivative(
int varIdx,
const ValueType& derVal)
569 assert(0 <= varIdx && varIdx <
size());
571 data_[
dstart_() + varIdx] = derVal;
574 template<
class Serializer>
575 void serializeOp(Serializer& serializer)
581 std::array<ValueT, 8> data_;