numo-gsl-integration 0.6.0 → 0.8.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 +4 -4
- data/CHANGELOG.md +28 -1
- data/README.md +33 -3
- data/docs/development.md +2 -2
- data/docs/error-handling.md +1 -1
- data/docs/routines.md +107 -1
- data/ext/numo/gsl/integration/cquad.c +45 -18
- data/ext/numo/gsl/integration/cquad_workspace.c +214 -0
- data/ext/numo/gsl/integration/fixed.c +374 -80
- data/ext/numo/gsl/integration/glfixed.c +22 -18
- data/ext/numo/gsl/integration/glfixed_table.c +211 -0
- data/ext/numo/gsl/integration/integration.c +9 -2
- data/ext/numo/gsl/integration/integration_internal.h +45 -2
- data/ext/numo/gsl/integration/lebedev.c +239 -32
- data/ext/numo/gsl/integration/romberg.c +47 -19
- data/ext/numo/gsl/integration/romberg_workspace.c +215 -0
- data/lib/numo/gsl/integration/version.rb +1 -1
- data/sig/numo/gsl/integration.rbs +64 -3
- metadata +4 -1
|
@@ -13,17 +13,38 @@ typedef struct {
|
|
|
13
13
|
} integration_fixed_type_info;
|
|
14
14
|
|
|
15
15
|
typedef struct {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const integration_fixed_type_info *type_info;
|
|
17
|
+
size_t order;
|
|
18
|
+
double a;
|
|
19
|
+
double b;
|
|
20
|
+
double alpha;
|
|
21
|
+
double beta;
|
|
22
|
+
} integration_fixed_config;
|
|
23
|
+
|
|
24
|
+
typedef struct {
|
|
25
|
+
gsl_integration_fixed_workspace *workspace;
|
|
26
|
+
const integration_fixed_type_info *type_info;
|
|
18
27
|
size_t order;
|
|
19
28
|
double a;
|
|
20
29
|
double b;
|
|
21
30
|
double alpha;
|
|
22
31
|
double beta;
|
|
32
|
+
int busy;
|
|
33
|
+
} integration_fixed_workspace;
|
|
34
|
+
|
|
35
|
+
typedef struct {
|
|
36
|
+
gsl_integration_fixed_workspace *workspace;
|
|
37
|
+
integration_fixed_workspace *owner;
|
|
38
|
+
} integration_fixed_workspace_use;
|
|
39
|
+
|
|
40
|
+
typedef struct {
|
|
41
|
+
gsl_function *function;
|
|
23
42
|
gsl_integration_fixed_workspace *workspace;
|
|
24
43
|
double *result;
|
|
25
44
|
} integration_fixed_params;
|
|
26
45
|
|
|
46
|
+
static VALUE integration_cFixedWorkspace;
|
|
47
|
+
|
|
27
48
|
static integration_fixed_type_info integration_fixed_types[] = {
|
|
28
49
|
{0, "legendre", &gsl_integration_fixed_legendre, 0},
|
|
29
50
|
{0, "chebyshev", &gsl_integration_fixed_chebyshev, 0},
|
|
@@ -47,25 +68,9 @@ static ID integration_fixed_id_a;
|
|
|
47
68
|
static ID integration_fixed_id_b;
|
|
48
69
|
static ID integration_fixed_id_alpha;
|
|
49
70
|
static ID integration_fixed_id_beta;
|
|
71
|
+
static ID integration_fixed_id_workspace;
|
|
50
72
|
static ID integration_fixed_id_less_than_or_equal;
|
|
51
73
|
|
|
52
|
-
void integration_fixed_init(void) {
|
|
53
|
-
size_t i;
|
|
54
|
-
|
|
55
|
-
for (i = 0;
|
|
56
|
-
i < sizeof(integration_fixed_types) / sizeof(integration_fixed_types[0]);
|
|
57
|
-
++i) {
|
|
58
|
-
integration_fixed_types[i].id = rb_intern(integration_fixed_types[i].name);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
integration_fixed_id_order = rb_intern("order");
|
|
62
|
-
integration_fixed_id_a = rb_intern("a");
|
|
63
|
-
integration_fixed_id_b = rb_intern("b");
|
|
64
|
-
integration_fixed_id_alpha = rb_intern("alpha");
|
|
65
|
-
integration_fixed_id_beta = rb_intern("beta");
|
|
66
|
-
integration_fixed_id_less_than_or_equal = rb_intern("<=");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
74
|
static const integration_fixed_type_info *integration_fixed_type(VALUE type) {
|
|
70
75
|
ID type_id;
|
|
71
76
|
size_t i;
|
|
@@ -87,104 +92,393 @@ static const integration_fixed_type_info *integration_fixed_type(VALUE type) {
|
|
|
87
92
|
rb_id2name(type_id));
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
static
|
|
91
|
-
|
|
95
|
+
static void integration_fixed_config_parse(VALUE type, VALUE order_value,
|
|
96
|
+
VALUE a_value, VALUE b_value,
|
|
97
|
+
VALUE alpha_value, VALUE beta_value,
|
|
98
|
+
integration_fixed_config *config) {
|
|
99
|
+
const integration_fixed_type_info *type_info = integration_fixed_type(type);
|
|
92
100
|
|
|
93
|
-
if (
|
|
94
|
-
|
|
101
|
+
if (order_value == Qundef) {
|
|
102
|
+
rb_raise(rb_eArgError, "missing keyword: :order");
|
|
95
103
|
}
|
|
96
|
-
|
|
104
|
+
if (a_value == Qundef) {
|
|
105
|
+
rb_raise(rb_eArgError, "missing keyword: :a");
|
|
106
|
+
}
|
|
107
|
+
if (b_value == Qundef) {
|
|
108
|
+
rb_raise(rb_eArgError, "missing keyword: :b");
|
|
109
|
+
}
|
|
110
|
+
if (!RB_INTEGER_TYPE_P(order_value)) {
|
|
111
|
+
rb_raise(rb_eTypeError, "order must be an Integer");
|
|
112
|
+
}
|
|
113
|
+
if (RTEST(rb_funcall(order_value, integration_fixed_id_less_than_or_equal, 1,
|
|
114
|
+
INT2FIX(0)))) {
|
|
115
|
+
rb_raise(rb_eArgError, "order must be positive");
|
|
116
|
+
}
|
|
117
|
+
if ((type_info->requirements & INTEGRATION_FIXED_REQUIRES_ALPHA) != 0 &&
|
|
118
|
+
alpha_value == Qundef) {
|
|
119
|
+
rb_raise(rb_eArgError, "alpha is required for %s", type_info->name);
|
|
120
|
+
}
|
|
121
|
+
if ((type_info->requirements & INTEGRATION_FIXED_REQUIRES_BETA) != 0 &&
|
|
122
|
+
beta_value == Qundef) {
|
|
123
|
+
rb_raise(rb_eArgError, "beta is required for %s", type_info->name);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
config->type_info = type_info;
|
|
127
|
+
config->order = NUM2SIZET(order_value);
|
|
128
|
+
config->a = NUM2DBL(a_value);
|
|
129
|
+
config->b = NUM2DBL(b_value);
|
|
130
|
+
config->alpha =
|
|
131
|
+
(type_info->requirements & INTEGRATION_FIXED_REQUIRES_ALPHA) != 0
|
|
132
|
+
? NUM2DBL(alpha_value)
|
|
133
|
+
: 0.0;
|
|
134
|
+
config->beta =
|
|
135
|
+
(type_info->requirements & INTEGRATION_FIXED_REQUIRES_BETA) != 0
|
|
136
|
+
? NUM2DBL(beta_value)
|
|
137
|
+
: 0.0;
|
|
97
138
|
}
|
|
98
139
|
|
|
99
|
-
static
|
|
100
|
-
|
|
140
|
+
static void integration_fixed_workspace_free(void *data) {
|
|
141
|
+
integration_fixed_workspace *workspace = data;
|
|
101
142
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
params->b, params->alpha, params->beta);
|
|
105
|
-
if (params->workspace == NULL) {
|
|
106
|
-
rb_memerror();
|
|
143
|
+
if (workspace->workspace != NULL) {
|
|
144
|
+
gsl_integration_fixed_free(workspace->workspace);
|
|
107
145
|
}
|
|
146
|
+
xfree(workspace);
|
|
147
|
+
}
|
|
108
148
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return Qnil;
|
|
149
|
+
static size_t integration_fixed_workspace_memsize(const void *data) {
|
|
150
|
+
return data == NULL ? 0 : sizeof(integration_fixed_workspace);
|
|
112
151
|
}
|
|
113
152
|
|
|
114
|
-
static
|
|
115
|
-
|
|
116
|
-
|
|
153
|
+
static const rb_data_type_t integration_fixed_workspace_type = {
|
|
154
|
+
.wrap_struct_name = "Numo::GSL::Integration::FixedWorkspace",
|
|
155
|
+
.function =
|
|
156
|
+
{
|
|
157
|
+
.dmark = NULL,
|
|
158
|
+
.dfree = integration_fixed_workspace_free,
|
|
159
|
+
.dsize = integration_fixed_workspace_memsize,
|
|
160
|
+
},
|
|
161
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
static VALUE integration_fixed_workspace_allocate(VALUE klass) {
|
|
165
|
+
integration_fixed_workspace *workspace;
|
|
166
|
+
VALUE object =
|
|
167
|
+
TypedData_Make_Struct(klass, integration_fixed_workspace,
|
|
168
|
+
&integration_fixed_workspace_type, workspace);
|
|
169
|
+
|
|
170
|
+
workspace->workspace = NULL;
|
|
171
|
+
workspace->type_info = NULL;
|
|
172
|
+
workspace->order = 0;
|
|
173
|
+
workspace->a = 0.0;
|
|
174
|
+
workspace->b = 0.0;
|
|
175
|
+
workspace->alpha = 0.0;
|
|
176
|
+
workspace->beta = 0.0;
|
|
177
|
+
workspace->busy = 0;
|
|
178
|
+
return object;
|
|
117
179
|
}
|
|
118
180
|
|
|
119
|
-
VALUE
|
|
181
|
+
static VALUE integration_fixed_workspace_initialize(int argc, VALUE *argv,
|
|
182
|
+
VALUE self) {
|
|
120
183
|
VALUE type;
|
|
121
184
|
VALUE options;
|
|
122
185
|
ID keywords[] = {integration_fixed_id_order, integration_fixed_id_a,
|
|
123
186
|
integration_fixed_id_b, integration_fixed_id_alpha,
|
|
124
187
|
integration_fixed_id_beta};
|
|
125
188
|
VALUE keyword_values[5];
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
189
|
+
integration_fixed_config config;
|
|
190
|
+
gsl_integration_fixed_workspace *native_workspace;
|
|
191
|
+
integration_fixed_workspace *workspace;
|
|
192
|
+
|
|
193
|
+
rb_scan_args(argc, argv, "1:", &type, &options);
|
|
194
|
+
if (NIL_P(options)) {
|
|
195
|
+
options = rb_hash_new();
|
|
196
|
+
}
|
|
197
|
+
rb_get_kwargs(options, keywords, 0, 5, keyword_values);
|
|
198
|
+
integration_fixed_config_parse(type, keyword_values[0], keyword_values[1],
|
|
199
|
+
keyword_values[2], keyword_values[3],
|
|
200
|
+
keyword_values[4], &config);
|
|
201
|
+
|
|
202
|
+
TypedData_Get_Struct(self, integration_fixed_workspace,
|
|
203
|
+
&integration_fixed_workspace_type, workspace);
|
|
204
|
+
if (workspace->workspace != NULL) {
|
|
205
|
+
rb_raise(rb_eRuntimeError, "workspace is already initialized");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
native_workspace = gsl_integration_fixed_alloc(
|
|
209
|
+
*config.type_info->type, config.order, config.a, config.b, config.alpha,
|
|
210
|
+
config.beta);
|
|
211
|
+
if (native_workspace == NULL) {
|
|
212
|
+
rb_memerror();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
workspace->workspace = native_workspace;
|
|
216
|
+
workspace->type_info = config.type_info;
|
|
217
|
+
workspace->order = config.order;
|
|
218
|
+
workspace->a = config.a;
|
|
219
|
+
workspace->b = config.b;
|
|
220
|
+
workspace->alpha = config.alpha;
|
|
221
|
+
workspace->beta = config.beta;
|
|
222
|
+
return self;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
static VALUE integration_fixed_workspace_type_value(VALUE self) {
|
|
226
|
+
integration_fixed_workspace *workspace;
|
|
227
|
+
|
|
228
|
+
TypedData_Get_Struct(self, integration_fixed_workspace,
|
|
229
|
+
&integration_fixed_workspace_type, workspace);
|
|
230
|
+
return ID2SYM(workspace->type_info->id);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
static VALUE integration_fixed_workspace_order(VALUE self) {
|
|
234
|
+
integration_fixed_workspace *workspace;
|
|
235
|
+
|
|
236
|
+
TypedData_Get_Struct(self, integration_fixed_workspace,
|
|
237
|
+
&integration_fixed_workspace_type, workspace);
|
|
238
|
+
return SIZET2NUM(workspace->order);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
static VALUE integration_fixed_workspace_a(VALUE self) {
|
|
242
|
+
integration_fixed_workspace *workspace;
|
|
243
|
+
|
|
244
|
+
TypedData_Get_Struct(self, integration_fixed_workspace,
|
|
245
|
+
&integration_fixed_workspace_type, workspace);
|
|
246
|
+
return DBL2NUM(workspace->a);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
static VALUE integration_fixed_workspace_b(VALUE self) {
|
|
250
|
+
integration_fixed_workspace *workspace;
|
|
251
|
+
|
|
252
|
+
TypedData_Get_Struct(self, integration_fixed_workspace,
|
|
253
|
+
&integration_fixed_workspace_type, workspace);
|
|
254
|
+
return DBL2NUM(workspace->b);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
static VALUE integration_fixed_workspace_alpha(VALUE self) {
|
|
258
|
+
integration_fixed_workspace *workspace;
|
|
259
|
+
|
|
260
|
+
TypedData_Get_Struct(self, integration_fixed_workspace,
|
|
261
|
+
&integration_fixed_workspace_type, workspace);
|
|
262
|
+
if ((workspace->type_info->requirements & INTEGRATION_FIXED_REQUIRES_ALPHA) ==
|
|
263
|
+
0) {
|
|
264
|
+
return Qnil;
|
|
265
|
+
}
|
|
266
|
+
return DBL2NUM(workspace->alpha);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
static VALUE integration_fixed_workspace_beta(VALUE self) {
|
|
270
|
+
integration_fixed_workspace *workspace;
|
|
271
|
+
|
|
272
|
+
TypedData_Get_Struct(self, integration_fixed_workspace,
|
|
273
|
+
&integration_fixed_workspace_type, workspace);
|
|
274
|
+
if ((workspace->type_info->requirements & INTEGRATION_FIXED_REQUIRES_BETA) ==
|
|
275
|
+
0) {
|
|
276
|
+
return Qnil;
|
|
277
|
+
}
|
|
278
|
+
return DBL2NUM(workspace->beta);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
static VALUE integration_fixed_workspace_closed_p(VALUE self) {
|
|
282
|
+
integration_fixed_workspace *workspace;
|
|
283
|
+
|
|
284
|
+
TypedData_Get_Struct(self, integration_fixed_workspace,
|
|
285
|
+
&integration_fixed_workspace_type, workspace);
|
|
286
|
+
return workspace->workspace == NULL ? Qtrue : Qfalse;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
static VALUE integration_fixed_workspace_close(VALUE self) {
|
|
290
|
+
integration_fixed_workspace *workspace;
|
|
291
|
+
|
|
292
|
+
TypedData_Get_Struct(self, integration_fixed_workspace,
|
|
293
|
+
&integration_fixed_workspace_type, workspace);
|
|
294
|
+
if (workspace->busy) {
|
|
295
|
+
rb_raise(rb_eRuntimeError, "workspace is already in use");
|
|
296
|
+
}
|
|
297
|
+
if (workspace->workspace != NULL) {
|
|
298
|
+
gsl_integration_fixed_free(workspace->workspace);
|
|
299
|
+
workspace->workspace = NULL;
|
|
300
|
+
}
|
|
301
|
+
return Qnil;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
static VALUE integration_fixed_workspace_yield(VALUE workspace) {
|
|
305
|
+
return rb_yield(workspace);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
static VALUE integration_fixed_workspace_open(int argc, VALUE *argv,
|
|
309
|
+
VALUE klass) {
|
|
310
|
+
VALUE workspace =
|
|
311
|
+
rb_funcallv_kw(klass, rb_intern("new"), argc, argv, RB_PASS_KEYWORDS);
|
|
312
|
+
return rb_ensure(integration_fixed_workspace_yield, workspace,
|
|
313
|
+
integration_fixed_workspace_close, workspace);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
static integration_fixed_workspace *
|
|
317
|
+
integration_fixed_workspace_get(VALUE workspace_value) {
|
|
318
|
+
integration_fixed_workspace *workspace;
|
|
319
|
+
|
|
320
|
+
if (!rb_obj_is_kind_of(workspace_value, integration_cFixedWorkspace)) {
|
|
321
|
+
rb_raise(rb_eTypeError,
|
|
322
|
+
"workspace must be a Numo::GSL::Integration::FixedWorkspace");
|
|
323
|
+
}
|
|
324
|
+
TypedData_Get_Struct(workspace_value, integration_fixed_workspace,
|
|
325
|
+
&integration_fixed_workspace_type, workspace);
|
|
326
|
+
if (workspace->workspace == NULL) {
|
|
327
|
+
rb_raise(rb_eRuntimeError, "workspace is closed");
|
|
328
|
+
}
|
|
329
|
+
if (workspace->busy) {
|
|
330
|
+
rb_raise(rb_eRuntimeError, "workspace is already in use");
|
|
331
|
+
}
|
|
332
|
+
return workspace;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
static void
|
|
336
|
+
integration_fixed_workspace_use_begin(VALUE workspace_value,
|
|
337
|
+
const integration_fixed_config *config,
|
|
338
|
+
integration_fixed_workspace_use *use) {
|
|
339
|
+
integration_fixed_workspace *workspace;
|
|
340
|
+
|
|
341
|
+
use->workspace = NULL;
|
|
342
|
+
use->owner = NULL;
|
|
343
|
+
|
|
344
|
+
if (workspace_value == Qundef) {
|
|
345
|
+
use->workspace = gsl_integration_fixed_alloc(
|
|
346
|
+
*config->type_info->type, config->order, config->a, config->b,
|
|
347
|
+
config->alpha, config->beta);
|
|
348
|
+
if (use->workspace == NULL) {
|
|
349
|
+
rb_memerror();
|
|
350
|
+
}
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
workspace = integration_fixed_workspace_get(workspace_value);
|
|
355
|
+
workspace->busy = 1;
|
|
356
|
+
use->workspace = workspace->workspace;
|
|
357
|
+
use->owner = workspace;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
static VALUE integration_fixed_workspace_use_end(VALUE data) {
|
|
361
|
+
integration_fixed_workspace_use *use =
|
|
362
|
+
(integration_fixed_workspace_use *)data;
|
|
363
|
+
|
|
364
|
+
if (use->owner != NULL) {
|
|
365
|
+
use->owner->busy = 0;
|
|
366
|
+
} else if (use->workspace != NULL) {
|
|
367
|
+
gsl_integration_fixed_free(use->workspace);
|
|
368
|
+
}
|
|
369
|
+
use->workspace = NULL;
|
|
370
|
+
use->owner = NULL;
|
|
371
|
+
return Qnil;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
static VALUE integration_run_fixed(VALUE data) {
|
|
375
|
+
integration_fixed_params *params = (integration_fixed_params *)data;
|
|
376
|
+
|
|
377
|
+
(void)gsl_integration_fixed(params->function, params->result,
|
|
378
|
+
params->workspace);
|
|
379
|
+
return Qnil;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
VALUE integration_fixed(int argc, VALUE *argv, VALUE self) {
|
|
383
|
+
VALUE type = Qundef;
|
|
384
|
+
VALUE options;
|
|
385
|
+
VALUE workspace_value = Qundef;
|
|
386
|
+
ID keywords[] = {integration_fixed_id_order, integration_fixed_id_a,
|
|
387
|
+
integration_fixed_id_b, integration_fixed_id_alpha,
|
|
388
|
+
integration_fixed_id_beta, integration_fixed_id_workspace};
|
|
389
|
+
VALUE keyword_values[6];
|
|
390
|
+
integration_fixed_config config = {0};
|
|
391
|
+
int positional_count;
|
|
392
|
+
int config_given;
|
|
131
393
|
gsl_function function;
|
|
132
394
|
integration_callback_params params;
|
|
133
|
-
integration_fixed_params fixed_params
|
|
395
|
+
integration_fixed_params fixed_params;
|
|
396
|
+
integration_fixed_workspace_use workspace_use;
|
|
134
397
|
double result;
|
|
135
398
|
int state = 0;
|
|
136
399
|
|
|
137
400
|
(void)self;
|
|
138
|
-
rb_scan_args(argc, argv, "
|
|
139
|
-
type_info = integration_fixed_type(type);
|
|
140
|
-
|
|
401
|
+
positional_count = rb_scan_args(argc, argv, "01:", &type, &options);
|
|
141
402
|
if (NIL_P(options)) {
|
|
142
403
|
options = rb_hash_new();
|
|
143
404
|
}
|
|
144
|
-
rb_get_kwargs(options, keywords,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
alpha_value = keyword_values[3];
|
|
148
|
-
beta_value = keyword_values[4];
|
|
405
|
+
rb_get_kwargs(options, keywords, 0, 6, keyword_values);
|
|
406
|
+
workspace_value = keyword_values[5];
|
|
407
|
+
config_given = positional_count == 1;
|
|
149
408
|
|
|
150
|
-
if (!
|
|
151
|
-
rb_raise(
|
|
409
|
+
if (!config_given && workspace_value == Qundef) {
|
|
410
|
+
rb_raise(rb_eArgError, "wrong number of arguments (given 0, expected 1)");
|
|
152
411
|
}
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
412
|
+
if (config_given && workspace_value != Qundef) {
|
|
413
|
+
rb_raise(rb_eArgError,
|
|
414
|
+
"workspace cannot be specified with fixed quadrature parameters");
|
|
156
415
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
rb_raise(rb_eArgError,
|
|
416
|
+
if (!config_given &&
|
|
417
|
+
(keyword_values[0] != Qundef || keyword_values[1] != Qundef ||
|
|
418
|
+
keyword_values[2] != Qundef || keyword_values[3] != Qundef ||
|
|
419
|
+
keyword_values[4] != Qundef)) {
|
|
420
|
+
rb_raise(rb_eArgError,
|
|
421
|
+
"type is required when fixed quadrature parameters are specified");
|
|
162
422
|
}
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
423
|
+
if (config_given) {
|
|
424
|
+
integration_fixed_config_parse(type, keyword_values[0], keyword_values[1],
|
|
425
|
+
keyword_values[2], keyword_values[3],
|
|
426
|
+
keyword_values[4], &config);
|
|
166
427
|
}
|
|
167
428
|
|
|
168
429
|
integration_function_init(&function, ¶ms);
|
|
430
|
+
integration_fixed_workspace_use_begin(workspace_value, &config,
|
|
431
|
+
&workspace_use);
|
|
169
432
|
fixed_params.function = &function;
|
|
170
|
-
fixed_params.
|
|
171
|
-
fixed_params.order = order;
|
|
172
|
-
fixed_params.a = NUM2DBL(keyword_values[1]);
|
|
173
|
-
fixed_params.b = NUM2DBL(keyword_values[2]);
|
|
174
|
-
fixed_params.alpha =
|
|
175
|
-
(type_info->requirements & INTEGRATION_FIXED_REQUIRES_ALPHA) != 0
|
|
176
|
-
? NUM2DBL(alpha_value)
|
|
177
|
-
: 0.0;
|
|
178
|
-
fixed_params.beta =
|
|
179
|
-
(type_info->requirements & INTEGRATION_FIXED_REQUIRES_BETA) != 0
|
|
180
|
-
? NUM2DBL(beta_value)
|
|
181
|
-
: 0.0;
|
|
433
|
+
fixed_params.workspace = workspace_use.workspace;
|
|
182
434
|
fixed_params.result = &result;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
435
|
+
rb_protect(integration_run_fixed, (VALUE)&fixed_params, &state);
|
|
436
|
+
integration_fixed_workspace_use_end((VALUE)&workspace_use);
|
|
437
|
+
RB_GC_GUARD(workspace_value);
|
|
186
438
|
RB_GC_GUARD(params.block);
|
|
187
439
|
RB_GC_GUARD(params.exception);
|
|
188
440
|
integration_finish_callback(¶ms, state);
|
|
189
441
|
return DBL2NUM(result);
|
|
190
442
|
}
|
|
443
|
+
|
|
444
|
+
void integration_fixed_init(VALUE integration_module) {
|
|
445
|
+
size_t i;
|
|
446
|
+
|
|
447
|
+
for (i = 0;
|
|
448
|
+
i < sizeof(integration_fixed_types) / sizeof(integration_fixed_types[0]);
|
|
449
|
+
++i) {
|
|
450
|
+
integration_fixed_types[i].id = rb_intern(integration_fixed_types[i].name);
|
|
451
|
+
}
|
|
452
|
+
integration_fixed_id_order = rb_intern("order");
|
|
453
|
+
integration_fixed_id_a = rb_intern("a");
|
|
454
|
+
integration_fixed_id_b = rb_intern("b");
|
|
455
|
+
integration_fixed_id_alpha = rb_intern("alpha");
|
|
456
|
+
integration_fixed_id_beta = rb_intern("beta");
|
|
457
|
+
integration_fixed_id_workspace = rb_intern("workspace");
|
|
458
|
+
integration_fixed_id_less_than_or_equal = rb_intern("<=");
|
|
459
|
+
|
|
460
|
+
integration_cFixedWorkspace =
|
|
461
|
+
rb_define_class_under(integration_module, "FixedWorkspace", rb_cObject);
|
|
462
|
+
rb_define_alloc_func(integration_cFixedWorkspace,
|
|
463
|
+
integration_fixed_workspace_allocate);
|
|
464
|
+
rb_define_method(integration_cFixedWorkspace, "initialize",
|
|
465
|
+
integration_fixed_workspace_initialize, -1);
|
|
466
|
+
rb_define_method(integration_cFixedWorkspace, "type",
|
|
467
|
+
integration_fixed_workspace_type_value, 0);
|
|
468
|
+
rb_define_method(integration_cFixedWorkspace, "order",
|
|
469
|
+
integration_fixed_workspace_order, 0);
|
|
470
|
+
rb_define_method(integration_cFixedWorkspace, "a",
|
|
471
|
+
integration_fixed_workspace_a, 0);
|
|
472
|
+
rb_define_method(integration_cFixedWorkspace, "b",
|
|
473
|
+
integration_fixed_workspace_b, 0);
|
|
474
|
+
rb_define_method(integration_cFixedWorkspace, "alpha",
|
|
475
|
+
integration_fixed_workspace_alpha, 0);
|
|
476
|
+
rb_define_method(integration_cFixedWorkspace, "beta",
|
|
477
|
+
integration_fixed_workspace_beta, 0);
|
|
478
|
+
rb_define_method(integration_cFixedWorkspace, "closed?",
|
|
479
|
+
integration_fixed_workspace_closed_p, 0);
|
|
480
|
+
rb_define_method(integration_cFixedWorkspace, "close",
|
|
481
|
+
integration_fixed_workspace_close, 0);
|
|
482
|
+
rb_define_singleton_method(integration_cFixedWorkspace, "open",
|
|
483
|
+
integration_fixed_workspace_open, -1);
|
|
484
|
+
}
|
|
@@ -5,15 +5,19 @@ typedef struct {
|
|
|
5
5
|
double a;
|
|
6
6
|
double b;
|
|
7
7
|
size_t order;
|
|
8
|
-
|
|
8
|
+
int order_given;
|
|
9
|
+
VALUE table_value;
|
|
10
|
+
integration_glfixed_table_use table_use;
|
|
9
11
|
double *result;
|
|
10
12
|
} integration_glfixed_params;
|
|
11
13
|
|
|
12
14
|
static VALUE integration_run_glfixed(VALUE data) {
|
|
13
15
|
integration_glfixed_params *params = (integration_glfixed_params *)data;
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
integration_glfixed_table_use_begin(params->table_value, ¶ms->order,
|
|
18
|
+
params->order_given, ¶ms->table_use);
|
|
19
|
+
*(params->result) = gsl_integration_glfixed(
|
|
20
|
+
params->function, params->a, params->b, params->table_use.table);
|
|
17
21
|
|
|
18
22
|
return Qnil;
|
|
19
23
|
}
|
|
@@ -22,7 +26,8 @@ static VALUE integration_run_glfixed_with_table(VALUE data) {
|
|
|
22
26
|
integration_glfixed_params *params = (integration_glfixed_params *)data;
|
|
23
27
|
|
|
24
28
|
return rb_ensure(integration_run_glfixed, data,
|
|
25
|
-
|
|
29
|
+
integration_glfixed_table_use_end,
|
|
30
|
+
(VALUE)¶ms->table_use);
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
VALUE integration_glfixed(int argc, VALUE *argv, VALUE self) {
|
|
@@ -30,35 +35,34 @@ VALUE integration_glfixed(int argc, VALUE *argv, VALUE self) {
|
|
|
30
35
|
VALUE b;
|
|
31
36
|
VALUE options;
|
|
32
37
|
VALUE order_value = Qundef;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
VALUE table_value = Qundef;
|
|
39
|
+
ID keywords[] = {rb_intern("order"), rb_intern("table")};
|
|
40
|
+
VALUE keyword_values[2];
|
|
41
|
+
size_t order = 10;
|
|
42
|
+
int order_given;
|
|
36
43
|
gsl_function function;
|
|
37
44
|
integration_callback_params params;
|
|
38
|
-
integration_glfixed_params glfixed_params;
|
|
45
|
+
integration_glfixed_params glfixed_params = {0};
|
|
39
46
|
double result;
|
|
40
47
|
int state = 0;
|
|
41
48
|
|
|
42
49
|
(void)self;
|
|
43
50
|
|
|
44
51
|
rb_scan_args(argc, argv, "2:", &a, &b, &options);
|
|
45
|
-
|
|
46
52
|
if (!NIL_P(options)) {
|
|
47
|
-
rb_get_kwargs(options, keywords, 0,
|
|
53
|
+
rb_get_kwargs(options, keywords, 0, 2, keyword_values);
|
|
48
54
|
order_value = keyword_values[0];
|
|
55
|
+
table_value = keyword_values[1];
|
|
49
56
|
}
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} else {
|
|
58
|
+
order_given = order_value != Qundef;
|
|
59
|
+
if (order_given) {
|
|
54
60
|
if (!RB_INTEGER_TYPE_P(order_value)) {
|
|
55
61
|
rb_raise(rb_eTypeError, "order must be an Integer");
|
|
56
62
|
}
|
|
57
|
-
|
|
58
63
|
if (RTEST(rb_funcall(order_value, rb_intern("<="), 1, INT2FIX(0)))) {
|
|
59
64
|
rb_raise(rb_eArgError, "order must be positive");
|
|
60
65
|
}
|
|
61
|
-
|
|
62
66
|
order = NUM2SIZET(order_value);
|
|
63
67
|
}
|
|
64
68
|
|
|
@@ -68,9 +72,8 @@ VALUE integration_glfixed(int argc, VALUE *argv, VALUE self) {
|
|
|
68
72
|
glfixed_params.a = NUM2DBL(a);
|
|
69
73
|
glfixed_params.b = NUM2DBL(b);
|
|
70
74
|
glfixed_params.order = order;
|
|
71
|
-
|
|
72
|
-
glfixed_params.
|
|
73
|
-
|
|
75
|
+
glfixed_params.order_given = order_given;
|
|
76
|
+
glfixed_params.table_value = table_value;
|
|
74
77
|
glfixed_params.result = &result;
|
|
75
78
|
|
|
76
79
|
rb_protect(integration_run_glfixed_with_table, (VALUE)&glfixed_params,
|
|
@@ -78,6 +81,7 @@ VALUE integration_glfixed(int argc, VALUE *argv, VALUE self) {
|
|
|
78
81
|
|
|
79
82
|
RB_GC_GUARD(params.block);
|
|
80
83
|
RB_GC_GUARD(params.exception);
|
|
84
|
+
RB_GC_GUARD(table_value);
|
|
81
85
|
|
|
82
86
|
integration_finish_callback(¶ms, state);
|
|
83
87
|
|