move some Expression implementations to include header
parent
949efebe72
commit
376c9e409d
|
@ -931,6 +931,48 @@ Expression<T>::Expression(
|
||||||
expression3)) {
|
expression3)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Return root
|
||||||
|
template<typename T>
|
||||||
|
const boost::shared_ptr<ExpressionNode<T> >& Expression<T>::root() const {
|
||||||
|
return root_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return size needed for memory buffer in traceExecution
|
||||||
|
template<typename T>
|
||||||
|
size_t Expression<T>::traceSize() const {
|
||||||
|
return root_->traceSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return keys that play in this expression
|
||||||
|
template<typename T>
|
||||||
|
std::set<Key> Expression<T>::keys() const {
|
||||||
|
return root_->keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return dimensions for each argument, as a map
|
||||||
|
template<typename T>
|
||||||
|
void Expression<T>::dims(std::map<Key, int>& map) const {
|
||||||
|
root_->dims(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return value and optional derivatives, reverse AD version
|
||||||
|
* Notes: this is not terribly efficient, and H should have correct size.
|
||||||
|
* The order of the Jacobians is same as keys in either keys() or dims()
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
T Expression<T>::value(const Values& values, boost::optional<std::vector<Matrix>&> H) const {
|
||||||
|
|
||||||
|
if (H) {
|
||||||
|
// Call private version that returns derivatives in H
|
||||||
|
KeysAndDims pair = keysAndDims();
|
||||||
|
return value(values, pair.first, pair.second, *H);
|
||||||
|
} else
|
||||||
|
// no derivatives needed, just return value
|
||||||
|
return root_->value(values);
|
||||||
|
}
|
||||||
|
|
||||||
/// private version that takes keys and dimensions, returns derivatives
|
/// private version that takes keys and dimensions, returns derivatives
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T Expression<T>::value(const Values& values, const FastVector<Key>& keys,
|
T Expression<T>::value(const Values& values, const FastVector<Key>& keys,
|
||||||
|
|
|
@ -144,24 +144,16 @@ public:
|
||||||
const Expression<A3>& expression3);
|
const Expression<A3>& expression3);
|
||||||
|
|
||||||
/// Return root
|
/// Return root
|
||||||
const boost::shared_ptr<ExpressionNode<T> >& root() const {
|
const boost::shared_ptr<ExpressionNode<T> >& root() const;
|
||||||
return root_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return size needed for memory buffer in traceExecution
|
// Return size needed for memory buffer in traceExecution
|
||||||
size_t traceSize() const {
|
size_t traceSize() const;
|
||||||
return root_->traceSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return keys that play in this expression
|
/// Return keys that play in this expression
|
||||||
std::set<Key> keys() const {
|
std::set<Key> keys() const;
|
||||||
return root_->keys();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return dimensions for each argument, as a map
|
/// Return dimensions for each argument, as a map
|
||||||
void dims(std::map<Key, int>& map) const {
|
void dims(std::map<Key, int>& map) const;
|
||||||
root_->dims(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return value and optional derivatives, reverse AD version
|
* @brief Return value and optional derivatives, reverse AD version
|
||||||
|
@ -169,16 +161,7 @@ public:
|
||||||
* The order of the Jacobians is same as keys in either keys() or dims()
|
* The order of the Jacobians is same as keys in either keys() or dims()
|
||||||
*/
|
*/
|
||||||
T value(const Values& values, boost::optional<std::vector<Matrix>&> H =
|
T value(const Values& values, boost::optional<std::vector<Matrix>&> H =
|
||||||
boost::none) const {
|
boost::none) const;
|
||||||
|
|
||||||
if (H) {
|
|
||||||
// Call private version that returns derivatives in H
|
|
||||||
KeysAndDims pair = keysAndDims();
|
|
||||||
return value(values, pair.first, pair.second, *H);
|
|
||||||
} else
|
|
||||||
// no derivatives needed, just return value
|
|
||||||
return root_->value(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a "deep" copy of this Expression
|
* @return a "deep" copy of this Expression
|
||||||
|
|
Loading…
Reference in New Issue