MCPcopy Create free account
hub / github.com/KratosMultiphysics/Kratos / optimize

Function optimize

external_libraries/tinyexpr/tinyexpr/tinyexpr.c:665–688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

663#undef M
664
665static void optimize(te_expr *n) {
666 /* Evaluates as much as possible. */
667 if (n->type == TE_CONSTANT) return;
668 if (n->type == TE_VARIABLE) return;
669
670 /* Only optimize out functions flagged as pure. */
671 if (IS_PURE(n->type)) {
672 const int arity = ARITY(n->type);
673 int known = 1;
674 int i;
675 for (i = 0; i < arity; ++i) {
676 optimize(n->parameters[i]);
677 if (((te_expr*)(n->parameters[i]))->type != TE_CONSTANT) {
678 known = 0;
679 }
680 }
681 if (known) {
682 const double value = te_eval(n);
683 te_free_parameters(n);
684 n->type = TE_CONSTANT;
685 n->value = value;
686 }
687 }
688}
689
690
691te_expr *te_compile(const char *expression, const te_variable *variables, int var_count, int *error) {

Callers 3

te_compileFunction · 0.85
psincos_floatFunction · 0.85
psincos_doubleFunction · 0.85

Calls 2

te_evalFunction · 0.85
te_free_parametersFunction · 0.85

Tested by

no test coverage detected