revert optimizing the division code for evaluations
This commit is contained in:
@@ -319,23 +319,23 @@ public:
|
||||
// m(u*v)' = (vu' - uv')/v^2
|
||||
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 ValueType v_vv = 1.0 / other.value();
|
||||
const ValueType u_vv = value() * v_vv * v_vv;
|
||||
|
||||
// value
|
||||
data_[valuepos_] *= v_vv;
|
||||
|
||||
// derivatives
|
||||
// values are divided, derivatives follow the rule for division, i.e., (u/v)' = (v'u -
|
||||
// u'v)/v^2.
|
||||
ValueType& u = data_[ valuepos_ ];
|
||||
const ValueType& v = other.value();
|
||||
{% if numDerivs < 0 %}\
|
||||
for (int i = dstart_; i < dend_; ++i) {
|
||||
data_[i] = data_[i] * v_vv - other.data_[i] * u_vv;
|
||||
for (unsigned idx = dstart_; idx < dend_; ++idx) {
|
||||
const ValueType& uPrime = data_[idx];
|
||||
const ValueType& vPrime = other.data_[idx];
|
||||
|
||||
data_[idx] = (v*uPrime - u*vPrime)/(v*v);
|
||||
}
|
||||
{% else %}\
|
||||
{% for i in range(1, numDerivs+1) %}\
|
||||
data_[{{i}}] = data_[{{i}}] * v_vv - other.data_[{{i}}] * u_vv;
|
||||
data_[{{i}}] = (v*data_[{{i}}] - u*other.data_[{{i}}])/(v*v);
|
||||
{% endfor %}\
|
||||
{% endif %}\
|
||||
u /= v;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -359,29 +359,6 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
// division of a constant by an Evaluation
|
||||
template <class RhsValueType>
|
||||
static inline Evaluation divide(const RhsValueType& a, const Evaluation& b)
|
||||
{
|
||||
Evaluation result;
|
||||
|
||||
const ValueType tmp = 1.0/b.value();
|
||||
result.setValue( a*tmp );
|
||||
const ValueType df_dg = - result.value()*tmp;
|
||||
|
||||
{% if numDerivs < 0 %}\
|
||||
for (int i = dstart_; i < dend_; ++i) {
|
||||
result.data_[i] = df_dg * b.data_[i];
|
||||
}
|
||||
{% else %}\
|
||||
{% for i in range(1, numDerivs+1) %}\
|
||||
result.data_[{{i}}] = df_dg * b.data_[{{i}}];
|
||||
{% endfor %}\
|
||||
{% endif %}\
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// add two evaluation objects
|
||||
Evaluation operator+(const Evaluation& other) const
|
||||
{
|
||||
@@ -621,7 +598,9 @@ Evaluation<ValueType, numVars> operator-(const RhsValueType& a, const Evaluation
|
||||
template <class RhsValueType, class ValueType, int numVars>
|
||||
Evaluation<ValueType, numVars> operator/(const RhsValueType& a, const Evaluation<ValueType, numVars>& b)
|
||||
{
|
||||
return Evaluation<ValueType, numVars>::divide(a, b);
|
||||
Evaluation<ValueType, numVars> tmp(a);
|
||||
tmp /= b;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <class RhsValueType, class ValueType, int numVars>
|
||||
|
||||
Reference in New Issue
Block a user