romanbsd-gsl 1.11.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. data/README.rdoc +29 -0
  2. data/Rakefile +54 -0
  3. data/VERSION +1 -0
  4. data/ext/MANIFEST +116 -0
  5. data/ext/array.c +665 -0
  6. data/ext/array_complex.c +247 -0
  7. data/ext/blas.c +29 -0
  8. data/ext/blas1.c +729 -0
  9. data/ext/blas2.c +1093 -0
  10. data/ext/blas3.c +881 -0
  11. data/ext/block.c +44 -0
  12. data/ext/block_source.c +885 -0
  13. data/ext/bspline.c +116 -0
  14. data/ext/bundle.c +3 -0
  15. data/ext/cdf.c +754 -0
  16. data/ext/cheb.c +538 -0
  17. data/ext/combination.c +283 -0
  18. data/ext/common.c +310 -0
  19. data/ext/complex.c +1005 -0
  20. data/ext/const.c +668 -0
  21. data/ext/const_additional.c +120 -0
  22. data/ext/cqp.c +283 -0
  23. data/ext/deriv.c +194 -0
  24. data/ext/dht.c +360 -0
  25. data/ext/diff.c +165 -0
  26. data/ext/dirac.c +395 -0
  27. data/ext/eigen.c +2373 -0
  28. data/ext/error.c +194 -0
  29. data/ext/extconf.rb +272 -0
  30. data/ext/fcmp.c +66 -0
  31. data/ext/fft.c +1092 -0
  32. data/ext/fit.c +205 -0
  33. data/ext/fresnel.c +312 -0
  34. data/ext/function.c +522 -0
  35. data/ext/graph.c +1634 -0
  36. data/ext/gsl.c +265 -0
  37. data/ext/gsl_narray.c +652 -0
  38. data/ext/histogram.c +1717 -0
  39. data/ext/histogram2d.c +1067 -0
  40. data/ext/histogram3d.c +883 -0
  41. data/ext/histogram3d_source.c +750 -0
  42. data/ext/histogram_find.c +101 -0
  43. data/ext/histogram_oper.c +159 -0
  44. data/ext/ieee.c +98 -0
  45. data/ext/integration.c +1138 -0
  46. data/ext/interp.c +511 -0
  47. data/ext/jacobi.c +737 -0
  48. data/ext/linalg.c +4045 -0
  49. data/ext/linalg_complex.c +743 -0
  50. data/ext/math.c +724 -0
  51. data/ext/matrix.c +39 -0
  52. data/ext/matrix_complex.c +1731 -0
  53. data/ext/matrix_double.c +560 -0
  54. data/ext/matrix_int.c +256 -0
  55. data/ext/matrix_source.c +2678 -0
  56. data/ext/min.c +234 -0
  57. data/ext/monte.c +759 -0
  58. data/ext/multifit.c +1810 -0
  59. data/ext/multimin.c +793 -0
  60. data/ext/multimin_fsdf.c +156 -0
  61. data/ext/multiroots.c +952 -0
  62. data/ext/ndlinear.c +320 -0
  63. data/ext/nmf.c +159 -0
  64. data/ext/nmf_wrap.c +63 -0
  65. data/ext/ntuple.c +469 -0
  66. data/ext/odeiv.c +958 -0
  67. data/ext/ool.c +879 -0
  68. data/ext/oper_complex_source.c +253 -0
  69. data/ext/permutation.c +596 -0
  70. data/ext/poly.c +42 -0
  71. data/ext/poly2.c +265 -0
  72. data/ext/poly_source.c +1799 -0
  73. data/ext/qrng.c +171 -0
  74. data/ext/randist.c +1869 -0
  75. data/ext/rational.c +480 -0
  76. data/ext/rng.c +612 -0
  77. data/ext/root.c +408 -0
  78. data/ext/sf.c +1494 -0
  79. data/ext/sf_airy.c +200 -0
  80. data/ext/sf_bessel.c +867 -0
  81. data/ext/sf_clausen.c +28 -0
  82. data/ext/sf_coulomb.c +206 -0
  83. data/ext/sf_coupling.c +118 -0
  84. data/ext/sf_dawson.c +29 -0
  85. data/ext/sf_debye.c +157 -0
  86. data/ext/sf_dilog.c +42 -0
  87. data/ext/sf_elementary.c +44 -0
  88. data/ext/sf_ellint.c +206 -0
  89. data/ext/sf_elljac.c +29 -0
  90. data/ext/sf_erfc.c +93 -0
  91. data/ext/sf_exp.c +164 -0
  92. data/ext/sf_expint.c +211 -0
  93. data/ext/sf_fermi_dirac.c +148 -0
  94. data/ext/sf_gamma.c +344 -0
  95. data/ext/sf_gegenbauer.c +96 -0
  96. data/ext/sf_hyperg.c +197 -0
  97. data/ext/sf_laguerre.c +112 -0
  98. data/ext/sf_lambert.c +47 -0
  99. data/ext/sf_legendre.c +367 -0
  100. data/ext/sf_log.c +104 -0
  101. data/ext/sf_mathieu.c +238 -0
  102. data/ext/sf_power.c +46 -0
  103. data/ext/sf_psi.c +98 -0
  104. data/ext/sf_synchrotron.c +48 -0
  105. data/ext/sf_transport.c +76 -0
  106. data/ext/sf_trigonometric.c +207 -0
  107. data/ext/sf_zeta.c +119 -0
  108. data/ext/signal.c +310 -0
  109. data/ext/siman.c +718 -0
  110. data/ext/sort.c +208 -0
  111. data/ext/spline.c +393 -0
  112. data/ext/stats.c +799 -0
  113. data/ext/sum.c +168 -0
  114. data/ext/tamu_anova.c +56 -0
  115. data/ext/tensor.c +38 -0
  116. data/ext/tensor_source.c +1121 -0
  117. data/ext/vector.c +38 -0
  118. data/ext/vector_complex.c +2139 -0
  119. data/ext/vector_double.c +1445 -0
  120. data/ext/vector_int.c +204 -0
  121. data/ext/vector_source.c +3325 -0
  122. data/ext/wavelet.c +937 -0
  123. data/include/rb_gsl.h +140 -0
  124. data/include/rb_gsl_array.h +230 -0
  125. data/include/rb_gsl_cheb.h +21 -0
  126. data/include/rb_gsl_common.h +343 -0
  127. data/include/rb_gsl_complex.h +25 -0
  128. data/include/rb_gsl_const.h +29 -0
  129. data/include/rb_gsl_dirac.h +15 -0
  130. data/include/rb_gsl_eigen.h +17 -0
  131. data/include/rb_gsl_fft.h +62 -0
  132. data/include/rb_gsl_fit.h +25 -0
  133. data/include/rb_gsl_function.h +27 -0
  134. data/include/rb_gsl_graph.h +70 -0
  135. data/include/rb_gsl_histogram.h +65 -0
  136. data/include/rb_gsl_histogram3d.h +97 -0
  137. data/include/rb_gsl_integration.h +17 -0
  138. data/include/rb_gsl_interp.h +46 -0
  139. data/include/rb_gsl_linalg.h +25 -0
  140. data/include/rb_gsl_math.h +26 -0
  141. data/include/rb_gsl_odeiv.h +21 -0
  142. data/include/rb_gsl_poly.h +71 -0
  143. data/include/rb_gsl_rational.h +37 -0
  144. data/include/rb_gsl_rng.h +21 -0
  145. data/include/rb_gsl_root.h +22 -0
  146. data/include/rb_gsl_sf.h +119 -0
  147. data/include/rb_gsl_statistics.h +17 -0
  148. data/include/rb_gsl_tensor.h +45 -0
  149. data/include/rb_gsl_with_narray.h +22 -0
  150. data/include/templates_off.h +87 -0
  151. data/include/templates_on.h +241 -0
  152. data/lib/gsl/gnuplot.rb +41 -0
  153. data/lib/gsl/oper.rb +68 -0
  154. data/lib/ool.rb +22 -0
  155. data/lib/ool/conmin.rb +30 -0
  156. metadata +221 -0
data/ext/combination.c ADDED
@@ -0,0 +1,283 @@
1
+ /*
2
+ combination.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2004 by Yoshiki Tsunesada
5
+
6
+ Ruby/GSL is free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License.
8
+ This library is distributed in the hope that it will be useful, but
9
+ WITHOUT ANY WARRANTY.
10
+ */
11
+
12
+ #include "rb_gsl_config.h"
13
+ #ifdef GSL_1_1_LATER
14
+ #include "rb_gsl_common.h"
15
+ #include "rb_gsl_array.h"
16
+
17
+ static VALUE cgsl_combination_data;
18
+
19
+ static VALUE rb_gsl_combination_new(VALUE klass, VALUE n, VALUE k)
20
+ {
21
+ gsl_combination *c = NULL;
22
+ CHECK_FIXNUM(n);CHECK_FIXNUM(k);
23
+ c = gsl_combination_alloc(FIX2INT(n), FIX2INT(k));
24
+ return Data_Wrap_Struct(klass, 0, gsl_combination_free, c);
25
+ }
26
+
27
+ static VALUE rb_gsl_combination_calloc(VALUE klass, VALUE n, VALUE k)
28
+ {
29
+ gsl_combination *c = NULL;
30
+ CHECK_FIXNUM(n);CHECK_FIXNUM(k);
31
+ c = gsl_combination_calloc(FIX2INT(n), FIX2INT(k));
32
+ return Data_Wrap_Struct(klass, 0, gsl_combination_free, c);
33
+ }
34
+
35
+ static VALUE rb_gsl_combination_init_first(VALUE obj)
36
+ {
37
+ gsl_combination *c = NULL;
38
+ Data_Get_Struct(obj, gsl_combination, c);
39
+ gsl_combination_init_first(c);
40
+ return obj;
41
+ }
42
+
43
+ static VALUE rb_gsl_combination_init_last(VALUE obj)
44
+ {
45
+ gsl_combination *c = NULL;
46
+ Data_Get_Struct(obj, gsl_combination, c);
47
+ gsl_combination_init_last(c);
48
+ return obj;
49
+ }
50
+
51
+ #ifdef GSL_1_4_LATER
52
+ /* singleton */
53
+ static VALUE rb_gsl_combination_memcpy(VALUE klass, VALUE dst, VALUE src)
54
+ {
55
+ gsl_combination *c, *c2;
56
+ if (!rb_obj_is_kind_of(dst, klass))
57
+ rb_raise(rb_eTypeError, "wrong argument type %s (Combination expected)",
58
+ rb_class2name(CLASS_OF(dst)));
59
+ if (!rb_obj_is_kind_of(src, klass))
60
+ rb_raise(rb_eTypeError, "wrong argument type %s (Combination expected)",
61
+ rb_class2name(CLASS_OF(src)));
62
+
63
+ Data_Get_Struct(dst, gsl_combination, c2);
64
+ Data_Get_Struct(src, gsl_combination, c);
65
+ gsl_combination_memcpy(c2, c);
66
+ return dst;
67
+ }
68
+
69
+ static VALUE rb_gsl_combination_clone(VALUE obj)
70
+ {
71
+ gsl_combination *c, *c2;
72
+ Data_Get_Struct(obj, gsl_combination, c);
73
+ c2 = gsl_combination_alloc(c->n, c->k);
74
+ gsl_combination_memcpy(c2, c);
75
+ return Data_Wrap_Struct(CLASS_OF(obj), 0, gsl_combination_free, c2);
76
+ }
77
+ #endif
78
+
79
+ static VALUE rb_gsl_combination_get(VALUE obj, VALUE ii)
80
+ {
81
+ gsl_combination *c = NULL;
82
+ size_t i;
83
+ CHECK_FIXNUM(ii);
84
+ Data_Get_Struct(obj, gsl_combination, c);
85
+ i = FIX2INT(ii);
86
+ if (i > c->n) rb_raise(rb_eIndexError, "index out of range");
87
+ return INT2FIX(gsl_combination_get(c, i));
88
+ }
89
+
90
+ static VALUE rb_gsl_combination_set(VALUE obj, VALUE ii, VALUE val)
91
+ {
92
+ gsl_combination *c = NULL;
93
+ size_t i;
94
+ CHECK_FIXNUM(ii);
95
+ CHECK_FIXNUM(val);
96
+ Data_Get_Struct(obj, gsl_combination, c);
97
+ i = FIX2INT(ii);
98
+ c->data[i] = FIX2INT(val);
99
+ return obj;
100
+ }
101
+
102
+ static VALUE rb_gsl_combination_n(VALUE obj)
103
+ {
104
+ gsl_combination *c = NULL;
105
+ Data_Get_Struct(obj, gsl_combination, c);
106
+ return INT2FIX(gsl_combination_n(c));
107
+
108
+ }
109
+ static VALUE rb_gsl_combination_k(VALUE obj)
110
+ {
111
+ gsl_combination *c = NULL;
112
+ Data_Get_Struct(obj, gsl_combination, c);
113
+ return INT2FIX(gsl_combination_k(c));
114
+ }
115
+
116
+ static VALUE rb_gsl_combination_data(VALUE obj)
117
+ {
118
+ gsl_combination *c = NULL;
119
+ gsl_permutation *p = NULL;
120
+ Data_Get_Struct(obj, gsl_combination, c);
121
+ p = ALLOC(gsl_permutation);
122
+ p->size = c->k;
123
+ p->data = c->data;
124
+ return Data_Wrap_Struct(cgsl_combination_data, 0, free, p);
125
+ }
126
+
127
+ static VALUE rb_gsl_combination_valid(VALUE obj)
128
+ {
129
+ gsl_combination *c = NULL;
130
+ Data_Get_Struct(obj, gsl_combination, c);
131
+ return INT2FIX(gsl_combination_valid(c));
132
+ }
133
+
134
+ static VALUE rb_gsl_combination_valid2(VALUE obj)
135
+ {
136
+ gsl_combination *c = NULL;
137
+ Data_Get_Struct(obj, gsl_combination, c);
138
+ if(gsl_combination_valid(c)) return Qtrue;
139
+ else return Qfalse;
140
+ }
141
+
142
+ static VALUE rb_gsl_combination_next(VALUE obj)
143
+ {
144
+ gsl_combination *c = NULL;
145
+ Data_Get_Struct(obj, gsl_combination, c);
146
+ return INT2FIX(gsl_combination_next(c));
147
+ }
148
+ static VALUE rb_gsl_combination_prev(VALUE obj)
149
+ {
150
+ gsl_combination *c = NULL;
151
+ Data_Get_Struct(obj, gsl_combination, c);
152
+ return INT2FIX(gsl_combination_prev(c));
153
+ }
154
+
155
+ static VALUE rb_gsl_combination_fwrite(VALUE obj, VALUE io)
156
+ {
157
+ gsl_combination *h = NULL;
158
+ FILE *f = NULL;
159
+ int status, flag = 0;
160
+ Data_Get_Struct(obj, gsl_combination, h);
161
+ f = rb_gsl_open_writefile(io, &flag);
162
+ status = gsl_combination_fwrite(f, h);
163
+ if (flag == 1) fclose(f);
164
+ return INT2FIX(status);
165
+ }
166
+
167
+ static VALUE rb_gsl_combination_fread(VALUE obj, VALUE io)
168
+ {
169
+ gsl_combination *h = NULL;
170
+ FILE *f = NULL;
171
+ int status, flag = 0;
172
+
173
+ Data_Get_Struct(obj, gsl_combination, h);
174
+ f = rb_gsl_open_readfile(io, &flag);
175
+ status = gsl_combination_fread(f, h);
176
+ if (flag == 1) fclose(f);
177
+ return INT2FIX(status);
178
+ }
179
+
180
+ static VALUE rb_gsl_combination_fprintf(int argc, VALUE *argv, VALUE obj)
181
+ {
182
+ gsl_combination *h = NULL;
183
+ FILE *fp = NULL;
184
+ int status, flag = 0;
185
+
186
+ if (argc != 1 && argc != 2) rb_raise(rb_eArgError,
187
+ "wrong number of arguments (%d for 1 or 2)", argc);
188
+
189
+ Data_Get_Struct(obj, gsl_combination, h);
190
+ fp = rb_gsl_open_writefile(argv[0], &flag);
191
+ switch (argc) {
192
+ case 1:
193
+ status = gsl_combination_fprintf(fp, h, "%u\n");
194
+ break;
195
+ default:
196
+ Check_Type(argv[1], T_STRING);
197
+ status = gsl_combination_fprintf(fp, h, STR2CSTR(argv[1]));
198
+ break;
199
+ }
200
+ if (flag == 1) fclose(fp);
201
+ return INT2FIX(status);
202
+ }
203
+
204
+ static VALUE rb_gsl_combination_printf(int argc, VALUE *argv, VALUE obj)
205
+ {
206
+ gsl_combination *h = NULL;
207
+ int status;
208
+ Data_Get_Struct(obj, gsl_combination, h);
209
+ switch (argc) {
210
+ case 0:
211
+ status = gsl_combination_fprintf(stdout, h, "%u\n");
212
+ break;
213
+ default:
214
+ Check_Type(argv[0], T_STRING);
215
+ status = gsl_combination_fprintf(stdout, h, STR2CSTR(argv[0]));
216
+ break;
217
+ }
218
+ return INT2FIX(status);
219
+ }
220
+
221
+
222
+ static VALUE rb_gsl_combination_fscanf(VALUE obj, VALUE io)
223
+ {
224
+ gsl_combination *h = NULL;
225
+ FILE *f = NULL;
226
+ int status, flag = 0;
227
+ Data_Get_Struct(obj, gsl_combination, h);
228
+ f = rb_gsl_open_readfile(io, &flag);
229
+ status = gsl_combination_fscanf(f, h);
230
+ if (flag == 1) fclose(f);
231
+ return INT2FIX(status);
232
+ }
233
+
234
+ static VALUE rb_gsl_combination_equal(VALUE obj, VALUE other)
235
+ {
236
+ gsl_combination *p1 = NULL, *p2 = NULL;
237
+ size_t i;
238
+ Data_Get_Struct(obj, gsl_combination, p1);
239
+ Data_Get_Struct(other, gsl_combination, p2);
240
+ if (p1->k != p2->k) return Qfalse;
241
+ for (i = 0; i < p1->k; i++)
242
+ if (p1->data[i] != p2->data[i]) return Qfalse;
243
+ return Qtrue;
244
+ }
245
+
246
+ void Init_gsl_combination(VALUE module)
247
+ {
248
+ VALUE cgsl_combination;
249
+ cgsl_combination = rb_define_class_under(module, "Combination", cGSL_Object);
250
+ cgsl_combination_data = rb_define_class_under(cgsl_combination, "Data",
251
+ cgsl_permutation);
252
+ rb_define_singleton_method(cgsl_combination, "new", rb_gsl_combination_new, 2);
253
+ rb_define_singleton_method(cgsl_combination, "alloc", rb_gsl_combination_new, 2);
254
+ rb_define_singleton_method(cgsl_combination, "calloc", rb_gsl_combination_calloc, 2);
255
+ rb_define_method(cgsl_combination, "init_first", rb_gsl_combination_init_first, 0);
256
+ rb_define_method(cgsl_combination, "init_last", rb_gsl_combination_init_last, 0);
257
+ #ifdef GSL_1_4_LATER
258
+ rb_define_singleton_method(cgsl_combination, "memcpy", rb_gsl_combination_memcpy, 2);
259
+ rb_define_method(cgsl_combination, "clone", rb_gsl_combination_clone, 0);
260
+ #endif
261
+ rb_define_method(cgsl_combination, "get", rb_gsl_combination_get, 1);
262
+ rb_define_alias(cgsl_combination, "[]", "get");
263
+ rb_define_method(cgsl_combination, "set", rb_gsl_combination_set, 2);
264
+ rb_define_alias(cgsl_combination, "[]=", "set");
265
+
266
+ rb_define_method(cgsl_combination, "n", rb_gsl_combination_n, 0);
267
+ rb_define_method(cgsl_combination, "k", rb_gsl_combination_k, 0);
268
+ rb_define_method(cgsl_combination, "data", rb_gsl_combination_data, 0);
269
+ rb_define_method(cgsl_combination, "valid", rb_gsl_combination_valid, 0);
270
+ rb_define_method(cgsl_combination, "valid?", rb_gsl_combination_valid2, 0);
271
+ rb_define_method(cgsl_combination, "next", rb_gsl_combination_next, 0);
272
+ rb_define_method(cgsl_combination, "prev", rb_gsl_combination_prev, 0);
273
+
274
+ rb_define_method(cgsl_combination, "fwrite", rb_gsl_combination_fwrite, 1);
275
+ rb_define_method(cgsl_combination, "fread", rb_gsl_combination_fread, 1);
276
+ rb_define_method(cgsl_combination, "fprintf", rb_gsl_combination_fprintf, -1);
277
+ rb_define_method(cgsl_combination, "printf", rb_gsl_combination_printf, -1);
278
+ rb_define_method(cgsl_combination, "fscanf", rb_gsl_combination_fscanf, 1);
279
+
280
+ rb_define_method(cgsl_combination, "equal?", rb_gsl_combination_equal, 1);
281
+ rb_define_alias(cgsl_combination, "==", "equal?");
282
+ }
283
+ #endif
data/ext/common.c ADDED
@@ -0,0 +1,310 @@
1
+ /*
2
+ common.c
3
+ Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
4
+ (C) Copyright 2001-2006 by Yoshiki Tsunesada
5
+
6
+ Ruby/GSL is free software: you can redistribute it and/or modify it
7
+ under the terms of the GNU General Public License.
8
+ This library is distributed in the hope that it will be useful, but
9
+ WITHOUT ANY WARRANTY.
10
+ */
11
+
12
+ #include "rb_gsl_config.h"
13
+
14
+ #include "rb_gsl_array.h"
15
+ #include "rb_gsl_histogram.h"
16
+ #include <string.h>
17
+ #include <ctype.h>
18
+
19
+ FILE* rb_gsl_open_writefile(VALUE io, int *flag)
20
+ {
21
+ #ifdef RUBY_1_9_LATER
22
+ rb_io_t *fptr = NULL;
23
+ #else
24
+ OpenFile *fptr = NULL;
25
+ #endif
26
+ FILE *fp = NULL;
27
+ char *name;
28
+ switch (TYPE(io)) {
29
+ case T_STRING:
30
+ name = RSTRING_PTR(io);
31
+ fp = fopen(name, "w");
32
+ *flag = 1;
33
+ break;
34
+ case T_FILE:
35
+ GetOpenFile(io, fptr);
36
+ name = fptr->path;
37
+ rb_io_check_writable(fptr);
38
+ #ifdef RUBY_1_9_LATER
39
+ fp = rb_io_stdio_file(fptr);
40
+ #else
41
+ fp = GetWriteFile(fptr);
42
+ #endif
43
+ *flag = 0;
44
+ break;
45
+ default:
46
+ rb_raise(rb_eTypeError, "argv 1 String or File expected");
47
+ break;
48
+ }
49
+ if (fp == NULL) rb_raise(rb_eIOError, "Cannot open file %s.", name);
50
+ return fp;
51
+ }
52
+
53
+ FILE* rb_gsl_open_readfile(VALUE io, int *flag)
54
+ {
55
+ #ifdef RUBY_1_9_LATER
56
+ rb_io_t *fptr = NULL;
57
+ #else
58
+ OpenFile *fptr = NULL;
59
+ #endif
60
+ FILE *fp = NULL;
61
+ char *name;
62
+ switch (TYPE(io)) {
63
+ case T_STRING:
64
+ name = RSTRING_PTR(io);
65
+ fp = fopen(name, "r");
66
+ *flag = 1;
67
+ break;
68
+ case T_FILE:
69
+ GetOpenFile(io, fptr);
70
+ name = fptr->path;
71
+ rb_io_check_readable(fptr);
72
+ #ifdef RUBY_1_9_LATER
73
+ fp = rb_io_stdio_file(fptr);
74
+ #else
75
+ fp = fptr->f;
76
+ #endif
77
+ *flag = 0;
78
+ break;
79
+ default:
80
+ rb_raise(rb_eTypeError, "argv 1 String or File expected");
81
+ break;
82
+ }
83
+ if (fp == NULL) rb_raise(rb_eIOError, "Cannot open file %s.", name);
84
+ return fp;
85
+ }
86
+
87
+ VALUE rb_gsl_obj_read_only(int argc, VALUE *argv, VALUE obj)
88
+ {
89
+ rb_raise(rb_eRuntimeError, "Read only object.");
90
+ }
91
+
92
+ int str_tail_grep(const char *s0, const char *s1)
93
+ {
94
+ int len0, len1;
95
+ char *p = NULL;
96
+ len0 = strlen(s0);
97
+ len1 = strlen(s1);
98
+ p = (char *) s0 + len0 - len1;
99
+ return strcmp(p, s1);
100
+ }
101
+
102
+ int str_head_grep(const char *s0, const char *s1)
103
+ {
104
+ int len0, len1;
105
+ size_t i, len;
106
+ char *p0, *p1;
107
+ len0 = strlen(s0);
108
+ len1 = strlen(s1);
109
+ len = (size_t) GSL_MIN_INT(len0, len1);
110
+ p0 = (char *) s0;
111
+ p1 = (char *) s1;
112
+ for (i = 0; i < len; i++) if (*p0++ != *p1++) return 1;
113
+ return 0;
114
+ }
115
+
116
+ size_t count_columns(const char *str)
117
+ {
118
+ size_t n = 0;
119
+ int flag = 1;
120
+ char *p;
121
+ p = (char *) str;
122
+ do {
123
+ if (isspace(*p)) {
124
+ flag = 1;
125
+ } else {
126
+ if (flag == 1) {
127
+ flag = 0;
128
+ n++;
129
+ }
130
+ }
131
+ p++;
132
+ } while (*p != '\0' && *p != '\n');
133
+ return n;
134
+ }
135
+
136
+ char* str_scan_double(const char *str, double *val)
137
+ {
138
+ char buf[256];
139
+ char *p, *q;
140
+ double x;
141
+ int flag = 0;
142
+ p = (char *) str;
143
+ q = buf;
144
+ do {
145
+ if (isspace(*p)) {
146
+ if (flag == 0) {
147
+ /* do nothing */
148
+ } else {
149
+ break;
150
+ }
151
+ } else {
152
+ *q++ = *p;
153
+ flag = 1;
154
+ }
155
+ p++;
156
+ } while (*p != '\0' && *p != '\n');
157
+ if (flag == 0) {
158
+ *val = 0;
159
+ return NULL;
160
+ }
161
+ *q = '\0';
162
+ flag = sscanf(buf, "%lf", &x);
163
+ if (flag == 1) {
164
+ *val = x;
165
+ return p;
166
+ } else {
167
+ *val = 0;
168
+ return NULL;
169
+ }
170
+ }
171
+
172
+ char* str_scan_int(const char *str, int *val)
173
+ {
174
+ char buf[256];
175
+ char *p, *q;
176
+ int x;
177
+ int flag = 0;
178
+ p = (char *) str;
179
+ q = buf;
180
+ do {
181
+ if (isspace(*p)) {
182
+ if (flag == 0) {
183
+ /* do nothing */
184
+ } else {
185
+ break;
186
+ }
187
+ } else {
188
+ *q++ = *p;
189
+ flag = 1;
190
+ }
191
+ p++;
192
+ } while (*p != '\0' && *p != '\n');
193
+ if (flag == 0) {
194
+ *val = 0;
195
+ return NULL;
196
+ }
197
+ *q = '\0';
198
+ flag = sscanf(buf, "%d", &x);
199
+ if (flag == 1) {
200
+ *val = x;
201
+ return p;
202
+ } else {
203
+ *val = 0;
204
+ return NULL;
205
+ }
206
+ }
207
+
208
+ double* get_ptr_double3(VALUE obj, size_t *size, size_t *stride, int *flag)
209
+ {
210
+ gsl_vector *v;
211
+ #ifdef HAVE_NARRAY_H
212
+ double *ptr;
213
+ struct NARRAY *na;
214
+ if (NA_IsNArray(obj)) {
215
+ obj = na_change_type(obj, NA_DFLOAT);
216
+ GetNArray(obj, na);
217
+ ptr = (double *) na->ptr;
218
+ *size = na->total;
219
+ *stride = 1;
220
+ *flag = 1;
221
+ return ptr;
222
+ }
223
+ #endif
224
+ CHECK_VECTOR(obj);
225
+ Data_Get_Struct(obj, gsl_vector, v);
226
+ *size = v->size;
227
+ *stride = v->stride;
228
+ *flag = 0;
229
+ return v->data;
230
+ }
231
+
232
+ gsl_complex ary2complex(VALUE obj)
233
+ {
234
+ gsl_complex *z, c;
235
+ switch (TYPE(obj)) {
236
+ case T_ARRAY:
237
+ GSL_SET_REAL(&c, NUM2DBL(rb_ary_entry(obj, 0)));
238
+ GSL_SET_IMAG(&c, NUM2DBL(rb_ary_entry(obj, 1)));
239
+ break;
240
+ default:
241
+ if (COMPLEX_P(obj)) {
242
+ Data_Get_Struct(obj, gsl_complex, z);
243
+ c = *z;
244
+ } else {
245
+ rb_raise(rb_eTypeError, "wrong argument type %s (Array or Complex expected)",
246
+ rb_class2name(CLASS_OF(obj)));
247
+ }
248
+ break;
249
+ }
250
+ return c;
251
+ }
252
+
253
+ VALUE vector_eval_create(VALUE obj, double (*func)(double))
254
+ {
255
+ gsl_vector *vnew;
256
+ size_t i, size, stride;
257
+ double *ptr;
258
+ ptr = get_vector_ptr(obj, &stride, &size);
259
+ vnew = gsl_vector_alloc(size);
260
+ for (i = 0; i < size; i++) {
261
+ gsl_vector_set(vnew, i, (*func)(ptr[i*stride]));
262
+ }
263
+ return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
264
+ }
265
+
266
+ VALUE matrix_eval_create(VALUE obj, double (*func)(double))
267
+ {
268
+ gsl_matrix *m, *mnew;
269
+ size_t i, j;
270
+ Data_Get_Struct(obj, gsl_matrix, m);
271
+ mnew = gsl_matrix_alloc(m->size1, m->size2);
272
+ for (i = 0; i < m->size1; i++) {
273
+ for (j = 0; j < m->size2; j++) {
274
+ gsl_matrix_set(mnew, i, j, (*func)(gsl_matrix_get(m, i, j)));
275
+ }
276
+ }
277
+ return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
278
+ }
279
+
280
+ VALUE rb_gsl_ary_eval1(VALUE ary, double (*f)(double))
281
+ {
282
+ VALUE ary2;
283
+ size_t i, n;
284
+ double val;
285
+ n = RARRAY(ary)->len;
286
+ ary2 = rb_ary_new2(n);
287
+ for (i = 0; i < n; i++) {
288
+ val = (*f)(NUM2DBL(rb_ary_entry(ary, i)));
289
+ rb_ary_store(ary2, i, rb_float_new(val));
290
+ }
291
+ return ary2;
292
+ }
293
+
294
+ #ifdef HAVE_NARRAY_H
295
+ VALUE rb_gsl_nary_eval1(VALUE ary, double (*f)(double))
296
+ {
297
+ VALUE ary2;
298
+ struct NARRAY *na;
299
+ double *ptr1, *ptr2;
300
+ size_t i, n;
301
+ ary = na_change_type(ary, NA_DFLOAT);
302
+ GetNArray(ary, na);
303
+ ptr1 = (double *) na->ptr;
304
+ n = na->total;
305
+ ary2 = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(ary));
306
+ ptr2 = NA_PTR_TYPE(ary2, double*);
307
+ for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i]);
308
+ return ary2;
309
+ }
310
+ #endif