CAMLprim value ml_gsl_multimin_fdfminimizer_minimum(value ox, value odx, value og, value T) { gsl_multimin_fdfminimizer *t=GSLMULTIMINFDFMINIMIZER_VAL(T); if(Is_block(ox)) { value x=Unoption(ox); _DECLARE_VECTOR(x); _CONVERT_VECTOR(x); gsl_vector_memcpy(&v_x, gsl_multimin_fdfminimizer_x(t)); } if(Is_block(odx)) { value dx=Unoption(odx); _DECLARE_VECTOR(dx); _CONVERT_VECTOR(dx); gsl_vector_memcpy(&v_dx, gsl_multimin_fdfminimizer_dx(t)); } if(Is_block(og)) { value g=Unoption(og); _DECLARE_VECTOR(g); _CONVERT_VECTOR(g); gsl_vector_memcpy(&v_g, gsl_multimin_fdfminimizer_gradient(t)); } return copy_double(gsl_multimin_fdfminimizer_minimum(t)); }
CAMLprim value ml_gsl_multiroot_fdfsolver_get_state(value S, value ox, value of, value oj, value odx, value unit) { gsl_multiroot_fdfsolver *s=GSLMULTIROOTFDFSOLVER_VAL(S); if(Is_block(ox)) { value x=Unoption(ox); _DECLARE_VECTOR(x); _CONVERT_VECTOR(x); gsl_vector_memcpy(&v_x, s->x); } if(Is_block(of)) { value f=Unoption(of); _DECLARE_VECTOR(f); _CONVERT_VECTOR(f); gsl_vector_memcpy(&v_f, s->f); } if(Is_block(odx)) { value dx=Unoption(odx); _DECLARE_VECTOR(dx); _CONVERT_VECTOR(dx); gsl_vector_memcpy(&v_dx, s->dx); } if(Is_block(oj)) { value j=Unoption(oj); _DECLARE_MATRIX(j); _CONVERT_MATRIX(j); gsl_matrix_memcpy(&m_j, s->J); } return Val_unit; }
CAMLprim value ml_gsl_odeiv_alloc_system(value func, value ojac, value dim) { const int barr_flags = BIGARRAY_FLOAT64 | BIGARRAY_C_LAYOUT | BIGARRAY_EXTERNAL; struct mlgsl_odeiv_params *p; gsl_odeiv_system *syst; value res; p=stat_alloc(sizeof (*p)); p->dim = Int_val(dim); p->closure = func; register_global_root(&(p->closure)); p->jac_closure = (ojac == Val_none ? Val_unit : Unoption(ojac)); register_global_root(&(p->jac_closure)); p->arr1 = alloc(Int_val(dim) * Double_wosize, Double_array_tag); register_global_root(&(p->arr1)); p->arr2 = alloc(Int_val(dim) * Double_wosize, Double_array_tag); register_global_root(&(p->arr2)); p->mat = (ojac == Val_none) ? Val_unit : alloc_bigarray_dims(barr_flags, 2, NULL, Int_val(dim), Int_val(dim)); register_global_root(&(p->mat)); syst=stat_alloc(sizeof (*syst)); syst->function = ml_gsl_odeiv_func; syst->jacobian = ml_gsl_odeiv_jacobian; syst->dimension = Int_val(dim); syst->params = p; Abstract_ptr(res, syst); return res; }
CAMLprim value ml_gsl_stats_lag1_autocorrelation(value omean, value data) { size_t len = Double_array_length(data); double result; if(omean == Val_none) result = gsl_stats_lag1_autocorrelation(Double_array_val(data), 1, len); else result = gsl_stats_lag1_autocorrelation_m(Double_array_val(data), 1, len, Double_val(Unoption(omean))); return copy_double(result); }
CAMLprim value ml_gsl_multimin_fminimizer_minimum(value ox, value T) { gsl_multimin_fminimizer *t=GSLMULTIMINFMINIMIZER_VAL(T); if(Is_block(ox)) { value x=Unoption(ox); _DECLARE_VECTOR(x); _CONVERT_VECTOR(x); gsl_vector_memcpy(&v_x, gsl_multimin_fminimizer_x(t)); } return copy_double(gsl_multimin_fminimizer_minimum(t)); }
CAMLprim value ml_gsl_stats_sd(value ow, value omean, value data) { size_t len = Double_array_length(data); double result; if(ow == Val_none) if(omean == Val_none) result = gsl_stats_sd(Double_array_val(data), 1, len); else result = gsl_stats_sd_m(Double_array_val(data), 1, len, Double_val(Unoption(omean))); else { value w = Unoption(ow); check_array_size(data, w); if(omean == Val_none) result = gsl_stats_wsd(Double_array_val(w), 1, Double_array_val(data), 1, len); else result = gsl_stats_wsd_m(Double_array_val(w), 1, Double_array_val(data), 1, len, Double_val(Unoption(omean))); } return copy_double(result); }
CAMLprim value ml_gsl_stats_kurtosis(value ow, value data) { size_t len = Double_array_length(data); double result; if(ow == Val_none) result = gsl_stats_kurtosis(Double_array_val(data), 1, len); else { value w = Unoption(ow); check_array_size(data, w); result = gsl_stats_wkurtosis(Double_array_val(w), 1, Double_array_val(data), 1, len); } return copy_double(result); }
CAMLprim value ml_gsl_stats_variance_with_fixed_mean(value ow, value mean, value data) { size_t len = Double_array_length(data); double result; if(ow == Val_none) result = gsl_stats_variance_with_fixed_mean(Double_array_val(data), 1, len, Double_val(mean)); else { value w = Unoption(ow); check_array_size(data, w); result = gsl_stats_wvariance_with_fixed_mean(Double_array_val(w), 1, Double_array_val(data), 1, len, Double_val(mean)); } return copy_double(result); }
CAMLprim value ml_gsl_odeiv_step_apply(value step, value t, value h, value y, value yerr, value odydt_in, value odydt_out, value syst) { CAMLparam5(step, syst, y, yerr, odydt_out); LOCALARRAY(double, y_copy, Double_array_length(y)); LOCALARRAY(double, yerr_copy, Double_array_length(yerr)); size_t len_dydt_in = odydt_in == Val_none ? 0 : Double_array_length(Unoption(odydt_in)) ; size_t len_dydt_out = odydt_out == Val_none ? 0 : Double_array_length(Unoption(odydt_out)) ; LOCALARRAY(double, dydt_in, len_dydt_in); LOCALARRAY(double, dydt_out, len_dydt_out); int status; if(len_dydt_in) memcpy(dydt_in, Double_array_val(Unoption(odydt_in)), Bosize_val(Unoption(odydt_in))); memcpy(y_copy, Double_array_val(y), Bosize_val(y)); memcpy(yerr_copy, Double_array_val(yerr), Bosize_val(yerr)); status = gsl_odeiv_step_apply(ODEIV_STEP_VAL(step), Double_val(t), Double_val(h), y_copy, yerr_copy, len_dydt_in ? dydt_in : NULL, len_dydt_out ? dydt_out : NULL, ODEIV_SYSTEM_VAL(syst)); /* GSL does not call the error handler for this function */ if (status) GSL_ERROR_VAL ("gsl_odeiv_step_apply", status, Val_unit); memcpy(Double_array_val(y), y_copy, sizeof(y_copy)); memcpy(Double_array_val(yerr), yerr_copy, sizeof(yerr_copy)); if(len_dydt_out) memcpy(Double_array_val(Unoption(odydt_out)), dydt_out, Bosize_val(Unoption(odydt_out))); CAMLreturn(Val_unit); }