47 #include <Teuchos_MathExpr.hpp>
65 case Teuchos::MathExpr::TOK_NAME: {
66 std::string&
result = Teuchos::make_any_ref<std::string>(result_any);
70 case Teuchos::MathExpr::TOK_CONST: {
80 case Teuchos::MathExpr::PROD_PROGRAM: {
84 case Teuchos::MathExpr::PROD_NO_STATEMENTS:
85 case Teuchos::MathExpr::PROD_NO_EXPR:
86 case Teuchos::MathExpr::PROD_NEXT_STATEMENT: {
89 case Teuchos::MathExpr::PROD_ASSIGN: {
90 std::string
const& name = Teuchos::any_ref_cast<std::string>(rhs.at(0));
94 case Teuchos::MathExpr::PROD_YES_EXPR:
95 case Teuchos::MathExpr::PROD_EXPR:
96 case Teuchos::MathExpr::PROD_TERNARY_DECAY:
97 case Teuchos::MathExpr::PROD_OR_DECAY:
98 case Teuchos::MathExpr::PROD_AND_DECAY:
99 case Teuchos::MathExpr::PROD_ADD_SUB_DECAY:
100 case Teuchos::MathExpr::PROD_MUL_DIV_DECAY:
101 case Teuchos::MathExpr::PROD_POW_DECAY:
102 case Teuchos::MathExpr::PROD_NEG_DECAY:
103 case Teuchos::MathExpr::PROD_SOME_ARGS:
106 case Teuchos::MathExpr::PROD_TERNARY:
107 this->
ternary_op(result, rhs.at(0), rhs.at(3), rhs.at(6));
109 case Teuchos::MathExpr::PROD_OR:
112 case Teuchos::MathExpr::PROD_AND:
115 case Teuchos::MathExpr::PROD_GT:
118 case Teuchos::MathExpr::PROD_LT:
121 case Teuchos::MathExpr::PROD_GEQ:
124 case Teuchos::MathExpr::PROD_LEQ:
127 case Teuchos::MathExpr::PROD_EQ:
130 case Teuchos::MathExpr::PROD_BOOL_PARENS:
133 case Teuchos::MathExpr::PROD_ADD:
136 case Teuchos::MathExpr::PROD_SUB:
139 case Teuchos::MathExpr::PROD_MUL:
142 case Teuchos::MathExpr::PROD_DIV:
145 case Teuchos::MathExpr::PROD_POW:
148 case Teuchos::MathExpr::PROD_CALL: {
149 std::string
const& name = Teuchos::any_ref_cast<std::string>(rhs.at(0));
152 "symbol \"" << name <<
"\" being called doesn't exist!");
153 Function& func = Teuchos::any_ref_cast<Function>(it->second);
154 std::vector<Teuchos::any>& args = Teuchos::any_ref_cast<std::vector<Teuchos::any>>(rhs.at(4));
158 case Teuchos::MathExpr::PROD_NO_ARGS: {
159 result = std::vector<Teuchos::any>{};
162 case Teuchos::MathExpr::PROD_FIRST_ARG: {
163 std::vector<Teuchos::any>& args = Teuchos::make_any_ref<std::vector<Teuchos::any>>(
result);
165 swap(args.back(), rhs.at(0));
168 case Teuchos::MathExpr::PROD_NEXT_ARG: {
170 std::vector<Teuchos::any>& args = Teuchos::any_ref_cast<std::vector<Teuchos::any>>(
result);
172 swap(args.back(), rhs.at(3));
175 case Teuchos::MathExpr::PROD_NEG:
176 this->
neg_op(result, rhs.at(2));
178 case Teuchos::MathExpr::PROD_VAL_PARENS:
181 case Teuchos::MathExpr::PROD_CONST:
184 case Teuchos::MathExpr::PROD_VAR:
185 std::string
const& name = Teuchos::any_ref_cast<std::string>(rhs.at(0));
188 "symbol " << name <<
" being referenced doesn't exist!");
197 this->
inspect_arg(cond, cond_is_many, cond_is_bool);
199 "Ternary condition is not of boolean type!");
205 "Boolean values in ternary operator not yet supported");
207 auto cond_value = Teuchos::any_cast<Kokkos::View<bool const>>(cond);
208 auto host_cond_value = Kokkos::create_mirror_view(cond_value);
209 Kokkos::deep_copy(host_cond_value, cond_value);
210 if (host_cond_value()) {
216 if (!is_many[0] && !is_many[1]) {
218 }
else if (!is_many[0] && is_many[1]) {
220 }
else if (is_many[0] && !is_many[1]) {
222 }
else if (is_many[0] && is_many[1]) {
253 "Left argument to '" <<
get_op_syntax(code) <<
"' is " << (is_bool[0] ?
"" :
"not") <<
" boolean!");
255 "Right argument to '" <<
get_op_syntax(code) <<
"' is " << (is_bool[0] ?
"" :
"not") <<
" boolean!");
256 if (!is_many[0] && !is_many[1]) {
258 }
else if (!is_many[0] && is_many[1]) {
260 }
else if (is_many[0] && !is_many[1]) {
262 }
else if (is_many[0] && is_many[1]) {
272 "Can't negate a boolean");