Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef SUNDANCE_UNARYEVALUATOR_H
00032 #define SUNDANCE_UNARYEVALUATOR_H
00033
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceSubtypeEvaluator.hpp"
00036 #include "SundanceEvaluatableExpr.hpp"
00037
00038
00039 namespace Sundance
00040 {
00041 class EvalContext;
00042
00043
00044
00045
00046
00047 template <class ExprType> class UnaryEvaluator
00048 : public SubtypeEvaluator<ExprType>
00049 {
00050 public:
00051
00052 UnaryEvaluator(const ExprType* expr,
00053 const EvalContext& context)
00054 : SubtypeEvaluator<ExprType>(expr, context),
00055 argExpr_(expr->evaluatableArg()),
00056 argSparsitySuperset_(argExpr_->sparsitySuperset(context)),
00057 argEval_(argExpr_->evaluator(context))
00058 {
00059 try
00060 {
00061 Tabs tab;
00062
00063 SUNDANCE_MSG3(this->verb(), tab << "UnaryEvaluator ctor: expr = " << expr->toString());
00064
00065 SUNDANCE_MSG3(this->verb(), tab << "arg sparsity superset maxOrder: "
00066 << argSparsitySuperset_->maxOrder());
00067
00068 argEval_->addClient();
00069
00070 SUNDANCE_MSG3(this->verb(), tab << "done unary evalulator ctor");
00071 }
00072 catch(std::exception& e)
00073 {
00074 TEST_FOR_EXCEPTION(true, RuntimeError,
00075 "exception detected in UnaryEvaluator: expr="
00076 << expr->toString() << std::endl
00077 << "arg=" << expr->evaluatableArg()->toString() << std::endl
00078 << "exception=" << e.what());
00079 }
00080 }
00081
00082
00083 virtual ~UnaryEvaluator(){;}
00084
00085
00086 virtual void resetNumCalls() const
00087 {
00088 argEval_->resetNumCalls();
00089 Evaluator::resetNumCalls();
00090 }
00091
00092 protected:
00093
00094
00095 const RCP<SparsitySuperset>& argSparsitySuperset() const
00096 {return argSparsitySuperset_;}
00097
00098
00099 const EvaluatableExpr* argExpr() const {return argExpr_;}
00100
00101
00102 const RCP<Evaluator>& argEval() const {return argEval_;}
00103
00104
00105
00106 void evalOperand(const EvalManager& mgr,
00107 Array<double>& argConstantResults,
00108 Array<RCP<EvalVector> >& argVectorResults) const
00109 {
00110 Tabs tabs;
00111 SUNDANCE_MSG1(this->verb(), tabs << "UnaryEvaluator: evaluating operand: ");
00112 argEval()->eval(mgr, argConstantResults, argVectorResults);
00113 SUNDANCE_MSG1(this->verb(), tabs << "UnaryEvaluator: done eval operand ");
00114 }
00115 private:
00116 const EvaluatableExpr* argExpr_;
00117
00118 RCP<SparsitySuperset> argSparsitySuperset_;
00119
00120 RCP<Evaluator> argEval_;
00121 };
00122 }
00123
00124 #endif