From 407e7b7a9376dd3f722f0fc08fb806b3970e594d Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 10 Jan 2017 16:45:32 +0100 Subject: Simplify symbolic API by using "symbol=value" to associate a runtime value to a symbol. --- Eigen/src/Core/ArithmeticSequence.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'Eigen/src/Core/ArithmeticSequence.h') diff --git a/Eigen/src/Core/ArithmeticSequence.h b/Eigen/src/Core/ArithmeticSequence.h index b425b7804..01cc5e15b 100644 --- a/Eigen/src/Core/ArithmeticSequence.h +++ b/Eigen/src/Core/ArithmeticSequence.h @@ -37,11 +37,11 @@ static const all_t all; * auto expr = (x+3)/y+z; * * // And evaluate it: (c++14) - * std::cout << expr.eval(std::make_tuple(Symbolic::defineValue(x,6),Symbolic::defineValue(y,3),Symbolic::defineValue(z,-13))) << "\n"; + * std::cout << expr.eval(std::make_tuple(x=6,y=3,z=-13)) << "\n"; * * // In c++98/11, only one symbol per expression is supported for now: * auto expr98 = (3-x)/2; - * std::cout << expr98.eval(Symbolic::defineValue(x,6)) << "\n"; + * std::cout << expr98.eval(x=6) << "\n"; * * It is currently only used internally to define and minipulate the placeholders::last and placeholders::end symbols in Eigen::seq and Eigen::seqN. * @@ -77,7 +77,7 @@ public: /** Evaluate the expression given the \a values of the symbols. * * \param values defines the values of the symbols, it can either be a SymbolValue or a std::tuple of SymbolValue - * as constructed by the defineValue function. + * as constructed by SymbolExpr::operator= operator. * */ template @@ -120,7 +120,7 @@ struct is_symbolic { /** Represents the actual value of a symbol identified by its tag * - * It is the return type of defineValue(), and most of the time this is only way it is used. + * It is the return type of SymbolValue::operator=, and most of the time this is only way it is used. */ template class SymbolValue @@ -135,6 +135,7 @@ protected: Index m_value; }; +/** Expression of a symbol uniquely identified by the tag \tparam TagT */ template class SymbolExpr : public BaseExpr > { @@ -142,6 +143,14 @@ public: typedef TagT Tag; SymbolExpr() {} + /** Associate the value \a val to the given symbol \c *this, uniquely identified by its \c Tag. + * + * The returned object should be passed to ExprBase::eval() to evaluate a given expression with this specified runtime-time value. + */ + SymbolValue operator=(Index val) const { + return SymbolValue(val); + } + Index eval(const SymbolValue &values) const { return values.value(); } #if __cplusplus > 201103L @@ -151,13 +160,6 @@ public: #endif }; -/** Associate the value \a val to the symbol \a symb - */ -template -SymbolValue defineValue(SymbolExpr /*symb*/,Index val) { - return SymbolValue(val); -} - template class NegateExpr : public BaseExpr > { @@ -488,7 +490,7 @@ fix_t eval_expr_given_size(fix_t x, Index /*size*/) { return x; } template Index eval_expr_given_size(const Symbolic::BaseExpr &x, Index size) { - return x.derived().eval(Symbolic::defineValue(placeholders::last,size-1)); + return x.derived().eval(placeholders::last=size-1); } // Convert a symbolic span into a usable one (i.e., remove last/end "keywords") -- cgit v1.2.3