[cleanup] newly created Evaluation files, now with {} in for loops to
make it through the review process.
This commit is contained in:
@@ -59,17 +59,14 @@ namespace DenseAd {
|
||||
*/
|
||||
template <class ValueT, int numDerivs>
|
||||
class Evaluation
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = numDerivs;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -82,18 +79,15 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
: data_(other.data_)
|
||||
{ }
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -124,11 +118,10 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
for (int i = dstart_; i < dend_; ++i)
|
||||
{
|
||||
for (int i = dstart_; i < dend_; ++i) {
|
||||
data_[i] = 0.0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -154,28 +147,27 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
for (int i = dstart_; i < dend_; ++i)
|
||||
{
|
||||
for (int i = dstart_; i < dend_; ++i) {
|
||||
data_[i] = other.data_[i];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
for (int i = 0; i < length_; ++i)
|
||||
{
|
||||
for (int i = 0; i < length_; ++i) {
|
||||
data_[i] += other.data_[i];
|
||||
|
||||
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -190,11 +182,11 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
for (int i = 0; i < length_; ++i)
|
||||
{
|
||||
for (int i = 0; i < length_; ++i) {
|
||||
data_[i] -= other.data_[i];
|
||||
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -213,17 +205,16 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
for (int i = dstart_; i < dend_; ++i)
|
||||
this->data_[i] = this->data_[i]*v + other.data_[i] * u;
|
||||
|
||||
for (int i = dstart_; i < dend_; ++i) {
|
||||
data_[i] = data_[i] * v + other.data_[i] * u;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -231,12 +222,11 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
for (int i = 0; i < length_; ++i)
|
||||
{
|
||||
for (int i = 0; i < length_; ++i) {
|
||||
data_[i] *= other;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -244,18 +234,17 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
for (int i = dstart_; i < dend_; ++i)
|
||||
data_[i] = data_[i]*v_vv - other.data_[i]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
for (int i = dstart_; i < dend_; ++i) {
|
||||
data_[i] = data_[i] * v_vv - other.data_[i] * u_vv;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -263,12 +252,12 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
for (int i = 0; i < length_; ++i)
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
for (int i = 0; i < length_; ++i) {
|
||||
data_[i] *= tmp;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -277,14 +266,14 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
for (int i = dstart_; i < dend_; ++i)
|
||||
result.data_[i] = df_dg*b.data_[i];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
for (int i = dstart_; i < dend_; ++i) {
|
||||
result.data_[i] = df_dg * b.data_[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -324,12 +313,11 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
for (int i = 0; i < length_; ++i)
|
||||
// set value and derivatives to negative
|
||||
for (int i = 0; i < length_; ++i) {
|
||||
result.data_[i] = - data_[i];
|
||||
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -373,12 +361,11 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
for (int i = 0; i < length_; ++i)
|
||||
{
|
||||
for (int i = 0; i < length_; ++i) {
|
||||
data_[i] = other.data_[i];
|
||||
|
||||
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -388,10 +375,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 1>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 1;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,21 +74,17 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -122,11 +115,8 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -152,29 +142,24 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -189,12 +174,10 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -213,17 +196,14 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -231,13 +211,10 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -245,18 +222,15 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -264,13 +238,11 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -279,14 +251,12 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -326,13 +296,10 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -376,13 +343,10 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -392,10 +356,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 10>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 10;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,16 +74,13 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -100,7 +94,6 @@ public:
|
||||
data_[10] = other.data_[10];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -131,9 +124,7 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
data_[3] = 0.0;
|
||||
@@ -144,7 +135,6 @@ public:
|
||||
data_[8] = 0.0;
|
||||
data_[9] = 0.0;
|
||||
data_[10] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -170,15 +160,14 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
@@ -189,15 +178,12 @@ public:
|
||||
data_[8] = other.data_[8];
|
||||
data_[9] = other.data_[9];
|
||||
data_[10] = other.data_[10];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
@@ -209,8 +195,7 @@ public:
|
||||
data_[8] += other.data_[8];
|
||||
data_[9] += other.data_[9];
|
||||
data_[10] += other.data_[10];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -225,9 +210,7 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
@@ -239,7 +222,7 @@ public:
|
||||
data_[8] -= other.data_[8];
|
||||
data_[9] -= other.data_[9];
|
||||
data_[10] -= other.data_[10];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -258,26 +241,23 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
this->data_[3] = this->data_[3]*v + other.data_[3] * u;
|
||||
this->data_[4] = this->data_[4]*v + other.data_[4] * u;
|
||||
this->data_[5] = this->data_[5]*v + other.data_[5] * u;
|
||||
this->data_[6] = this->data_[6]*v + other.data_[6] * u;
|
||||
this->data_[7] = this->data_[7]*v + other.data_[7] * u;
|
||||
this->data_[8] = this->data_[8]*v + other.data_[8] * u;
|
||||
this->data_[9] = this->data_[9]*v + other.data_[9] * u;
|
||||
this->data_[10] = this->data_[10]*v + other.data_[10] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
data_[3] = data_[3] * v + other.data_[3] * u;
|
||||
data_[4] = data_[4] * v + other.data_[4] * u;
|
||||
data_[5] = data_[5] * v + other.data_[5] * u;
|
||||
data_[6] = data_[6] * v + other.data_[6] * u;
|
||||
data_[7] = data_[7] * v + other.data_[7] * u;
|
||||
data_[8] = data_[8] * v + other.data_[8] * u;
|
||||
data_[9] = data_[9] * v + other.data_[9] * u;
|
||||
data_[10] = data_[10] * v + other.data_[10] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -285,9 +265,7 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
@@ -299,8 +277,7 @@ public:
|
||||
data_[8] *= other;
|
||||
data_[9] *= other;
|
||||
data_[10] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -308,27 +285,24 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
data_[3] = data_[3]*v_vv - other.data_[3]*u_vv;
|
||||
data_[4] = data_[4]*v_vv - other.data_[4]*u_vv;
|
||||
data_[5] = data_[5]*v_vv - other.data_[5]*u_vv;
|
||||
data_[6] = data_[6]*v_vv - other.data_[6]*u_vv;
|
||||
data_[7] = data_[7]*v_vv - other.data_[7]*u_vv;
|
||||
data_[8] = data_[8]*v_vv - other.data_[8]*u_vv;
|
||||
data_[9] = data_[9]*v_vv - other.data_[9]*u_vv;
|
||||
data_[10] = data_[10]*v_vv - other.data_[10]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
data_[3] = data_[3] * v_vv - other.data_[3] * u_vv;
|
||||
data_[4] = data_[4] * v_vv - other.data_[4] * u_vv;
|
||||
data_[5] = data_[5] * v_vv - other.data_[5] * u_vv;
|
||||
data_[6] = data_[6] * v_vv - other.data_[6] * u_vv;
|
||||
data_[7] = data_[7] * v_vv - other.data_[7] * u_vv;
|
||||
data_[8] = data_[8] * v_vv - other.data_[8] * u_vv;
|
||||
data_[9] = data_[9] * v_vv - other.data_[9] * u_vv;
|
||||
data_[10] = data_[10] * v_vv - other.data_[10] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -336,9 +310,8 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
@@ -350,8 +323,7 @@ public:
|
||||
data_[8] *= tmp;
|
||||
data_[9] *= tmp;
|
||||
data_[10] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -360,23 +332,21 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
result.data_[3] = df_dg*b.data_[3];
|
||||
result.data_[4] = df_dg*b.data_[4];
|
||||
result.data_[5] = df_dg*b.data_[5];
|
||||
result.data_[6] = df_dg*b.data_[6];
|
||||
result.data_[7] = df_dg*b.data_[7];
|
||||
result.data_[8] = df_dg*b.data_[8];
|
||||
result.data_[9] = df_dg*b.data_[9];
|
||||
result.data_[10] = df_dg*b.data_[10];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
result.data_[3] = df_dg * b.data_[3];
|
||||
result.data_[4] = df_dg * b.data_[4];
|
||||
result.data_[5] = df_dg * b.data_[5];
|
||||
result.data_[6] = df_dg * b.data_[6];
|
||||
result.data_[7] = df_dg * b.data_[7];
|
||||
result.data_[8] = df_dg * b.data_[8];
|
||||
result.data_[9] = df_dg * b.data_[9];
|
||||
result.data_[10] = df_dg * b.data_[10];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -416,9 +386,7 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
@@ -430,8 +398,7 @@ public:
|
||||
result.data_[8] = - data_[8];
|
||||
result.data_[9] = - data_[9];
|
||||
result.data_[10] = - data_[10];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -475,9 +442,7 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -489,8 +454,7 @@ public:
|
||||
data_[8] = other.data_[8];
|
||||
data_[9] = other.data_[9];
|
||||
data_[10] = other.data_[10];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -500,10 +464,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 11>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 11;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,16 +74,13 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -101,7 +95,6 @@ public:
|
||||
data_[11] = other.data_[11];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -132,9 +125,7 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
data_[3] = 0.0;
|
||||
@@ -146,7 +137,6 @@ public:
|
||||
data_[9] = 0.0;
|
||||
data_[10] = 0.0;
|
||||
data_[11] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -172,15 +162,14 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
@@ -192,15 +181,12 @@ public:
|
||||
data_[9] = other.data_[9];
|
||||
data_[10] = other.data_[10];
|
||||
data_[11] = other.data_[11];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
@@ -213,8 +199,7 @@ public:
|
||||
data_[9] += other.data_[9];
|
||||
data_[10] += other.data_[10];
|
||||
data_[11] += other.data_[11];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -229,9 +214,7 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
@@ -244,7 +227,7 @@ public:
|
||||
data_[9] -= other.data_[9];
|
||||
data_[10] -= other.data_[10];
|
||||
data_[11] -= other.data_[11];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -263,27 +246,24 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
this->data_[3] = this->data_[3]*v + other.data_[3] * u;
|
||||
this->data_[4] = this->data_[4]*v + other.data_[4] * u;
|
||||
this->data_[5] = this->data_[5]*v + other.data_[5] * u;
|
||||
this->data_[6] = this->data_[6]*v + other.data_[6] * u;
|
||||
this->data_[7] = this->data_[7]*v + other.data_[7] * u;
|
||||
this->data_[8] = this->data_[8]*v + other.data_[8] * u;
|
||||
this->data_[9] = this->data_[9]*v + other.data_[9] * u;
|
||||
this->data_[10] = this->data_[10]*v + other.data_[10] * u;
|
||||
this->data_[11] = this->data_[11]*v + other.data_[11] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
data_[3] = data_[3] * v + other.data_[3] * u;
|
||||
data_[4] = data_[4] * v + other.data_[4] * u;
|
||||
data_[5] = data_[5] * v + other.data_[5] * u;
|
||||
data_[6] = data_[6] * v + other.data_[6] * u;
|
||||
data_[7] = data_[7] * v + other.data_[7] * u;
|
||||
data_[8] = data_[8] * v + other.data_[8] * u;
|
||||
data_[9] = data_[9] * v + other.data_[9] * u;
|
||||
data_[10] = data_[10] * v + other.data_[10] * u;
|
||||
data_[11] = data_[11] * v + other.data_[11] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -291,9 +271,7 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
@@ -306,8 +284,7 @@ public:
|
||||
data_[9] *= other;
|
||||
data_[10] *= other;
|
||||
data_[11] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -315,28 +292,25 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
data_[3] = data_[3]*v_vv - other.data_[3]*u_vv;
|
||||
data_[4] = data_[4]*v_vv - other.data_[4]*u_vv;
|
||||
data_[5] = data_[5]*v_vv - other.data_[5]*u_vv;
|
||||
data_[6] = data_[6]*v_vv - other.data_[6]*u_vv;
|
||||
data_[7] = data_[7]*v_vv - other.data_[7]*u_vv;
|
||||
data_[8] = data_[8]*v_vv - other.data_[8]*u_vv;
|
||||
data_[9] = data_[9]*v_vv - other.data_[9]*u_vv;
|
||||
data_[10] = data_[10]*v_vv - other.data_[10]*u_vv;
|
||||
data_[11] = data_[11]*v_vv - other.data_[11]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
data_[3] = data_[3] * v_vv - other.data_[3] * u_vv;
|
||||
data_[4] = data_[4] * v_vv - other.data_[4] * u_vv;
|
||||
data_[5] = data_[5] * v_vv - other.data_[5] * u_vv;
|
||||
data_[6] = data_[6] * v_vv - other.data_[6] * u_vv;
|
||||
data_[7] = data_[7] * v_vv - other.data_[7] * u_vv;
|
||||
data_[8] = data_[8] * v_vv - other.data_[8] * u_vv;
|
||||
data_[9] = data_[9] * v_vv - other.data_[9] * u_vv;
|
||||
data_[10] = data_[10] * v_vv - other.data_[10] * u_vv;
|
||||
data_[11] = data_[11] * v_vv - other.data_[11] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -344,9 +318,8 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
@@ -359,8 +332,7 @@ public:
|
||||
data_[9] *= tmp;
|
||||
data_[10] *= tmp;
|
||||
data_[11] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -369,24 +341,22 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
result.data_[3] = df_dg*b.data_[3];
|
||||
result.data_[4] = df_dg*b.data_[4];
|
||||
result.data_[5] = df_dg*b.data_[5];
|
||||
result.data_[6] = df_dg*b.data_[6];
|
||||
result.data_[7] = df_dg*b.data_[7];
|
||||
result.data_[8] = df_dg*b.data_[8];
|
||||
result.data_[9] = df_dg*b.data_[9];
|
||||
result.data_[10] = df_dg*b.data_[10];
|
||||
result.data_[11] = df_dg*b.data_[11];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
result.data_[3] = df_dg * b.data_[3];
|
||||
result.data_[4] = df_dg * b.data_[4];
|
||||
result.data_[5] = df_dg * b.data_[5];
|
||||
result.data_[6] = df_dg * b.data_[6];
|
||||
result.data_[7] = df_dg * b.data_[7];
|
||||
result.data_[8] = df_dg * b.data_[8];
|
||||
result.data_[9] = df_dg * b.data_[9];
|
||||
result.data_[10] = df_dg * b.data_[10];
|
||||
result.data_[11] = df_dg * b.data_[11];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -426,9 +396,7 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
@@ -441,8 +409,7 @@ public:
|
||||
result.data_[9] = - data_[9];
|
||||
result.data_[10] = - data_[10];
|
||||
result.data_[11] = - data_[11];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -486,9 +453,7 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -501,8 +466,7 @@ public:
|
||||
data_[9] = other.data_[9];
|
||||
data_[10] = other.data_[10];
|
||||
data_[11] = other.data_[11];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -512,10 +476,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 12>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 12;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,16 +74,13 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -102,7 +96,6 @@ public:
|
||||
data_[12] = other.data_[12];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -133,9 +126,7 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
data_[3] = 0.0;
|
||||
@@ -148,7 +139,6 @@ public:
|
||||
data_[10] = 0.0;
|
||||
data_[11] = 0.0;
|
||||
data_[12] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -174,15 +164,14 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
@@ -195,15 +184,12 @@ public:
|
||||
data_[10] = other.data_[10];
|
||||
data_[11] = other.data_[11];
|
||||
data_[12] = other.data_[12];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
@@ -217,8 +203,7 @@ public:
|
||||
data_[10] += other.data_[10];
|
||||
data_[11] += other.data_[11];
|
||||
data_[12] += other.data_[12];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -233,9 +218,7 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
@@ -249,7 +232,7 @@ public:
|
||||
data_[10] -= other.data_[10];
|
||||
data_[11] -= other.data_[11];
|
||||
data_[12] -= other.data_[12];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -268,28 +251,25 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
this->data_[3] = this->data_[3]*v + other.data_[3] * u;
|
||||
this->data_[4] = this->data_[4]*v + other.data_[4] * u;
|
||||
this->data_[5] = this->data_[5]*v + other.data_[5] * u;
|
||||
this->data_[6] = this->data_[6]*v + other.data_[6] * u;
|
||||
this->data_[7] = this->data_[7]*v + other.data_[7] * u;
|
||||
this->data_[8] = this->data_[8]*v + other.data_[8] * u;
|
||||
this->data_[9] = this->data_[9]*v + other.data_[9] * u;
|
||||
this->data_[10] = this->data_[10]*v + other.data_[10] * u;
|
||||
this->data_[11] = this->data_[11]*v + other.data_[11] * u;
|
||||
this->data_[12] = this->data_[12]*v + other.data_[12] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
data_[3] = data_[3] * v + other.data_[3] * u;
|
||||
data_[4] = data_[4] * v + other.data_[4] * u;
|
||||
data_[5] = data_[5] * v + other.data_[5] * u;
|
||||
data_[6] = data_[6] * v + other.data_[6] * u;
|
||||
data_[7] = data_[7] * v + other.data_[7] * u;
|
||||
data_[8] = data_[8] * v + other.data_[8] * u;
|
||||
data_[9] = data_[9] * v + other.data_[9] * u;
|
||||
data_[10] = data_[10] * v + other.data_[10] * u;
|
||||
data_[11] = data_[11] * v + other.data_[11] * u;
|
||||
data_[12] = data_[12] * v + other.data_[12] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -297,9 +277,7 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
@@ -313,8 +291,7 @@ public:
|
||||
data_[10] *= other;
|
||||
data_[11] *= other;
|
||||
data_[12] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -322,29 +299,26 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
data_[3] = data_[3]*v_vv - other.data_[3]*u_vv;
|
||||
data_[4] = data_[4]*v_vv - other.data_[4]*u_vv;
|
||||
data_[5] = data_[5]*v_vv - other.data_[5]*u_vv;
|
||||
data_[6] = data_[6]*v_vv - other.data_[6]*u_vv;
|
||||
data_[7] = data_[7]*v_vv - other.data_[7]*u_vv;
|
||||
data_[8] = data_[8]*v_vv - other.data_[8]*u_vv;
|
||||
data_[9] = data_[9]*v_vv - other.data_[9]*u_vv;
|
||||
data_[10] = data_[10]*v_vv - other.data_[10]*u_vv;
|
||||
data_[11] = data_[11]*v_vv - other.data_[11]*u_vv;
|
||||
data_[12] = data_[12]*v_vv - other.data_[12]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
data_[3] = data_[3] * v_vv - other.data_[3] * u_vv;
|
||||
data_[4] = data_[4] * v_vv - other.data_[4] * u_vv;
|
||||
data_[5] = data_[5] * v_vv - other.data_[5] * u_vv;
|
||||
data_[6] = data_[6] * v_vv - other.data_[6] * u_vv;
|
||||
data_[7] = data_[7] * v_vv - other.data_[7] * u_vv;
|
||||
data_[8] = data_[8] * v_vv - other.data_[8] * u_vv;
|
||||
data_[9] = data_[9] * v_vv - other.data_[9] * u_vv;
|
||||
data_[10] = data_[10] * v_vv - other.data_[10] * u_vv;
|
||||
data_[11] = data_[11] * v_vv - other.data_[11] * u_vv;
|
||||
data_[12] = data_[12] * v_vv - other.data_[12] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -352,9 +326,8 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
@@ -368,8 +341,7 @@ public:
|
||||
data_[10] *= tmp;
|
||||
data_[11] *= tmp;
|
||||
data_[12] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -378,25 +350,23 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
result.data_[3] = df_dg*b.data_[3];
|
||||
result.data_[4] = df_dg*b.data_[4];
|
||||
result.data_[5] = df_dg*b.data_[5];
|
||||
result.data_[6] = df_dg*b.data_[6];
|
||||
result.data_[7] = df_dg*b.data_[7];
|
||||
result.data_[8] = df_dg*b.data_[8];
|
||||
result.data_[9] = df_dg*b.data_[9];
|
||||
result.data_[10] = df_dg*b.data_[10];
|
||||
result.data_[11] = df_dg*b.data_[11];
|
||||
result.data_[12] = df_dg*b.data_[12];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
result.data_[3] = df_dg * b.data_[3];
|
||||
result.data_[4] = df_dg * b.data_[4];
|
||||
result.data_[5] = df_dg * b.data_[5];
|
||||
result.data_[6] = df_dg * b.data_[6];
|
||||
result.data_[7] = df_dg * b.data_[7];
|
||||
result.data_[8] = df_dg * b.data_[8];
|
||||
result.data_[9] = df_dg * b.data_[9];
|
||||
result.data_[10] = df_dg * b.data_[10];
|
||||
result.data_[11] = df_dg * b.data_[11];
|
||||
result.data_[12] = df_dg * b.data_[12];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -436,9 +406,7 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
@@ -452,8 +420,7 @@ public:
|
||||
result.data_[10] = - data_[10];
|
||||
result.data_[11] = - data_[11];
|
||||
result.data_[12] = - data_[12];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -497,9 +464,7 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -513,8 +478,7 @@ public:
|
||||
data_[10] = other.data_[10];
|
||||
data_[11] = other.data_[11];
|
||||
data_[12] = other.data_[12];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -524,10 +488,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 2>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 2;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,22 +74,18 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -123,12 +116,9 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -154,31 +144,26 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -193,13 +178,11 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -218,18 +201,15 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -237,14 +217,11 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -252,19 +229,16 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -272,14 +246,12 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -288,15 +260,13 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -336,14 +306,11 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -387,14 +354,11 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -404,10 +368,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 3>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 3;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,23 +74,19 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -124,13 +117,10 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
data_[3] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -156,33 +146,28 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
data_[3] += other.data_[3];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -197,14 +182,12 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
data_[3] -= other.data_[3];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -223,19 +206,16 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
this->data_[3] = this->data_[3]*v + other.data_[3] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
data_[3] = data_[3] * v + other.data_[3] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -243,15 +223,12 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
data_[3] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -259,20 +236,17 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
data_[3] = data_[3]*v_vv - other.data_[3]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
data_[3] = data_[3] * v_vv - other.data_[3] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -280,15 +254,13 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
data_[3] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -297,16 +269,14 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
result.data_[3] = df_dg*b.data_[3];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
result.data_[3] = df_dg * b.data_[3];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -346,15 +316,12 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
result.data_[3] = - data_[3];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -398,15 +365,12 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -416,10 +380,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 4>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 4;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,16 +74,13 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -94,7 +88,6 @@ public:
|
||||
data_[4] = other.data_[4];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -125,14 +118,11 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
data_[3] = 0.0;
|
||||
data_[4] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -158,35 +148,30 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
data_[4] = other.data_[4];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
data_[3] += other.data_[3];
|
||||
data_[4] += other.data_[4];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -201,15 +186,13 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
data_[3] -= other.data_[3];
|
||||
data_[4] -= other.data_[4];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -228,20 +211,17 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
this->data_[3] = this->data_[3]*v + other.data_[3] * u;
|
||||
this->data_[4] = this->data_[4]*v + other.data_[4] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
data_[3] = data_[3] * v + other.data_[3] * u;
|
||||
data_[4] = data_[4] * v + other.data_[4] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -249,16 +229,13 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
data_[3] *= other;
|
||||
data_[4] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -266,21 +243,18 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
data_[3] = data_[3]*v_vv - other.data_[3]*u_vv;
|
||||
data_[4] = data_[4]*v_vv - other.data_[4]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
data_[3] = data_[3] * v_vv - other.data_[3] * u_vv;
|
||||
data_[4] = data_[4] * v_vv - other.data_[4] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -288,16 +262,14 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
data_[3] *= tmp;
|
||||
data_[4] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -306,17 +278,15 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
result.data_[3] = df_dg*b.data_[3];
|
||||
result.data_[4] = df_dg*b.data_[4];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
result.data_[3] = df_dg * b.data_[3];
|
||||
result.data_[4] = df_dg * b.data_[4];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -356,16 +326,13 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
result.data_[3] = - data_[3];
|
||||
result.data_[4] = - data_[4];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -409,16 +376,13 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
data_[4] = other.data_[4];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -428,10 +392,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 5>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 5;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,16 +74,13 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -95,7 +89,6 @@ public:
|
||||
data_[5] = other.data_[5];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -126,15 +119,12 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
data_[3] = 0.0;
|
||||
data_[4] = 0.0;
|
||||
data_[5] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -160,37 +150,32 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
data_[4] = other.data_[4];
|
||||
data_[5] = other.data_[5];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
data_[3] += other.data_[3];
|
||||
data_[4] += other.data_[4];
|
||||
data_[5] += other.data_[5];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -205,16 +190,14 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
data_[3] -= other.data_[3];
|
||||
data_[4] -= other.data_[4];
|
||||
data_[5] -= other.data_[5];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -233,21 +216,18 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
this->data_[3] = this->data_[3]*v + other.data_[3] * u;
|
||||
this->data_[4] = this->data_[4]*v + other.data_[4] * u;
|
||||
this->data_[5] = this->data_[5]*v + other.data_[5] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
data_[3] = data_[3] * v + other.data_[3] * u;
|
||||
data_[4] = data_[4] * v + other.data_[4] * u;
|
||||
data_[5] = data_[5] * v + other.data_[5] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -255,17 +235,14 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
data_[3] *= other;
|
||||
data_[4] *= other;
|
||||
data_[5] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -273,22 +250,19 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
data_[3] = data_[3]*v_vv - other.data_[3]*u_vv;
|
||||
data_[4] = data_[4]*v_vv - other.data_[4]*u_vv;
|
||||
data_[5] = data_[5]*v_vv - other.data_[5]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
data_[3] = data_[3] * v_vv - other.data_[3] * u_vv;
|
||||
data_[4] = data_[4] * v_vv - other.data_[4] * u_vv;
|
||||
data_[5] = data_[5] * v_vv - other.data_[5] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -296,17 +270,15 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
data_[3] *= tmp;
|
||||
data_[4] *= tmp;
|
||||
data_[5] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -315,18 +287,16 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
result.data_[3] = df_dg*b.data_[3];
|
||||
result.data_[4] = df_dg*b.data_[4];
|
||||
result.data_[5] = df_dg*b.data_[5];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
result.data_[3] = df_dg * b.data_[3];
|
||||
result.data_[4] = df_dg * b.data_[4];
|
||||
result.data_[5] = df_dg * b.data_[5];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -366,17 +336,14 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
result.data_[3] = - data_[3];
|
||||
result.data_[4] = - data_[4];
|
||||
result.data_[5] = - data_[5];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -420,17 +387,14 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
data_[4] = other.data_[4];
|
||||
data_[5] = other.data_[5];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -440,10 +404,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 6>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 6;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,16 +74,13 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -96,7 +90,6 @@ public:
|
||||
data_[6] = other.data_[6];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -127,16 +120,13 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
data_[3] = 0.0;
|
||||
data_[4] = 0.0;
|
||||
data_[5] = 0.0;
|
||||
data_[6] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -162,30 +152,26 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
data_[4] = other.data_[4];
|
||||
data_[5] = other.data_[5];
|
||||
data_[6] = other.data_[6];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
@@ -193,8 +179,7 @@ public:
|
||||
data_[4] += other.data_[4];
|
||||
data_[5] += other.data_[5];
|
||||
data_[6] += other.data_[6];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -209,9 +194,7 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
@@ -219,7 +202,7 @@ public:
|
||||
data_[4] -= other.data_[4];
|
||||
data_[5] -= other.data_[5];
|
||||
data_[6] -= other.data_[6];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -238,22 +221,19 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
this->data_[3] = this->data_[3]*v + other.data_[3] * u;
|
||||
this->data_[4] = this->data_[4]*v + other.data_[4] * u;
|
||||
this->data_[5] = this->data_[5]*v + other.data_[5] * u;
|
||||
this->data_[6] = this->data_[6]*v + other.data_[6] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
data_[3] = data_[3] * v + other.data_[3] * u;
|
||||
data_[4] = data_[4] * v + other.data_[4] * u;
|
||||
data_[5] = data_[5] * v + other.data_[5] * u;
|
||||
data_[6] = data_[6] * v + other.data_[6] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -261,9 +241,7 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
@@ -271,8 +249,7 @@ public:
|
||||
data_[4] *= other;
|
||||
data_[5] *= other;
|
||||
data_[6] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -280,23 +257,20 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
data_[3] = data_[3]*v_vv - other.data_[3]*u_vv;
|
||||
data_[4] = data_[4]*v_vv - other.data_[4]*u_vv;
|
||||
data_[5] = data_[5]*v_vv - other.data_[5]*u_vv;
|
||||
data_[6] = data_[6]*v_vv - other.data_[6]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
data_[3] = data_[3] * v_vv - other.data_[3] * u_vv;
|
||||
data_[4] = data_[4] * v_vv - other.data_[4] * u_vv;
|
||||
data_[5] = data_[5] * v_vv - other.data_[5] * u_vv;
|
||||
data_[6] = data_[6] * v_vv - other.data_[6] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -304,9 +278,8 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
@@ -314,8 +287,7 @@ public:
|
||||
data_[4] *= tmp;
|
||||
data_[5] *= tmp;
|
||||
data_[6] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -324,19 +296,17 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
result.data_[3] = df_dg*b.data_[3];
|
||||
result.data_[4] = df_dg*b.data_[4];
|
||||
result.data_[5] = df_dg*b.data_[5];
|
||||
result.data_[6] = df_dg*b.data_[6];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
result.data_[3] = df_dg * b.data_[3];
|
||||
result.data_[4] = df_dg * b.data_[4];
|
||||
result.data_[5] = df_dg * b.data_[5];
|
||||
result.data_[6] = df_dg * b.data_[6];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -376,9 +346,7 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
@@ -386,8 +354,7 @@ public:
|
||||
result.data_[4] = - data_[4];
|
||||
result.data_[5] = - data_[5];
|
||||
result.data_[6] = - data_[6];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -431,9 +398,7 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -441,8 +406,7 @@ public:
|
||||
data_[4] = other.data_[4];
|
||||
data_[5] = other.data_[5];
|
||||
data_[6] = other.data_[6];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -452,10 +416,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 7>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 7;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,16 +74,13 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -97,7 +91,6 @@ public:
|
||||
data_[7] = other.data_[7];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -128,9 +121,7 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
data_[3] = 0.0;
|
||||
@@ -138,7 +129,6 @@ public:
|
||||
data_[5] = 0.0;
|
||||
data_[6] = 0.0;
|
||||
data_[7] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -164,15 +154,14 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
@@ -180,15 +169,12 @@ public:
|
||||
data_[5] = other.data_[5];
|
||||
data_[6] = other.data_[6];
|
||||
data_[7] = other.data_[7];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
@@ -197,8 +183,7 @@ public:
|
||||
data_[5] += other.data_[5];
|
||||
data_[6] += other.data_[6];
|
||||
data_[7] += other.data_[7];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -213,9 +198,7 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
@@ -224,7 +207,7 @@ public:
|
||||
data_[5] -= other.data_[5];
|
||||
data_[6] -= other.data_[6];
|
||||
data_[7] -= other.data_[7];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -243,23 +226,20 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
this->data_[3] = this->data_[3]*v + other.data_[3] * u;
|
||||
this->data_[4] = this->data_[4]*v + other.data_[4] * u;
|
||||
this->data_[5] = this->data_[5]*v + other.data_[5] * u;
|
||||
this->data_[6] = this->data_[6]*v + other.data_[6] * u;
|
||||
this->data_[7] = this->data_[7]*v + other.data_[7] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
data_[3] = data_[3] * v + other.data_[3] * u;
|
||||
data_[4] = data_[4] * v + other.data_[4] * u;
|
||||
data_[5] = data_[5] * v + other.data_[5] * u;
|
||||
data_[6] = data_[6] * v + other.data_[6] * u;
|
||||
data_[7] = data_[7] * v + other.data_[7] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -267,9 +247,7 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
@@ -278,8 +256,7 @@ public:
|
||||
data_[5] *= other;
|
||||
data_[6] *= other;
|
||||
data_[7] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -287,24 +264,21 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
data_[3] = data_[3]*v_vv - other.data_[3]*u_vv;
|
||||
data_[4] = data_[4]*v_vv - other.data_[4]*u_vv;
|
||||
data_[5] = data_[5]*v_vv - other.data_[5]*u_vv;
|
||||
data_[6] = data_[6]*v_vv - other.data_[6]*u_vv;
|
||||
data_[7] = data_[7]*v_vv - other.data_[7]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
data_[3] = data_[3] * v_vv - other.data_[3] * u_vv;
|
||||
data_[4] = data_[4] * v_vv - other.data_[4] * u_vv;
|
||||
data_[5] = data_[5] * v_vv - other.data_[5] * u_vv;
|
||||
data_[6] = data_[6] * v_vv - other.data_[6] * u_vv;
|
||||
data_[7] = data_[7] * v_vv - other.data_[7] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -312,9 +286,8 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
@@ -323,8 +296,7 @@ public:
|
||||
data_[5] *= tmp;
|
||||
data_[6] *= tmp;
|
||||
data_[7] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -333,20 +305,18 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
result.data_[3] = df_dg*b.data_[3];
|
||||
result.data_[4] = df_dg*b.data_[4];
|
||||
result.data_[5] = df_dg*b.data_[5];
|
||||
result.data_[6] = df_dg*b.data_[6];
|
||||
result.data_[7] = df_dg*b.data_[7];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
result.data_[3] = df_dg * b.data_[3];
|
||||
result.data_[4] = df_dg * b.data_[4];
|
||||
result.data_[5] = df_dg * b.data_[5];
|
||||
result.data_[6] = df_dg * b.data_[6];
|
||||
result.data_[7] = df_dg * b.data_[7];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -386,9 +356,7 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
@@ -397,8 +365,7 @@ public:
|
||||
result.data_[5] = - data_[5];
|
||||
result.data_[6] = - data_[6];
|
||||
result.data_[7] = - data_[7];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -442,9 +409,7 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -453,8 +418,7 @@ public:
|
||||
data_[5] = other.data_[5];
|
||||
data_[6] = other.data_[6];
|
||||
data_[7] = other.data_[7];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -464,10 +428,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 8>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 8;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,16 +74,13 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -98,7 +92,6 @@ public:
|
||||
data_[8] = other.data_[8];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -129,9 +122,7 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
data_[3] = 0.0;
|
||||
@@ -140,7 +131,6 @@ public:
|
||||
data_[6] = 0.0;
|
||||
data_[7] = 0.0;
|
||||
data_[8] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -166,15 +156,14 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
@@ -183,15 +172,12 @@ public:
|
||||
data_[6] = other.data_[6];
|
||||
data_[7] = other.data_[7];
|
||||
data_[8] = other.data_[8];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
@@ -201,8 +187,7 @@ public:
|
||||
data_[6] += other.data_[6];
|
||||
data_[7] += other.data_[7];
|
||||
data_[8] += other.data_[8];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -217,9 +202,7 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
@@ -229,7 +212,7 @@ public:
|
||||
data_[6] -= other.data_[6];
|
||||
data_[7] -= other.data_[7];
|
||||
data_[8] -= other.data_[8];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -248,24 +231,21 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
this->data_[3] = this->data_[3]*v + other.data_[3] * u;
|
||||
this->data_[4] = this->data_[4]*v + other.data_[4] * u;
|
||||
this->data_[5] = this->data_[5]*v + other.data_[5] * u;
|
||||
this->data_[6] = this->data_[6]*v + other.data_[6] * u;
|
||||
this->data_[7] = this->data_[7]*v + other.data_[7] * u;
|
||||
this->data_[8] = this->data_[8]*v + other.data_[8] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
data_[3] = data_[3] * v + other.data_[3] * u;
|
||||
data_[4] = data_[4] * v + other.data_[4] * u;
|
||||
data_[5] = data_[5] * v + other.data_[5] * u;
|
||||
data_[6] = data_[6] * v + other.data_[6] * u;
|
||||
data_[7] = data_[7] * v + other.data_[7] * u;
|
||||
data_[8] = data_[8] * v + other.data_[8] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -273,9 +253,7 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
@@ -285,8 +263,7 @@ public:
|
||||
data_[6] *= other;
|
||||
data_[7] *= other;
|
||||
data_[8] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -294,25 +271,22 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
data_[3] = data_[3]*v_vv - other.data_[3]*u_vv;
|
||||
data_[4] = data_[4]*v_vv - other.data_[4]*u_vv;
|
||||
data_[5] = data_[5]*v_vv - other.data_[5]*u_vv;
|
||||
data_[6] = data_[6]*v_vv - other.data_[6]*u_vv;
|
||||
data_[7] = data_[7]*v_vv - other.data_[7]*u_vv;
|
||||
data_[8] = data_[8]*v_vv - other.data_[8]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
data_[3] = data_[3] * v_vv - other.data_[3] * u_vv;
|
||||
data_[4] = data_[4] * v_vv - other.data_[4] * u_vv;
|
||||
data_[5] = data_[5] * v_vv - other.data_[5] * u_vv;
|
||||
data_[6] = data_[6] * v_vv - other.data_[6] * u_vv;
|
||||
data_[7] = data_[7] * v_vv - other.data_[7] * u_vv;
|
||||
data_[8] = data_[8] * v_vv - other.data_[8] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -320,9 +294,8 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
@@ -332,8 +305,7 @@ public:
|
||||
data_[6] *= tmp;
|
||||
data_[7] *= tmp;
|
||||
data_[8] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -342,21 +314,19 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
result.data_[3] = df_dg*b.data_[3];
|
||||
result.data_[4] = df_dg*b.data_[4];
|
||||
result.data_[5] = df_dg*b.data_[5];
|
||||
result.data_[6] = df_dg*b.data_[6];
|
||||
result.data_[7] = df_dg*b.data_[7];
|
||||
result.data_[8] = df_dg*b.data_[8];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
result.data_[3] = df_dg * b.data_[3];
|
||||
result.data_[4] = df_dg * b.data_[4];
|
||||
result.data_[5] = df_dg * b.data_[5];
|
||||
result.data_[6] = df_dg * b.data_[6];
|
||||
result.data_[7] = df_dg * b.data_[7];
|
||||
result.data_[8] = df_dg * b.data_[8];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -396,9 +366,7 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
@@ -408,8 +376,7 @@ public:
|
||||
result.data_[6] = - data_[6];
|
||||
result.data_[7] = - data_[7];
|
||||
result.data_[8] = - data_[8];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -453,9 +420,7 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -465,8 +430,7 @@ public:
|
||||
data_[6] = other.data_[6];
|
||||
data_[7] = other.data_[7];
|
||||
data_[8] = other.data_[8];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -476,10 +440,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,17 +54,14 @@ namespace DenseAd {
|
||||
|
||||
template <class ValueT>
|
||||
class Evaluation<ValueT, 9>
|
||||
|
||||
{
|
||||
public:
|
||||
//! field type
|
||||
typedef ValueT ValueType;
|
||||
|
||||
//! number of derivatives
|
||||
|
||||
//! number of derivatives
|
||||
static constexpr int size = 9;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
//! length of internal data vector
|
||||
static constexpr int length_ = size + 1;
|
||||
@@ -77,16 +74,13 @@ protected:
|
||||
static constexpr int dend_ = length_;
|
||||
|
||||
public:
|
||||
|
||||
//! default constructor
|
||||
Evaluation() : data_()
|
||||
{}
|
||||
|
||||
//! copy other function evaluation
|
||||
Evaluation(const Evaluation& other)
|
||||
|
||||
{
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -99,7 +93,6 @@ public:
|
||||
data_[9] = other.data_[9];
|
||||
}
|
||||
|
||||
|
||||
// create an evaluation which represents a constant function
|
||||
//
|
||||
// i.e., f(x) = c. this implies an evaluation with the given value and all
|
||||
@@ -130,9 +123,7 @@ public:
|
||||
|
||||
// set all derivatives to zero
|
||||
void clearDerivatives()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = 0.0;
|
||||
data_[2] = 0.0;
|
||||
data_[3] = 0.0;
|
||||
@@ -142,7 +133,6 @@ public:
|
||||
data_[7] = 0.0;
|
||||
data_[8] = 0.0;
|
||||
data_[9] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
|
||||
@@ -168,15 +158,14 @@ public:
|
||||
// print value
|
||||
os << "v: " << value() << " / d:";
|
||||
// print derivatives
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx)
|
||||
for (int varIdx = 0; varIdx < size; ++varIdx) {
|
||||
os << " " << derivative(varIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// copy all derivatives from other
|
||||
void copyDerivatives(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
data_[3] = other.data_[3];
|
||||
@@ -186,15 +175,12 @@ public:
|
||||
data_[7] = other.data_[7];
|
||||
data_[8] = other.data_[8];
|
||||
data_[9] = other.data_[9];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add value and derivatives from other to this values and derivatives
|
||||
Evaluation& operator+=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] += other.data_[0];
|
||||
data_[1] += other.data_[1];
|
||||
data_[2] += other.data_[2];
|
||||
@@ -205,8 +191,7 @@ public:
|
||||
data_[7] += other.data_[7];
|
||||
data_[8] += other.data_[8];
|
||||
data_[9] += other.data_[9];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -221,9 +206,7 @@ public:
|
||||
|
||||
// subtract other's value and derivatives from this values
|
||||
Evaluation& operator-=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] -= other.data_[0];
|
||||
data_[1] -= other.data_[1];
|
||||
data_[2] -= other.data_[2];
|
||||
@@ -234,7 +217,7 @@ public:
|
||||
data_[7] -= other.data_[7];
|
||||
data_[8] -= other.data_[8];
|
||||
data_[9] -= other.data_[9];
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -253,25 +236,22 @@ public:
|
||||
{
|
||||
// while the values are multiplied, the derivatives follow the product rule,
|
||||
// i.e., (u*v)' = (v'u + u'v).
|
||||
const ValueT u = this->value();
|
||||
const ValueT v = other.value();
|
||||
const ValueType u = this->value();
|
||||
const ValueType v = other.value();
|
||||
|
||||
// value
|
||||
this->data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
this->data_[1] = this->data_[1]*v + other.data_[1] * u;
|
||||
this->data_[2] = this->data_[2]*v + other.data_[2] * u;
|
||||
this->data_[3] = this->data_[3]*v + other.data_[3] * u;
|
||||
this->data_[4] = this->data_[4]*v + other.data_[4] * u;
|
||||
this->data_[5] = this->data_[5]*v + other.data_[5] * u;
|
||||
this->data_[6] = this->data_[6]*v + other.data_[6] * u;
|
||||
this->data_[7] = this->data_[7]*v + other.data_[7] * u;
|
||||
this->data_[8] = this->data_[8]*v + other.data_[8] * u;
|
||||
this->data_[9] = this->data_[9]*v + other.data_[9] * u;
|
||||
data_[valuepos_] *= v ;
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v + other.data_[1] * u;
|
||||
data_[2] = data_[2] * v + other.data_[2] * u;
|
||||
data_[3] = data_[3] * v + other.data_[3] * u;
|
||||
data_[4] = data_[4] * v + other.data_[4] * u;
|
||||
data_[5] = data_[5] * v + other.data_[5] * u;
|
||||
data_[6] = data_[6] * v + other.data_[6] * u;
|
||||
data_[7] = data_[7] * v + other.data_[7] * u;
|
||||
data_[8] = data_[8] * v + other.data_[8] * u;
|
||||
data_[9] = data_[9] * v + other.data_[9] * u;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -279,9 +259,7 @@ public:
|
||||
// m(c*u)' = c*u'
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator*=(const RhsValueType& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] *= other;
|
||||
data_[1] *= other;
|
||||
data_[2] *= other;
|
||||
@@ -292,8 +270,7 @@ public:
|
||||
data_[7] *= other;
|
||||
data_[8] *= other;
|
||||
data_[9] *= other;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -301,26 +278,23 @@ public:
|
||||
Evaluation& operator/=(const Evaluation& other)
|
||||
{
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u - u'v)/v^2.
|
||||
const ValueT v_vv = 1.0 / other.value();
|
||||
const ValueT u_vv = value() * v_vv * v_vv;
|
||||
const ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
|
||||
|
||||
data_[1] = data_[1]*v_vv - other.data_[1]*u_vv;
|
||||
data_[2] = data_[2]*v_vv - other.data_[2]*u_vv;
|
||||
data_[3] = data_[3]*v_vv - other.data_[3]*u_vv;
|
||||
data_[4] = data_[4]*v_vv - other.data_[4]*u_vv;
|
||||
data_[5] = data_[5]*v_vv - other.data_[5]*u_vv;
|
||||
data_[6] = data_[6]*v_vv - other.data_[6]*u_vv;
|
||||
data_[7] = data_[7]*v_vv - other.data_[7]*u_vv;
|
||||
data_[8] = data_[8]*v_vv - other.data_[8]*u_vv;
|
||||
data_[9] = data_[9]*v_vv - other.data_[9]*u_vv;
|
||||
|
||||
|
||||
// derivatives
|
||||
data_[1] = data_[1] * v_vv - other.data_[1] * u_vv;
|
||||
data_[2] = data_[2] * v_vv - other.data_[2] * u_vv;
|
||||
data_[3] = data_[3] * v_vv - other.data_[3] * u_vv;
|
||||
data_[4] = data_[4] * v_vv - other.data_[4] * u_vv;
|
||||
data_[5] = data_[5] * v_vv - other.data_[5] * u_vv;
|
||||
data_[6] = data_[6] * v_vv - other.data_[6] * u_vv;
|
||||
data_[7] = data_[7] * v_vv - other.data_[7] * u_vv;
|
||||
data_[8] = data_[8] * v_vv - other.data_[8] * u_vv;
|
||||
data_[9] = data_[9] * v_vv - other.data_[9] * u_vv;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -328,9 +302,8 @@ public:
|
||||
template <class RhsValueType>
|
||||
Evaluation& operator/=(const RhsValueType& other)
|
||||
{
|
||||
ValueType tmp = 1.0/other;
|
||||
|
||||
|
||||
const ValueType tmp = 1.0/other;
|
||||
|
||||
data_[0] *= tmp;
|
||||
data_[1] *= tmp;
|
||||
data_[2] *= tmp;
|
||||
@@ -341,8 +314,7 @@ public:
|
||||
data_[7] *= tmp;
|
||||
data_[8] *= tmp;
|
||||
data_[9] *= tmp;
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -351,22 +323,20 @@ public:
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
ValueType tmp = 1.0/b.value();
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueT df_dg = - result.value()*tmp;
|
||||
|
||||
|
||||
|
||||
result.data_[1] = df_dg*b.data_[1];
|
||||
result.data_[2] = df_dg*b.data_[2];
|
||||
result.data_[3] = df_dg*b.data_[3];
|
||||
result.data_[4] = df_dg*b.data_[4];
|
||||
result.data_[5] = df_dg*b.data_[5];
|
||||
result.data_[6] = df_dg*b.data_[6];
|
||||
result.data_[7] = df_dg*b.data_[7];
|
||||
result.data_[8] = df_dg*b.data_[8];
|
||||
result.data_[9] = df_dg*b.data_[9];
|
||||
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
result.data_[1] = df_dg * b.data_[1];
|
||||
result.data_[2] = df_dg * b.data_[2];
|
||||
result.data_[3] = df_dg * b.data_[3];
|
||||
result.data_[4] = df_dg * b.data_[4];
|
||||
result.data_[5] = df_dg * b.data_[5];
|
||||
result.data_[6] = df_dg * b.data_[6];
|
||||
result.data_[7] = df_dg * b.data_[7];
|
||||
result.data_[8] = df_dg * b.data_[8];
|
||||
result.data_[9] = df_dg * b.data_[9];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -406,9 +376,7 @@ public:
|
||||
Evaluation operator-() const
|
||||
{
|
||||
Evaluation result;
|
||||
// set value and derivatives to negative
|
||||
|
||||
|
||||
// set value and derivatives to negative
|
||||
result.data_[0] = - data_[0];
|
||||
result.data_[1] = - data_[1];
|
||||
result.data_[2] = - data_[2];
|
||||
@@ -419,8 +387,7 @@ public:
|
||||
result.data_[7] = - data_[7];
|
||||
result.data_[8] = - data_[8];
|
||||
result.data_[9] = - data_[9];
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -464,9 +431,7 @@ public:
|
||||
|
||||
// copy assignment from evaluation
|
||||
Evaluation& operator=(const Evaluation& other)
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
data_[0] = other.data_[0];
|
||||
data_[1] = other.data_[1];
|
||||
data_[2] = other.data_[2];
|
||||
@@ -477,8 +442,7 @@ public:
|
||||
data_[7] = other.data_[7];
|
||||
data_[8] = other.data_[8];
|
||||
data_[9] = other.data_[9];
|
||||
|
||||
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -488,10 +452,11 @@ public:
|
||||
|
||||
bool operator==(const Evaluation& other) const
|
||||
{
|
||||
for (int idx = 0; idx < length_; ++idx)
|
||||
if (data_[idx] != other.data_[idx])
|
||||
for (int idx = 0; idx < length_; ++idx) {
|
||||
if (data_[idx] != other.data_[idx]) {
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user