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()
160 template <
class RhsValueType>
161 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
168 template <
class RhsValueType>
169 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
172 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
173 " with 8 derivatives");
180 template <
class RhsValueType>
191 template <
class RhsValueType>
192 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
195 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
196 " with 8 derivatives");
202 template <
class RhsValueType>
203 static Evaluation createConstant(
const RhsValueType& value)
210 template <
class RhsValueType>
219 assert(
size() == other.size());
221 data_[1] = other.data_[1];
222 data_[2] = other.data_[2];
223 data_[3] = other.data_[3];
224 data_[4] = other.data_[4];
225 data_[5] = other.data_[5];
226 data_[6] = other.data_[6];
227 data_[7] = other.data_[7];
228 data_[8] = other.data_[8];
235 assert(
size() == other.size());
237 data_[0] += other.data_[0];
238 data_[1] += other.data_[1];
239 data_[2] += other.data_[2];
240 data_[3] += other.data_[3];
241 data_[4] += other.data_[4];
242 data_[5] += other.data_[5];
243 data_[6] += other.data_[6];
244 data_[7] += other.data_[7];
245 data_[8] += other.data_[8];
251 template <
class RhsValueType>
252 Evaluation& operator+=(
const RhsValueType& other)
263 assert(
size() == other.size());
265 data_[0] -= other.data_[0];
266 data_[1] -= other.data_[1];
267 data_[2] -= other.data_[2];
268 data_[3] -= other.data_[3];
269 data_[4] -= other.data_[4];
270 data_[5] -= other.data_[5];
271 data_[6] -= other.data_[6];
272 data_[7] -= other.data_[7];
273 data_[8] -= other.data_[8];
279 template <
class RhsValueType>
280 Evaluation& operator-=(
const RhsValueType& other)
291 assert(
size() == other.size());
302 data_[1] = data_[1] * v + other.data_[1] * u;
303 data_[2] = data_[2] * v + other.data_[2] * u;
304 data_[3] = data_[3] * v + other.data_[3] * u;
305 data_[4] = data_[4] * v + other.data_[4] * u;
306 data_[5] = data_[5] * v + other.data_[5] * u;
307 data_[6] = data_[6] * v + other.data_[6] * u;
308 data_[7] = data_[7] * v + other.data_[7] * u;
309 data_[8] = data_[8] * v + other.data_[8] * u;
315 template <
class RhsValueType>
316 Evaluation& operator*=(
const RhsValueType& other)
334 assert(
size() == other.size());
340 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
341 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
342 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
343 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
344 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
345 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
346 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
347 data_[8] = (v*data_[8] - u*other.data_[8])/(v*v);
354 template <
class RhsValueType>
355 Evaluation& operator/=(
const RhsValueType& other)
375 assert(
size() == other.size());
385 template <
class RhsValueType>
386 Evaluation operator+(
const RhsValueType& other)
const
398 assert(
size() == other.size());
408 template <
class RhsValueType>
409 Evaluation operator-(
const RhsValueType& other)
const
424 result.data_[0] = - data_[0];
425 result.data_[1] = - data_[1];
426 result.data_[2] = - data_[2];
427 result.data_[3] = - data_[3];
428 result.data_[4] = - data_[4];
429 result.data_[5] = - data_[5];
430 result.data_[6] = - data_[6];
431 result.data_[7] = - data_[7];
432 result.data_[8] = - data_[8];
439 assert(
size() == other.size());
448 template <
class RhsValueType>
449 Evaluation operator*(
const RhsValueType& other)
const
460 assert(
size() == other.size());
469 template <
class RhsValueType>
470 Evaluation operator/(
const RhsValueType& other)
const
479 template <
class RhsValueType>
480 Evaluation& operator=(
const RhsValueType& other)
491 template <
class RhsValueType>
492 bool operator==(
const RhsValueType& other)
const
493 {
return value() == other; }
495 bool operator==(
const Evaluation& other)
const
497 assert(
size() == other.size());
499 for (
int idx = 0; idx <
length_(); ++idx) {
500 if (data_[idx] != other.data_[idx]) {
507 bool operator!=(
const Evaluation& other)
const
508 {
return !operator==(other); }
510 template <
class RhsValueType>
511 bool operator!=(
const RhsValueType& other)
const
512 {
return !operator==(other); }
514 template <
class RhsValueType>
515 bool operator>(RhsValueType other)
const
516 {
return value() > other; }
520 assert(
size() == other.size());
522 return value() > other.value();
525 template <
class RhsValueType>
526 bool operator<(RhsValueType other)
const
527 {
return value() < other; }
531 assert(
size() == other.size());
533 return value() < other.value();
536 template <
class RhsValueType>
537 bool operator>=(RhsValueType other)
const
538 {
return value() >= other; }
540 bool operator>=(
const Evaluation& other)
const
542 assert(
size() == other.size());
544 return value() >= other.value();
547 template <
class RhsValueType>
548 bool operator<=(RhsValueType other)
const
549 {
return value() <= other; }
551 bool operator<=(
const Evaluation& other)
const
553 assert(
size() == other.size());
555 return value() <= other.value();
563 template <
class RhsValueType>
564 void setValue(
const RhsValueType& val)
568 const ValueType& derivative(
int varIdx)
const
570 assert(0 <= varIdx && varIdx <
size());
572 return data_[
dstart_() + varIdx];
576 void setDerivative(
int varIdx,
const ValueType& derVal)
578 assert(0 <= varIdx && varIdx <
size());
580 data_[
dstart_() + varIdx] = derVal;
583 template<
class Serializer>
584 void serializeOp(Serializer& serializer)
590 std::array<ValueT, 9> data_;