void rb_monitor_get_op_variables(const rb_monitor_t *monitor, char ***vars, size_t *vars_size) { void *evaluator = NULL; (*vars) = NULL; *vars_size = 0; struct { char **vars; int count; } all_vars; if (monitor->type != RB_MONITOR_T__OP) { goto no_deps; } evaluator = evaluator_create((char *)monitor->cmd_arg); if (NULL == evaluator) { rdlog(LOG_ERR, "Couldn't create an evaluator from %s", monitor->cmd_arg); goto no_deps; } evaluator_get_variables(evaluator, &all_vars.vars, &all_vars.count); (*vars) = malloc((size_t)all_vars.count * sizeof((*vars)[0])); if (*vars == NULL) { rdlog(LOG_CRIT, "Couldn't allocate memory for %d vars", all_vars.count); goto no_deps; } for (int i = 0; i < all_vars.count; ++i) { (*vars)[i] = strdup(all_vars.vars[i]); if (NULL == (*vars)[i]) { rdlog(LOG_ERR, "Couldn't strdup %s (OOM?)", all_vars.vars[i]); for (int j = 0; j < i; ++j) { free((*vars)[j]); (*vars)[j] = NULL; } goto no_deps; } } *vars_size = (size_t)all_vars.count; evaluator_destroy(evaluator); return; no_deps: if (*vars) { free(*vars); } *vars = NULL; *vars_size = 0; if (evaluator) { evaluator_destroy(evaluator); } }
/*! \brief frees up the resource for a MultiSource structure \param data is the pointer to MultiSource structure to deallocate */ G_MODULE_EXPORT void free_multi_source(gpointer data) { MultiSource *multi = (MultiSource *)data; if (!multi) return; cleanup(multi->source); cleanup(multi->multiplier); cleanup(multi->adder); cleanup(multi->suffix); cleanup(multi->lookuptable); if (multi->dl_eval) evaluator_destroy(multi->dl_eval); if (multi->ul_eval) evaluator_destroy(multi->ul_eval); cleanup(multi); }
double newtonrap(double x0, double es, double *ea, int imax, int *iter, int tabla, char *buffer, char *buffer2) { double x1=x0; void *f, *f2; /* Evaluators for function and function derivative. */ /* Create evaluator for function. */ f = evaluator_create (buffer); f2 = evaluator_create (buffer2); assert (f); assert (f2); if(tabla == 1) { printf ("\n\n| i | Raiz | ea | f(xr) | \n"); printf ("______________________________________________________\n"); } *iter = 0; do{ x0 = x1; x1 = x0-(evaluator_evaluate_x(f,x0)/evaluator_evaluate_x(f2,x0)); *iter=*iter+1; if(x1!=0) { *ea=fabs((x1-x0)/x1)*100; } if ( tabla == 1 ) { printf ("| %2d | %12.8f | %12.8f | %12.8f |\n", *iter, x1, *ea, evaluator_evaluate_x(f,x1) ); } }while(es < *ea && *iter <= imax); evaluator_destroy(f); evaluator_destroy(f2); if ( tabla == 1 ) { printf ("\n\nLa Raiz es %6.4lf en %d iteraciones\n",x1,*iter); printf ("\n\nEl error relativo aproximado es %6.4lf\n",*ea); return 0; } else return x1; }
static void gs_function_plot_finalize (GObject *object) { GsFunctionPlot *plot = GS_FUNCTION_PLOT (object); if (plot->priv->matheval_c != NULL) { evaluator_destroy (plot->priv->matheval_c); } G_OBJECT_CLASS (gs_function_plot_parent_class)->finalize (object); }
void EVALOBJ::setExpression(char *expr) { int len = strlen(expr); if (expression != NULL) delete expression; expression = new char[len+1]; strcpy(expression, expr); setexp=TRUE; if (evaluator != NULL) evaluator_destroy(evaluator); evaluator = evaluator_create(expr); setexp=FALSE; if (evaluator == NULL) report_error("Unable to parse expression"); }
void oph_predicate2_deinit(UDF_INIT * initid) { int i; //Free allocated space if (initid->ptr) { if (((oph_predicate2_param *) initid->ptr)->f[0]) { free(((oph_predicate2_param *) initid->ptr)->f[0]); ((oph_predicate2_param *) initid->ptr)->f[0] = NULL; // binary_array free } for (i = 1; i < 4; ++i) if (((oph_predicate2_param *) initid->ptr)->f[i]) { evaluator_destroy(((oph_predicate2_param *) initid->ptr)->f[i]); ((oph_predicate2_param *) initid->ptr)->f[i] = NULL; // expressions free } free(initid->ptr); initid->ptr = NULL; } }
double pfijo(double x0, double es, double *ea, int imax, int *iter, int tabla, char *buffer) { double xr=x0, xrold; void *f; /* Evaluators for function and function derivative. */ /* Create evaluator for function. */ f = evaluator_create (buffer); assert (f); if(tabla == 1) { printf ("\n\n| i | Raiz | ea | f(xr) | \n"); printf ("______________________________________________________\n"); } *iter = 0; do{ xrold = xr; xr = evaluator_evaluate_x(f,xrold); *iter=*iter+1; if(xr!=0) { *ea=fabs((xr-xrold)/xr)*100; } if ( tabla == 1 ) { printf ("| %2d | %12.8f | %12.8f | %12.8f |\n", *iter, xr, *ea, evaluator_evaluate_x(f,xr) ); } }while(es < *ea && *iter <= imax); evaluator_destroy(f); if ( tabla == 1 ) { printf ("\n\nLa Raiz es %6.4lf en %d iteraciones\n",xr,*iter); printf ("\n\nEl error relativo aproximado es %6.4lf\n",*ea); return 0; } else return xr; }
/* TODO - Revisar que la formula sea correcta: * No tenga caracteres diferentes a una constante permitida y x. * Revisar que la formula tenga sentido para libmatheval... si no es el caso, explotar! */ void gs_function_plot_set_formula (GsFunctionPlot *plot, const gchar *formula) { g_return_if_fail (GS_IS_FUNCTION_PLOT (plot)); void *f = evaluator_create ((char *) formula); g_assert (f != NULL); /* if (f == NULL) { return FALSE; }*/ if (plot->priv->matheval_c != NULL) { evaluator_destroy (plot->priv->matheval_c); } plot->priv->matheval_c = f; g_signal_emit_by_name (G_OBJECT (plot), "plot-changed"); }
char *me_change_string(char *string, int opt, me_t * me) { void *f = NULL, *f_prim = NULL; char *sep_ptr; char *str = NULL; char **names = NULL; int count = 0; char *f_prim_str = NULL; char *vars_str = NULL; double res = 0, res_prim = 0; debug(NULL, "me_change_string: Entered: %s\n", string); if (!me || !string) return NULL; sep_ptr = str_find_sep(string); if (sep_ptr) string = sep_ptr; if (!strlen(string)) return NULL; f = evaluator_create(string); if (!f) return NULL; evaluator_get_variables(f, &names, &count); if (!names) goto cleanup; vars_str = array_to_str((void **)names, count, (char *(*)(void *))strdup); if (!vars_str) goto cleanup; f_prim = evaluator_derivative_x(f); if (!f_prim) goto cleanup; f_prim_str = evaluator_get_string(f_prim); res = evaluator_evaluate_x_y_z(f, me->x, me->y, me->z); res_prim = evaluator_evaluate_x_y_z(f_prim, me->x, me->y, me->z); str = str_unite("f(x,y,z)=%f ... vars={%s} ::: f'(x)=%s=%f", res, vars_str, f_prim_str, res_prim); cleanup: if (f_prim) evaluator_destroy(f_prim); if (f) evaluator_destroy(f); if (vars_str) free(vars_str); return str; }
Polynomial::~Polynomial() { evaluator_destroy( m_e ); }
EVALOBJ::~EVALOBJ() { if (evaluator != NULL) evaluator_destroy(evaluator); if (expression != NULL) delete expression; }
SwitchingFunction::~SwitchingFunction(){ #ifdef __PLUMED_HAS_MATHEVAL if(evaluator) evaluator_destroy(evaluator); if(evaluator_deriv) evaluator_destroy(evaluator_deriv); #endif }