numo-gsl 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +84 -0
- data/Rakefile +16 -0
- data/ext/numo/gsl/cdf/depend +17 -0
- data/ext/numo/gsl/cdf/erbpp_cdf.rb +44 -0
- data/ext/numo/gsl/cdf/extconf.rb +9 -0
- data/ext/numo/gsl/cdf/func_def.rb +610 -0
- data/ext/numo/gsl/const/const_def.rb +419 -0
- data/ext/numo/gsl/const/depend +17 -0
- data/ext/numo/gsl/const/erbpp_const.rb +30 -0
- data/ext/numo/gsl/const/extconf.rb +9 -0
- data/ext/numo/gsl/err/depend +1 -0
- data/ext/numo/gsl/err/err.c +22 -0
- data/ext/numo/gsl/err/extconf.rb +9 -0
- data/ext/numo/gsl/extconf_gsl.rb +44 -0
- data/ext/numo/gsl/fit/depend +17 -0
- data/ext/numo/gsl/fit/erbpp_fit.rb +74 -0
- data/ext/numo/gsl/fit/extconf.rb +9 -0
- data/ext/numo/gsl/fit/func_def.rb +129 -0
- data/ext/numo/gsl/fit/tmpl/check_1d.c +9 -0
- data/ext/numo/gsl/fit/tmpl/fit_linear.c +53 -0
- data/ext/numo/gsl/fit/tmpl/fit_linear_est.c +56 -0
- data/ext/numo/gsl/fit/tmpl/fit_mul.c +50 -0
- data/ext/numo/gsl/fit/tmpl/fit_mul_est.c +47 -0
- data/ext/numo/gsl/fit/tmpl/fit_wlinear.c +59 -0
- data/ext/numo/gsl/fit/tmpl/fit_wmul.c +56 -0
- data/ext/numo/gsl/gen/erbpp2.rb +306 -0
- data/ext/numo/gsl/gen/erbpp_gsl.rb +166 -0
- data/ext/numo/gsl/gen/func_parser.rb +520 -0
- data/ext/numo/gsl/gen/tmpl/c_DFloat_f_DFloat.c +40 -0
- data/ext/numo/gsl/gen/tmpl/c_DFloat_f_SZ.c +41 -0
- data/ext/numo/gsl/gen/tmpl/c_DFloat_f_SZ_x2.c +44 -0
- data/ext/numo/gsl/gen/tmpl/c_DFloat_x2_f_DFloat_x2.c +45 -0
- data/ext/numo/gsl/gen/tmpl/c_double_f_double.c +16 -0
- data/ext/numo/gsl/gen/tmpl/c_double_f_sizet.c +16 -0
- data/ext/numo/gsl/gen/tmpl/c_double_f_sizet_x2.c +17 -0
- data/ext/numo/gsl/gen/tmpl/c_double_f_void.c +15 -0
- data/ext/numo/gsl/gen/tmpl/c_double_x2_f_void.c +17 -0
- data/ext/numo/gsl/gen/tmpl/c_new_DFloat.c +29 -0
- data/ext/numo/gsl/gen/tmpl/c_new_double.c +22 -0
- data/ext/numo/gsl/gen/tmpl/c_new_f_other.c +25 -0
- data/ext/numo/gsl/gen/tmpl/c_new_sizet.c +22 -0
- data/ext/numo/gsl/gen/tmpl/c_new_sizet_double.c +23 -0
- data/ext/numo/gsl/gen/tmpl/c_new_sizet_x2.c +23 -0
- data/ext/numo/gsl/gen/tmpl/c_new_void.c +21 -0
- data/ext/numo/gsl/gen/tmpl/c_other_f_void.c +19 -0
- data/ext/numo/gsl/gen/tmpl/c_self_f_DFloat.c +46 -0
- data/ext/numo/gsl/gen/tmpl/c_self_f_DFloat_x2.c +41 -0
- data/ext/numo/gsl/gen/tmpl/c_self_f_DFloat_x3.c +44 -0
- data/ext/numo/gsl/gen/tmpl/c_self_f_DFloat_x4.c +47 -0
- data/ext/numo/gsl/gen/tmpl/c_self_f_SZ_x2_DFloat.c +45 -0
- data/ext/numo/gsl/gen/tmpl/c_self_f_double.c +17 -0
- data/ext/numo/gsl/gen/tmpl/c_self_f_other.c +17 -0
- data/ext/numo/gsl/gen/tmpl/c_self_f_sizet.c +21 -0
- data/ext/numo/gsl/gen/tmpl/c_self_f_void.c +14 -0
- data/ext/numo/gsl/gen/tmpl/c_sizet_f_void.c +15 -0
- data/ext/numo/gsl/gen/tmpl/c_sizet_x2_f_void.c +17 -0
- data/ext/numo/gsl/gen/tmpl/c_str_f_void.c +15 -0
- data/ext/numo/gsl/gen/tmpl/c_super_new_void.c +18 -0
- data/ext/numo/gsl/gen/tmpl/c_uint_f_void.c +15 -0
- data/ext/numo/gsl/gen/tmpl/c_ulong_f_void.c +15 -0
- data/ext/numo/gsl/gen/tmpl/c_void_f_double.c +17 -0
- data/ext/numo/gsl/gen/tmpl/c_void_f_double_x2.c +18 -0
- data/ext/numo/gsl/gen/tmpl/c_void_f_double_x4.c +20 -0
- data/ext/numo/gsl/gen/tmpl/c_void_f_ulong.c +17 -0
- data/ext/numo/gsl/gen/tmpl/c_void_f_void.c +14 -0
- data/ext/numo/gsl/gen/tmpl/cast_1d_contiguous.c +15 -0
- data/ext/numo/gsl/gen/tmpl/cast_2d_contiguous.c +15 -0
- data/ext/numo/gsl/gen/tmpl/class.c +26 -0
- data/ext/numo/gsl/gen/tmpl/create_new_narray.c +26 -0
- data/ext/numo/gsl/gen/tmpl/init_class.c +10 -0
- data/ext/numo/gsl/gen/tmpl/init_module.c +12 -0
- data/ext/numo/gsl/gen/tmpl/lib.c +41 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_Int_f_DFloat.c +38 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat.c +35 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_Int.c +39 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_UInt.c +39 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_double.c +42 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_double_x2.c +47 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_int.c +42 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_x2.c +38 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_DFloat_x3.c +41 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_Int.c +36 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt.c +36 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt32.c +36 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt32_double.c +43 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt32_double_uint.c +49 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt32_double_x2.c +48 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt32_uint_x3.c +51 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt_double.c +43 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt_double_uint.c +50 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt_double_x2.c +48 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_UInt_uint_x3.c +51 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_int_DFloat.c +41 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_int_DFloat_x2.c +44 -0
- data/ext/numo/gsl/gen/tmpl/m_DFloat_f_int_x2_DFloat_x2.c +46 -0
- data/ext/numo/gsl/gen/tmpl/m_Int_f_DFloat.c +36 -0
- data/ext/numo/gsl/gen/tmpl/m_Int_f_DFloat_x3.c +42 -0
- data/ext/numo/gsl/gen/tmpl/m_Int_f_int_DFloat.c +42 -0
- data/ext/numo/gsl/gen/tmpl/m_Int_f_int_DFloat_x2.c +45 -0
- data/ext/numo/gsl/gen/tmpl/mod_func_noloop.c +54 -0
- data/ext/numo/gsl/gen/tmpl/mod_func_scalar.c +27 -0
- data/ext/numo/gsl/gen/tmpl/module.c +9 -0
- data/ext/numo/gsl/histogram/depend +17 -0
- data/ext/numo/gsl/histogram/erbpp_histogram.rb +109 -0
- data/ext/numo/gsl/histogram/extconf.rb +9 -0
- data/ext/numo/gsl/histogram/func_def.rb +763 -0
- data/ext/numo/gsl/histogram/tmpl/c_DFloat_f_2d_get.c +54 -0
- data/ext/numo/gsl/histogram/tmpl/c_DFloat_f_field.c +35 -0
- data/ext/numo/gsl/histogram/tmpl/c_DFloat_f_get.c +47 -0
- data/ext/numo/gsl/histogram/tmpl/c_DFloat_x2_f_get_range.c +56 -0
- data/ext/numo/gsl/histogram/tmpl/c_bool_f_other.c +19 -0
- data/ext/numo/gsl/histogram/tmpl/c_bool_f_pdf_init.c +24 -0
- data/ext/numo/gsl/histogram/tmpl/c_self_f_2d_set_ranges.c +26 -0
- data/ext/numo/gsl/histogram/tmpl/c_self_f_set_ranges.c +21 -0
- data/ext/numo/gsl/histogram/tmpl/c_sizet_f_field.c +15 -0
- data/ext/numo/gsl/interp/depend +17 -0
- data/ext/numo/gsl/interp/erbpp_interp.rb +59 -0
- data/ext/numo/gsl/interp/extconf.rb +9 -0
- data/ext/numo/gsl/interp/func_def.rb +816 -0
- data/ext/numo/gsl/interp/parse_interp.rb +67 -0
- data/ext/numo/gsl/interp/tmpl/interp2d_new.c +36 -0
- data/ext/numo/gsl/interp/tmpl/interp2d_type_new.c +17 -0
- data/ext/numo/gsl/interp/tmpl/interp_bsearch.c +57 -0
- data/ext/numo/gsl/interp/tmpl/interp_new.c +29 -0
- data/ext/numo/gsl/interp/tmpl/interp_type_new.c +16 -0
- data/ext/numo/gsl/interp/tmpl/spline2d_eval.c +61 -0
- data/ext/numo/gsl/interp/tmpl/spline_eval.c +55 -0
- data/ext/numo/gsl/interp/tmpl/spline_integ.c +56 -0
- data/ext/numo/gsl/interp/type_def.rb +9 -0
- data/ext/numo/gsl/multifit/depend +17 -0
- data/ext/numo/gsl/multifit/erbpp_multifit.rb +99 -0
- data/ext/numo/gsl/multifit/extconf.rb +9 -0
- data/ext/numo/gsl/multifit/func_2.1.rb +1035 -0
- data/ext/numo/gsl/multifit/func_2.2.1.rb +736 -0
- data/ext/numo/gsl/multifit/func_2.2.rb +736 -0
- data/ext/numo/gsl/multifit/func_2.3.rb +872 -0
- data/ext/numo/gsl/multifit/func_def.rb +1012 -0
- data/ext/numo/gsl/multifit/tmpl/multifit_linear.c +66 -0
- data/ext/numo/gsl/multifit/tmpl/multifit_linear_est.c +48 -0
- data/ext/numo/gsl/multifit/tmpl/multifit_linear_residuals.c +47 -0
- data/ext/numo/gsl/multifit/tmpl/multifit_wlinear.c +70 -0
- data/ext/numo/gsl/multifit/type_def.rb +1 -0
- data/ext/numo/gsl/numo_gsl.h +117 -0
- data/ext/numo/gsl/pdf/depend +17 -0
- data/ext/numo/gsl/pdf/erbpp_pdf.rb +26 -0
- data/ext/numo/gsl/pdf/extconf.rb +9 -0
- data/ext/numo/gsl/pdf/func_2.2.1.rb +306 -0
- data/ext/numo/gsl/pdf/func_2.2.rb +306 -0
- data/ext/numo/gsl/pdf/func_2.3.rb +306 -0
- data/ext/numo/gsl/pdf/func_def.rb +282 -0
- data/ext/numo/gsl/pdf/parse_pdf.rb +42 -0
- data/ext/numo/gsl/pdf/tmpl/dirichlet.c +39 -0
- data/ext/numo/gsl/pdf/tmpl/multinomial.c +39 -0
- data/ext/numo/gsl/poly/depend +17 -0
- data/ext/numo/gsl/poly/erbpp_poly.rb +70 -0
- data/ext/numo/gsl/poly/extconf.rb +9 -0
- data/ext/numo/gsl/poly/func_def.rb +234 -0
- data/ext/numo/gsl/poly/tmpl/poly_complex_solve.c +59 -0
- data/ext/numo/gsl/poly/tmpl/poly_eval.c +70 -0
- data/ext/numo/gsl/poly/tmpl/poly_eval_derivs.c +40 -0
- data/ext/numo/gsl/ran/depend +17 -0
- data/ext/numo/gsl/ran/erbpp_ran.rb +42 -0
- data/ext/numo/gsl/ran/extconf.rb +9 -0
- data/ext/numo/gsl/ran/func_2.2.1.rb +1658 -0
- data/ext/numo/gsl/ran/func_2.2.rb +1658 -0
- data/ext/numo/gsl/ran/func_2.3.rb +1658 -0
- data/ext/numo/gsl/ran/func_def.rb +1594 -0
- data/ext/numo/gsl/ran/parse_ran.rb +10 -0
- data/ext/numo/gsl/rng/depend +17 -0
- data/ext/numo/gsl/rng/erbpp_rng.rb +58 -0
- data/ext/numo/gsl/rng/extconf.rb +9 -0
- data/ext/numo/gsl/rng/func_def.rb +230 -0
- data/ext/numo/gsl/rng/parse_rng.rb +125 -0
- data/ext/numo/gsl/rng/tmpl/ran.c +40 -0
- data/ext/numo/gsl/rng/tmpl/ran_DFloat_f_DFloat.c +28 -0
- data/ext/numo/gsl/rng/tmpl/ran_DFloat_x2.c +45 -0
- data/ext/numo/gsl/rng/tmpl/ran_DFloat_x3.c +51 -0
- data/ext/numo/gsl/rng/tmpl/ran_multinomial.c +32 -0
- data/ext/numo/gsl/rng/tmpl/rng_DFloat.c +29 -0
- data/ext/numo/gsl/rng/tmpl/rng_UInt.c +44 -0
- data/ext/numo/gsl/rng/tmpl/rng_alloc.c +24 -0
- data/ext/numo/gsl/rng/tmpl/rng_type_new.c +14 -0
- data/ext/numo/gsl/rng/type_def.rb +63 -0
- data/ext/numo/gsl/rstat/depend +17 -0
- data/ext/numo/gsl/rstat/erbpp_rstat.rb +64 -0
- data/ext/numo/gsl/rstat/extconf.rb +9 -0
- data/ext/numo/gsl/rstat/func_2.2.1.rb +116 -0
- data/ext/numo/gsl/rstat/func_2.2.rb +116 -0
- data/ext/numo/gsl/rstat/func_2.3.rb +123 -0
- data/ext/numo/gsl/rstat/func_def.rb +102 -0
- data/ext/numo/gsl/sf/depend +17 -0
- data/ext/numo/gsl/sf/erbpp_sf.rb +51 -0
- data/ext/numo/gsl/sf/extconf.rb +9 -0
- data/ext/numo/gsl/sf/func_def.rb +4703 -0
- data/ext/numo/gsl/sf/parse_sf.rb +277 -0
- data/ext/numo/gsl/sf/tmpl/c_DFloat_f_int_x2_DFloat.c +50 -0
- data/ext/numo/gsl/sf/tmpl/c_DFloat_f_int_x2_DFloat_x2.c +52 -0
- data/ext/numo/gsl/sf/tmpl/c_DFloat_f_int_x3_DFloat_x2.c +55 -0
- data/ext/numo/gsl/sf/tmpl/m_DFloat_f_DFloat_mode.c +47 -0
- data/ext/numo/gsl/sf/tmpl/m_DFloat_f_lmax_array.c +41 -0
- data/ext/numo/gsl/sf/tmpl/m_DFloat_f_nmin_nmax_array.c +49 -0
- data/ext/numo/gsl/spmatrix/const_2.2.1.rb +3 -0
- data/ext/numo/gsl/spmatrix/const_2.2.rb +3 -0
- data/ext/numo/gsl/spmatrix/const_2.3.rb +3 -0
- data/ext/numo/gsl/spmatrix/const_def.rb +2 -0
- data/ext/numo/gsl/spmatrix/depend +17 -0
- data/ext/numo/gsl/spmatrix/erbpp_spmatrix.rb +100 -0
- data/ext/numo/gsl/spmatrix/extconf.rb +9 -0
- data/ext/numo/gsl/spmatrix/func_2.2.1.rb +297 -0
- data/ext/numo/gsl/spmatrix/func_2.2.rb +297 -0
- data/ext/numo/gsl/spmatrix/func_2.3.rb +297 -0
- data/ext/numo/gsl/spmatrix/func_def.rb +218 -0
- data/ext/numo/gsl/spmatrix/parse_spmatrix.rb +70 -0
- data/ext/numo/gsl/spmatrix/tmpl/itersolve_iterate.c +47 -0
- data/ext/numo/gsl/spmatrix/tmpl/itersolve_new.c +22 -0
- data/ext/numo/gsl/spmatrix/tmpl/itersolve_type_new.c +16 -0
- data/ext/numo/gsl/spmatrix/tmpl/spblas_dgemm.c +35 -0
- data/ext/numo/gsl/spmatrix/tmpl/spblas_dgemv.c +43 -0
- data/ext/numo/gsl/spmatrix/tmpl/spmatrix_add.c +22 -0
- data/ext/numo/gsl/spmatrix/tmpl/spmatrix_d2sp.c +28 -0
- data/ext/numo/gsl/spmatrix/tmpl/spmatrix_new.c +40 -0
- data/ext/numo/gsl/spmatrix/tmpl/spmatrix_sp2d.c +25 -0
- data/ext/numo/gsl/spmatrix/type_def.rb +1 -0
- data/ext/numo/gsl/stats/depend +17 -0
- data/ext/numo/gsl/stats/erbpp_stats.rb +29 -0
- data/ext/numo/gsl/stats/extconf.rb +9 -0
- data/ext/numo/gsl/stats/func_2.2.1.rb +608 -0
- data/ext/numo/gsl/stats/func_2.2.rb +608 -0
- data/ext/numo/gsl/stats/func_2.3.rb +608 -0
- data/ext/numo/gsl/stats/func_def.rb +608 -0
- data/ext/numo/gsl/stats/parse_stats.rb +63 -0
- data/ext/numo/gsl/stats/tmpl/stats_1a0p.c +37 -0
- data/ext/numo/gsl/stats/tmpl/stats_1a0p_index.c +60 -0
- data/ext/numo/gsl/stats/tmpl/stats_1a1p.c +41 -0
- data/ext/numo/gsl/stats/tmpl/stats_1a2p.c +42 -0
- data/ext/numo/gsl/stats/tmpl/stats_2a0p.c +39 -0
- data/ext/numo/gsl/stats/tmpl/stats_2a1p.c +43 -0
- data/ext/numo/gsl/stats/tmpl/stats_2a2p.c +44 -0
- data/ext/numo/gsl/stats/tmpl/stats_minmax.c +37 -0
- data/ext/numo/gsl/stats/tmpl/stats_minmax_index.c +67 -0
- data/ext/numo/gsl/stats/tmpl/stats_spearman.c +46 -0
- data/ext/numo/gsl/sys/const_def.rb +21 -0
- data/ext/numo/gsl/sys/depend +17 -0
- data/ext/numo/gsl/sys/enum_def.rb +75 -0
- data/ext/numo/gsl/sys/erbpp_sys.rb +60 -0
- data/ext/numo/gsl/sys/extconf.rb +9 -0
- data/ext/numo/gsl/sys/func_def.rb +249 -0
- data/ext/numo/gsl/version.h +1 -0
- data/ext/numo/gsl/wavelet/depend +17 -0
- data/ext/numo/gsl/wavelet/erbpp_wavelet.rb +48 -0
- data/ext/numo/gsl/wavelet/extconf.rb +9 -0
- data/ext/numo/gsl/wavelet/func_def.rb +337 -0
- data/ext/numo/gsl/wavelet/parse_wavelet.rb +47 -0
- data/ext/numo/gsl/wavelet/tmpl/wavelet2d_transform.c +56 -0
- data/ext/numo/gsl/wavelet/tmpl/wavelet_array_check.c +56 -0
- data/ext/numo/gsl/wavelet/tmpl/wavelet_macro.c +1 -0
- data/ext/numo/gsl/wavelet/tmpl/wavelet_new.c +20 -0
- data/ext/numo/gsl/wavelet/tmpl/wavelet_transform.c +55 -0
- data/ext/numo/gsl/wavelet/tmpl/wavelet_transform2.c +22 -0
- data/ext/numo/gsl/wavelet/tmpl/wavelet_type_new.c +15 -0
- data/ext/numo/gsl/wavelet/type_def.rb +6 -0
- data/lib/numo/gsl.rb +17 -0
- data/numo-gsl.gemspec +33 -0
- metadata +367 -0
@@ -0,0 +1 @@
|
|
1
|
+
src :
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <gsl/gsl_errno.h>
|
3
|
+
|
4
|
+
VALUE numo_eGslError;
|
5
|
+
|
6
|
+
static void
|
7
|
+
numo_gsl_err_hdl(const char *reason, const char *file, int line, int gsl_errno)
|
8
|
+
{
|
9
|
+
rb_raise(numo_eGslError,"%s:%d: %s",file,line,reason);
|
10
|
+
}
|
11
|
+
|
12
|
+
void
|
13
|
+
Init_err(void)
|
14
|
+
{
|
15
|
+
VALUE mNumo, mGSL;
|
16
|
+
|
17
|
+
mNumo = rb_define_module("Numo");
|
18
|
+
mGSL = rb_define_module_under(mNumo, "GSL");
|
19
|
+
numo_eGslError = rb_define_class_under(mGSL, "GslError", rb_eStandardError);
|
20
|
+
|
21
|
+
gsl_set_error_handler(&numo_gsl_err_hdl);
|
22
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rbconfig.rb'
|
2
|
+
require 'numo/narray'
|
3
|
+
require 'mkmf'
|
4
|
+
|
5
|
+
# configure options: --with-gsl-lib=path
|
6
|
+
#dir_config("gsl")
|
7
|
+
|
8
|
+
# check gsl-config command
|
9
|
+
print "checking for gsl-config... "
|
10
|
+
begin
|
11
|
+
gsl_libs = `gsl-config --libs`
|
12
|
+
rescue
|
13
|
+
puts "no"
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
puts "yes"
|
17
|
+
|
18
|
+
# parse GSL libs
|
19
|
+
libs = []
|
20
|
+
gsl_libs.split(/\s+/).each do |x|
|
21
|
+
case x
|
22
|
+
when /^-L(.+)/
|
23
|
+
$LIBPATH.push($1)
|
24
|
+
when /^-l(.+)/
|
25
|
+
libs.unshift($1)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# check library
|
30
|
+
libs.each do |x|
|
31
|
+
exit 1 unless have_library(x)
|
32
|
+
end
|
33
|
+
|
34
|
+
# GSL include files
|
35
|
+
$INCFLAGS = [`gsl-config --cflags`.chomp,$INCFLAGS].join(" ")
|
36
|
+
|
37
|
+
# check narray.h
|
38
|
+
$LOAD_PATH.each do |x|
|
39
|
+
if File.exist? File.join(x,'numo','numo/narray.h')
|
40
|
+
$INCFLAGS = "-I#{x}/numo " + $INCFLAGS
|
41
|
+
break
|
42
|
+
end
|
43
|
+
end
|
44
|
+
exit 1 unless have_header('numo/narray.h')
|
@@ -0,0 +1,17 @@
|
|
1
|
+
COGEN=ruby erbpp_fit.rb
|
2
|
+
GENSRC=gsl_fit.c
|
3
|
+
GENDEPS=erbpp_fit.rb ../gen/*.rb ../gen/tmpl/*.c tmpl/*.c
|
4
|
+
|
5
|
+
src : $(GENSRC)
|
6
|
+
|
7
|
+
$(GENSRC) : $(GENDEPS)
|
8
|
+
$(COGEN) $@
|
9
|
+
|
10
|
+
doc : $(GENSRC)
|
11
|
+
yard doc $(GENSRC)
|
12
|
+
|
13
|
+
clean: cleansrc cleandoc
|
14
|
+
cleansrc:
|
15
|
+
-$(Q)$(RM) $(GENSRC)
|
16
|
+
cleandoc:
|
17
|
+
-$(Q)$(RM_RF) doc .yardoc
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require_relative "../gen/func_parser"
|
2
|
+
require_relative "../gen/erbpp_gsl"
|
3
|
+
require "erbpp/line_number"
|
4
|
+
|
5
|
+
fit_list = ErbppGsl.read_func
|
6
|
+
|
7
|
+
class DefFit < DefModule
|
8
|
+
def lookup(h)
|
9
|
+
h[:func_name].sub(/^gsl_/,"")
|
10
|
+
end
|
11
|
+
def check_func(h)
|
12
|
+
if t = lookup(h)
|
13
|
+
if File.exist?("tmpl/#{t}.c")
|
14
|
+
m = h[:func_name].sub(/^gsl_#{name}_/,"")
|
15
|
+
Fit.new(self, t, name:m, **h)
|
16
|
+
return true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
$stderr.puts "skip #{h[:func_name]}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Fit < DefModuleFunction
|
24
|
+
def result
|
25
|
+
case func_name
|
26
|
+
when /_w?(linear|mul)$/
|
27
|
+
cls = (name+"_result").split(/_/).map{|x| x.capitalize}.join("")
|
28
|
+
set result_class: cls
|
29
|
+
"static VALUE c#{cls};\n"+super
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def init_def
|
35
|
+
if get(:result_class)
|
36
|
+
super+"
|
37
|
+
#{struct_def}"
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
def struct_def
|
43
|
+
vars = get(:args).select{|a| a[0]=="double *"}
|
44
|
+
items = vars.map{|a| "\"#{a[1]}\""}.join(",")
|
45
|
+
cls = get(:result_class)
|
46
|
+
"/*
|
47
|
+
Document-class: Numo::GSL::Fit::#{cls}
|
48
|
+
*/
|
49
|
+
c#{cls} = rb_struct_define_under(#{_mod_var},\"#{cls}\",#{items},NULL);"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
DefLib.new do
|
54
|
+
set erb_dir: %w[tmpl ../gen/tmpl]
|
55
|
+
set erb_suffix: ".c"
|
56
|
+
set ns_var: "mG"
|
57
|
+
|
58
|
+
name = "Fit"
|
59
|
+
set file_name: "gsl_#{name}.c"
|
60
|
+
set include_files: %w[gsl/gsl_fit.h]
|
61
|
+
set lib_name: name.downcase
|
62
|
+
|
63
|
+
DefFit.new(self) do
|
64
|
+
set name: name.downcase
|
65
|
+
set module_name: name
|
66
|
+
set module_var: "m"+name
|
67
|
+
set full_module_name: "Numo::GSL::"+name
|
68
|
+
|
69
|
+
fit_list.each do |h|
|
70
|
+
check_func(h)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end.write(ARGV[0])
|
@@ -0,0 +1,129 @@
|
|
1
|
+
[{:func_name=>"gsl_fit_linear",
|
2
|
+
:func_type=>"int",
|
3
|
+
:args=>
|
4
|
+
[["const double *", "x"],
|
5
|
+
["const size_t", "xstride"],
|
6
|
+
["const double *", "y"],
|
7
|
+
["const size_t", "ystride"],
|
8
|
+
["size_t", "n"],
|
9
|
+
["double *", "c0"],
|
10
|
+
["double *", "c1"],
|
11
|
+
["double *", "cov00"],
|
12
|
+
["double *", "cov01"],
|
13
|
+
["double *", "cov11"],
|
14
|
+
["double *", "sumsq"]],
|
15
|
+
:desc=>
|
16
|
+
"This function computes the best-fit linear regression coefficients\n" +
|
17
|
+
"(c0,c1) of the model Y = c_0 + c_1 X for the dataset\n" +
|
18
|
+
"(x, y), two vectors of length n with strides\n" +
|
19
|
+
"xstride and ystride. The errors on y are assumed unknown so \n" +
|
20
|
+
"the variance-covariance matrix for the\n" +
|
21
|
+
"parameters (c0, c1) is estimated from the scatter of the\n" +
|
22
|
+
"points around the best-fit line and returned via the parameters\n" +
|
23
|
+
"(cov00, cov01, cov11). \n" +
|
24
|
+
"The sum of squares of the residuals from the best-fit line is returned\n" +
|
25
|
+
"in sumsq. Note: the correlation coefficient of the data can be computed using gsl_stats_correlation (Correlation), it does not depend on the fit."},
|
26
|
+
{:func_name=>"gsl_fit_wlinear",
|
27
|
+
:func_type=>"int",
|
28
|
+
:args=>
|
29
|
+
[["const double *", "x"],
|
30
|
+
["const size_t", "xstride"],
|
31
|
+
["const double *", "w"],
|
32
|
+
["const size_t", "wstride"],
|
33
|
+
["const double *", "y"],
|
34
|
+
["const size_t", "ystride"],
|
35
|
+
["size_t", "n"],
|
36
|
+
["double *", "c0"],
|
37
|
+
["double *", "c1"],
|
38
|
+
["double *", "cov00"],
|
39
|
+
["double *", "cov01"],
|
40
|
+
["double *", "cov11"],
|
41
|
+
["double *", "chisq"]],
|
42
|
+
:desc=>
|
43
|
+
"This function computes the best-fit linear regression coefficients\n" +
|
44
|
+
"(c0,c1) of the model Y = c_0 + c_1 X for the weighted\n" +
|
45
|
+
"dataset (x, y), two vectors of length n with strides\n" +
|
46
|
+
"xstride and ystride. The vector w, of length n\n" +
|
47
|
+
"and stride wstride, specifies the weight of each datapoint. The\n" +
|
48
|
+
"weight is the reciprocal of the variance for each datapoint in y.\n" +
|
49
|
+
"\n" +
|
50
|
+
"The covariance matrix for the parameters (c0, c1) is\n" +
|
51
|
+
"computed using the weights and returned via the parameters\n" +
|
52
|
+
"(cov00, cov01, cov11). The weighted sum of squares\n" +
|
53
|
+
"of the residuals from the best-fit line, \\chi^2, is returned in\n" +
|
54
|
+
"chisq."},
|
55
|
+
{:func_name=>"gsl_fit_linear_est",
|
56
|
+
:func_type=>"int",
|
57
|
+
:args=>
|
58
|
+
[["double", "x"],
|
59
|
+
["double", "c0"],
|
60
|
+
["double", "c1"],
|
61
|
+
["double", "cov00"],
|
62
|
+
["double", "cov01"],
|
63
|
+
["double", "cov11"],
|
64
|
+
["double *", "y"],
|
65
|
+
["double *", "y_err"]],
|
66
|
+
:desc=>
|
67
|
+
"This function uses the best-fit linear regression coefficients\n" +
|
68
|
+
"c0, c1 and their covariance\n" +
|
69
|
+
"cov00, cov01, cov11 to compute the fitted function\n" +
|
70
|
+
"y and its standard deviation y_err for the model Y =\n" +
|
71
|
+
"c_0 + c_1 X at the point x."},
|
72
|
+
{:func_name=>"gsl_fit_mul",
|
73
|
+
:func_type=>"int",
|
74
|
+
:args=>
|
75
|
+
[["const double *", "x"],
|
76
|
+
["const size_t", "xstride"],
|
77
|
+
["const double *", "y"],
|
78
|
+
["const size_t", "ystride"],
|
79
|
+
["size_t", "n"],
|
80
|
+
["double *", "c1"],
|
81
|
+
["double *", "cov11"],
|
82
|
+
["double *", "sumsq"]],
|
83
|
+
:desc=>
|
84
|
+
"This function computes the best-fit linear regression coefficient\n" +
|
85
|
+
"c1 of the model Y = c_1 X for the datasets (x,\n" +
|
86
|
+
"y), two vectors of length n with strides xstride and\n" +
|
87
|
+
"ystride. The errors on y are assumed unknown so the \n" +
|
88
|
+
"variance of the parameter c1 is estimated from\n" +
|
89
|
+
"the scatter of the points around the best-fit line and returned via the\n" +
|
90
|
+
"parameter cov11. The sum of squares of the residuals from the\n" +
|
91
|
+
"best-fit line is returned in sumsq."},
|
92
|
+
{:func_name=>"gsl_fit_wmul",
|
93
|
+
:func_type=>"int",
|
94
|
+
:args=>
|
95
|
+
[["const double *", "x"],
|
96
|
+
["const size_t", "xstride"],
|
97
|
+
["const double *", "w"],
|
98
|
+
["const size_t", "wstride"],
|
99
|
+
["const double *", "y"],
|
100
|
+
["const size_t", "ystride"],
|
101
|
+
["size_t", "n"],
|
102
|
+
["double *", "c1"],
|
103
|
+
["double *", "cov11"],
|
104
|
+
["double *", "sumsq"]],
|
105
|
+
:desc=>
|
106
|
+
"This function computes the best-fit linear regression coefficient\n" +
|
107
|
+
"c1 of the model Y = c_1 X for the weighted datasets\n" +
|
108
|
+
"(x, y), two vectors of length n with strides\n" +
|
109
|
+
"xstride and ystride. The vector w, of length n\n" +
|
110
|
+
"and stride wstride, specifies the weight of each datapoint. The\n" +
|
111
|
+
"weight is the reciprocal of the variance for each datapoint in y.\n" +
|
112
|
+
"\n" +
|
113
|
+
"The variance of the parameter c1 is computed using the weights\n" +
|
114
|
+
"and returned via the parameter cov11. The weighted sum of\n" +
|
115
|
+
"squares of the residuals from the best-fit line, \\chi^2, is\n" +
|
116
|
+
"returned in chisq."},
|
117
|
+
{:func_name=>"gsl_fit_mul_est",
|
118
|
+
:func_type=>"int",
|
119
|
+
:args=>
|
120
|
+
[["double", "x"],
|
121
|
+
["double", "c1"],
|
122
|
+
["double", "cov11"],
|
123
|
+
["double *", "y"],
|
124
|
+
["double *", "y_err"]],
|
125
|
+
:desc=>
|
126
|
+
"This function uses the best-fit linear regression coefficient c1\n" +
|
127
|
+
"and its covariance cov11 to compute the fitted function\n" +
|
128
|
+
"y and its standard deviation y_err for the model Y =\n" +
|
129
|
+
"c_1 X at the point x."}]
|
@@ -0,0 +1,53 @@
|
|
1
|
+
static void
|
2
|
+
iter_<%=c_func%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t n;
|
5
|
+
char *p1,*p2;
|
6
|
+
double *p3,*p4,*p5,*p6,*p7,*p8;
|
7
|
+
ssize_t s1, s2;
|
8
|
+
|
9
|
+
n = lp->args[0].shape[0];
|
10
|
+
INIT_PTR(lp, 0, p1, s1);
|
11
|
+
INIT_PTR(lp, 1, p2, s2);
|
12
|
+
p3 = (double*)GET_PTR(lp,2);
|
13
|
+
p4 = (double*)GET_PTR(lp,3);
|
14
|
+
p5 = (double*)GET_PTR(lp,4);
|
15
|
+
p6 = (double*)GET_PTR(lp,5);
|
16
|
+
p7 = (double*)GET_PTR(lp,6);
|
17
|
+
p8 = (double*)GET_PTR(lp,7);
|
18
|
+
|
19
|
+
<%=func_name%>((double*)p1,s1/sizeof(double),
|
20
|
+
(double*)p2,s2/sizeof(double),
|
21
|
+
n,p3,p4,p5,p6,p7,p8);
|
22
|
+
}
|
23
|
+
|
24
|
+
/*
|
25
|
+
@overload <%=name%>(<%=args[0][1]%>,<%=args[2][1]%>)
|
26
|
+
@param [DFloat] <%=args[0][1]%> (input array)
|
27
|
+
@param [DFloat] <%=args[2][1]%> (input array)
|
28
|
+
@return [GSL::Fit::<%=result_class%>] result Struct with members: <%=args[5][1]%>, <%=args[6][1]%>, <%=args[7][1]%>, <%=args[8][1]%>, <%=args[9][1]%>, <%=args[10][1]%>.
|
29
|
+
|
30
|
+
<%=desc%>
|
31
|
+
|
32
|
+
*/
|
33
|
+
static VALUE
|
34
|
+
<%=c_func(2)%>(VALUE mod, VALUE v1, VALUE v2)
|
35
|
+
{
|
36
|
+
VALUE r, result;
|
37
|
+
ndfunc_arg_in_t ain[2] = {{cDF,1},{cDF,1}};
|
38
|
+
ndfunc_arg_out_t aout[6] = {{cDF,0},{cDF,0},{cDF,0},{cDF,0},{cDF,0},{cDF,0}};
|
39
|
+
ndfunc_t ndf = { iter_<%=c_func%>, NO_LOOP|NDF_EXTRACT,
|
40
|
+
2, 6, ain, aout };
|
41
|
+
narray_t *x, *y;
|
42
|
+
|
43
|
+
GetNArray(v1,x);
|
44
|
+
GetNArray(v2,y);
|
45
|
+
CHECK_GE_1D(x);
|
46
|
+
CHECK_GE_1D(y);
|
47
|
+
CHECK_SIZE_EQ(VEC_SIZE(x),VEC_SIZE(y),"x size does not match y size");
|
48
|
+
|
49
|
+
r = na_ndloop(&ndf, 2, v1, v2);
|
50
|
+
result = rb_class_new_instance(6, RARRAY_PTR(r), c<%=result_class%>);
|
51
|
+
RB_GC_GUARD(r);
|
52
|
+
return result;
|
53
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
static void
|
2
|
+
iter_<%=c_func%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8;
|
6
|
+
ssize_t s1, s2, s3, s4, s5, s6, s7, s8;
|
7
|
+
double x,c0,c1,cov00,cov01,cov11,y,ye;
|
8
|
+
|
9
|
+
INIT_COUNTER(lp, i);
|
10
|
+
INIT_PTR(lp, 0, p1, s1);
|
11
|
+
INIT_PTR(lp, 1, p2, s2);
|
12
|
+
INIT_PTR(lp, 2, p3, s3);
|
13
|
+
INIT_PTR(lp, 3, p4, s4);
|
14
|
+
INIT_PTR(lp, 4, p5, s5);
|
15
|
+
INIT_PTR(lp, 5, p6, s6);
|
16
|
+
INIT_PTR(lp, 6, p7, s7);
|
17
|
+
INIT_PTR(lp, 7, p8, s8);
|
18
|
+
|
19
|
+
for (; i--; ) {
|
20
|
+
GET_DATA_STRIDE(p1,s1,double,x);
|
21
|
+
GET_DATA_STRIDE(p2,s2,double,c0);
|
22
|
+
GET_DATA_STRIDE(p3,s3,double,c1);
|
23
|
+
GET_DATA_STRIDE(p4,s4,double,cov00);
|
24
|
+
GET_DATA_STRIDE(p5,s5,double,cov01);
|
25
|
+
GET_DATA_STRIDE(p6,s6,double,cov11);
|
26
|
+
<%=func_name%>(x, c0, c1, cov00, cov01, cov11, &y, &ye);
|
27
|
+
SET_DATA_STRIDE(p7,s7,double,y);
|
28
|
+
SET_DATA_STRIDE(p8,s8,double,ye);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
/*
|
33
|
+
@overload <%=name%>(<%=args[0][1]%>,linear_result)
|
34
|
+
@param [DFloat] <%=args[0][1]%>
|
35
|
+
@param [(L|Wl)inearResult] linear_result Result of GSL::Fit.linear|wlinear
|
36
|
+
@return [[DFloat,DFloat]] array of (<%=args[6][1]%>, <%=args[7][1]%>).
|
37
|
+
|
38
|
+
<%=desc%>
|
39
|
+
|
40
|
+
*/
|
41
|
+
static VALUE
|
42
|
+
<%=c_func(2)%>(VALUE mod, VALUE v1, VALUE v2)
|
43
|
+
{
|
44
|
+
ndfunc_arg_in_t ain[6] = {{cDF,0},{cDF,0},{cDF,0},{cDF,0},{cDF,0},{cDF,0}};
|
45
|
+
ndfunc_arg_out_t aout[2] = {{cDF,0},{cDF,0}};
|
46
|
+
ndfunc_t ndf = { iter_<%=c_func%>, STRIDE_LOOP_NIP|NDF_EXTRACT,
|
47
|
+
6, 2, ain, aout };
|
48
|
+
VALUE c0, c1, cov00, cov01, cov11;
|
49
|
+
|
50
|
+
c0 = RSTRUCT_GET(v2,0);
|
51
|
+
c1 = RSTRUCT_GET(v2,1);
|
52
|
+
cov00 = RSTRUCT_GET(v2,2);
|
53
|
+
cov01 = RSTRUCT_GET(v2,3);
|
54
|
+
cov11 = RSTRUCT_GET(v2,4);
|
55
|
+
return na_ndloop(&ndf, 6, v1, c0, c1, cov00, cov01, cov11);
|
56
|
+
}
|