numo-gsl-integration 0.4.0 → 0.6.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 +31 -0
- data/README.md +22 -1
- data/docs/routines.md +144 -9
- data/ext/numo/gsl/integration/integration.c +6 -0
- data/ext/numo/gsl/integration/integration_internal.h +73 -0
- data/ext/numo/gsl/integration/options.c +30 -0
- data/ext/numo/gsl/integration/qag.c +22 -11
- data/ext/numo/gsl/integration/qagi.c +12 -13
- data/ext/numo/gsl/integration/qagil.c +15 -15
- data/ext/numo/gsl/integration/qagiu.c +15 -15
- data/ext/numo/gsl/integration/qagp.c +17 -8
- data/ext/numo/gsl/integration/qags.c +18 -15
- data/ext/numo/gsl/integration/qawc.c +21 -16
- data/ext/numo/gsl/integration/qawf.c +107 -31
- data/ext/numo/gsl/integration/qawf_table.c +120 -0
- data/ext/numo/gsl/integration/qawo.c +53 -22
- data/ext/numo/gsl/integration/qawo_table.c +295 -0
- data/ext/numo/gsl/integration/qaws.c +59 -24
- data/ext/numo/gsl/integration/qaws_table.c +292 -0
- data/ext/numo/gsl/integration/workspace.c +215 -0
- data/lib/numo/gsl/integration/version.rb +1 -1
- data/sig/numo/gsl/integration.rbs +83 -10
- metadata +5 -1
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
#include "integration_internal.h"
|
|
2
|
+
|
|
3
|
+
#include <float.h>
|
|
4
|
+
#include <math.h>
|
|
5
|
+
|
|
6
|
+
static VALUE integration_cQAWSTable;
|
|
7
|
+
|
|
8
|
+
static int integration_qaws_table_double_equal(double left, double right) {
|
|
9
|
+
double scale = fmax(fabs(left), fabs(right));
|
|
10
|
+
|
|
11
|
+
return fabs(left - right) <= DBL_EPSILON * fmax(1.0, scale) * 4.0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static void integration_qaws_table_free(void *data) {
|
|
15
|
+
integration_qaws_table *table = data;
|
|
16
|
+
|
|
17
|
+
if (table->table != NULL) {
|
|
18
|
+
gsl_integration_qaws_table_free(table->table);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
xfree(table);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static size_t integration_qaws_table_memsize(const void *data) {
|
|
25
|
+
const integration_qaws_table *table = data;
|
|
26
|
+
|
|
27
|
+
if (table == NULL) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return sizeof(integration_qaws_table) +
|
|
32
|
+
(table->table == NULL ? 0 : sizeof(gsl_integration_qaws_table));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static const rb_data_type_t integration_qaws_table_type = {
|
|
36
|
+
.wrap_struct_name = "Numo::GSL::Integration::QAWSTable",
|
|
37
|
+
.function =
|
|
38
|
+
{
|
|
39
|
+
.dmark = NULL,
|
|
40
|
+
.dfree = integration_qaws_table_free,
|
|
41
|
+
.dsize = integration_qaws_table_memsize,
|
|
42
|
+
},
|
|
43
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
static VALUE integration_qaws_table_allocate(VALUE klass) {
|
|
47
|
+
integration_qaws_table *table;
|
|
48
|
+
VALUE object = TypedData_Make_Struct(klass, integration_qaws_table,
|
|
49
|
+
&integration_qaws_table_type, table);
|
|
50
|
+
|
|
51
|
+
table->table = NULL;
|
|
52
|
+
table->alpha = 0.0;
|
|
53
|
+
table->beta = 0.0;
|
|
54
|
+
table->mu = 0;
|
|
55
|
+
table->nu = 0;
|
|
56
|
+
table->busy = 0;
|
|
57
|
+
|
|
58
|
+
return object;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static VALUE integration_qaws_table_initialize(int argc, VALUE *argv,
|
|
62
|
+
VALUE self) {
|
|
63
|
+
VALUE options;
|
|
64
|
+
VALUE alpha_value;
|
|
65
|
+
VALUE beta_value;
|
|
66
|
+
VALUE mu_value;
|
|
67
|
+
VALUE nu_value;
|
|
68
|
+
ID keywords[] = {rb_intern("alpha"), rb_intern("beta"), rb_intern("mu"),
|
|
69
|
+
rb_intern("nu")};
|
|
70
|
+
VALUE keyword_values[4];
|
|
71
|
+
double alpha;
|
|
72
|
+
double beta;
|
|
73
|
+
int mu;
|
|
74
|
+
int nu;
|
|
75
|
+
integration_qaws_table *table;
|
|
76
|
+
|
|
77
|
+
rb_scan_args(argc, argv, "0:", &options);
|
|
78
|
+
|
|
79
|
+
if (NIL_P(options)) {
|
|
80
|
+
rb_raise(rb_eArgError, "missing keywords: :alpha, :beta, :mu, :nu");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
rb_get_kwargs(options, keywords, 4, 0, keyword_values);
|
|
84
|
+
alpha_value = keyword_values[0];
|
|
85
|
+
beta_value = keyword_values[1];
|
|
86
|
+
mu_value = keyword_values[2];
|
|
87
|
+
nu_value = keyword_values[3];
|
|
88
|
+
|
|
89
|
+
if (!rb_obj_is_kind_of(alpha_value, rb_cNumeric)) {
|
|
90
|
+
rb_raise(rb_eTypeError, "alpha must be Numeric");
|
|
91
|
+
}
|
|
92
|
+
if (!rb_obj_is_kind_of(beta_value, rb_cNumeric)) {
|
|
93
|
+
rb_raise(rb_eTypeError, "beta must be Numeric");
|
|
94
|
+
}
|
|
95
|
+
if (!RB_INTEGER_TYPE_P(mu_value)) {
|
|
96
|
+
rb_raise(rb_eTypeError, "mu must be an Integer");
|
|
97
|
+
}
|
|
98
|
+
if (!RB_INTEGER_TYPE_P(nu_value)) {
|
|
99
|
+
rb_raise(rb_eTypeError, "nu must be an Integer");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
alpha = NUM2DBL(alpha_value);
|
|
103
|
+
beta = NUM2DBL(beta_value);
|
|
104
|
+
mu = NUM2INT(mu_value);
|
|
105
|
+
nu = NUM2INT(nu_value);
|
|
106
|
+
|
|
107
|
+
if (!(alpha > -1.0)) {
|
|
108
|
+
rb_raise(rb_eArgError, "alpha must be greater than -1");
|
|
109
|
+
}
|
|
110
|
+
if (!(beta > -1.0)) {
|
|
111
|
+
rb_raise(rb_eArgError, "beta must be greater than -1");
|
|
112
|
+
}
|
|
113
|
+
if (mu != 0 && mu != 1) {
|
|
114
|
+
rb_raise(rb_eArgError, "mu must be 0 or 1");
|
|
115
|
+
}
|
|
116
|
+
if (nu != 0 && nu != 1) {
|
|
117
|
+
rb_raise(rb_eArgError, "nu must be 0 or 1");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
TypedData_Get_Struct(self, integration_qaws_table,
|
|
121
|
+
&integration_qaws_table_type, table);
|
|
122
|
+
table->alpha = alpha;
|
|
123
|
+
table->beta = beta;
|
|
124
|
+
table->mu = mu;
|
|
125
|
+
table->nu = nu;
|
|
126
|
+
table->table =
|
|
127
|
+
gsl_integration_qaws_table_alloc(alpha, beta, table->mu, table->nu);
|
|
128
|
+
|
|
129
|
+
if (table->table == NULL) {
|
|
130
|
+
rb_memerror();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return self;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static VALUE integration_qaws_table_alpha(VALUE self) {
|
|
137
|
+
integration_qaws_table *table;
|
|
138
|
+
|
|
139
|
+
TypedData_Get_Struct(self, integration_qaws_table,
|
|
140
|
+
&integration_qaws_table_type, table);
|
|
141
|
+
|
|
142
|
+
return DBL2NUM(table->alpha);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static VALUE integration_qaws_table_beta(VALUE self) {
|
|
146
|
+
integration_qaws_table *table;
|
|
147
|
+
|
|
148
|
+
TypedData_Get_Struct(self, integration_qaws_table,
|
|
149
|
+
&integration_qaws_table_type, table);
|
|
150
|
+
|
|
151
|
+
return DBL2NUM(table->beta);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static VALUE integration_qaws_table_mu(VALUE self) {
|
|
155
|
+
integration_qaws_table *table;
|
|
156
|
+
|
|
157
|
+
TypedData_Get_Struct(self, integration_qaws_table,
|
|
158
|
+
&integration_qaws_table_type, table);
|
|
159
|
+
|
|
160
|
+
return INT2NUM(table->mu);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static VALUE integration_qaws_table_nu(VALUE self) {
|
|
164
|
+
integration_qaws_table *table;
|
|
165
|
+
|
|
166
|
+
TypedData_Get_Struct(self, integration_qaws_table,
|
|
167
|
+
&integration_qaws_table_type, table);
|
|
168
|
+
|
|
169
|
+
return INT2NUM(table->nu);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
static VALUE integration_qaws_table_closed_p(VALUE self) {
|
|
173
|
+
integration_qaws_table *table;
|
|
174
|
+
|
|
175
|
+
TypedData_Get_Struct(self, integration_qaws_table,
|
|
176
|
+
&integration_qaws_table_type, table);
|
|
177
|
+
|
|
178
|
+
return table->table == NULL ? Qtrue : Qfalse;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static VALUE integration_qaws_table_close(VALUE self) {
|
|
182
|
+
integration_qaws_table *table;
|
|
183
|
+
|
|
184
|
+
TypedData_Get_Struct(self, integration_qaws_table,
|
|
185
|
+
&integration_qaws_table_type, table);
|
|
186
|
+
|
|
187
|
+
if (table->busy) {
|
|
188
|
+
rb_raise(rb_eRuntimeError, "table is already in use");
|
|
189
|
+
}
|
|
190
|
+
if (table->table != NULL) {
|
|
191
|
+
gsl_integration_qaws_table_free(table->table);
|
|
192
|
+
table->table = NULL;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return Qnil;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
static VALUE integration_qaws_table_yield(VALUE table) {
|
|
199
|
+
return rb_yield(table);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
static VALUE integration_qaws_table_open(int argc, VALUE *argv, VALUE klass) {
|
|
203
|
+
VALUE table;
|
|
204
|
+
|
|
205
|
+
table = rb_funcallv_kw(klass, rb_intern("new"), argc, argv, RB_PASS_KEYWORDS);
|
|
206
|
+
|
|
207
|
+
return rb_ensure(integration_qaws_table_yield, table,
|
|
208
|
+
integration_qaws_table_close, table);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
void integration_qaws_table_use_begin(VALUE table_value, double alpha,
|
|
212
|
+
double beta, int mu, int nu,
|
|
213
|
+
integration_qaws_table_use *use) {
|
|
214
|
+
integration_qaws_table *table;
|
|
215
|
+
|
|
216
|
+
use->table = NULL;
|
|
217
|
+
use->owner = NULL;
|
|
218
|
+
|
|
219
|
+
if (table_value == Qundef) {
|
|
220
|
+
use->table = gsl_integration_qaws_table_alloc(alpha, beta, mu, nu);
|
|
221
|
+
if (use->table == NULL) {
|
|
222
|
+
rb_memerror();
|
|
223
|
+
}
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!rb_obj_is_kind_of(table_value, integration_cQAWSTable)) {
|
|
228
|
+
rb_raise(rb_eTypeError,
|
|
229
|
+
"table must be a Numo::GSL::Integration::QAWSTable");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
TypedData_Get_Struct(table_value, integration_qaws_table,
|
|
233
|
+
&integration_qaws_table_type, table);
|
|
234
|
+
|
|
235
|
+
if (table->table == NULL) {
|
|
236
|
+
rb_raise(rb_eRuntimeError, "table is closed");
|
|
237
|
+
}
|
|
238
|
+
if (table->busy) {
|
|
239
|
+
rb_raise(rb_eRuntimeError, "table is already in use");
|
|
240
|
+
}
|
|
241
|
+
if (!integration_qaws_table_double_equal(table->alpha, alpha)) {
|
|
242
|
+
rb_raise(rb_eArgError, "alpha does not match QAWS table");
|
|
243
|
+
}
|
|
244
|
+
if (!integration_qaws_table_double_equal(table->beta, beta)) {
|
|
245
|
+
rb_raise(rb_eArgError, "beta does not match QAWS table");
|
|
246
|
+
}
|
|
247
|
+
if (table->mu != mu) {
|
|
248
|
+
rb_raise(rb_eArgError, "mu does not match QAWS table");
|
|
249
|
+
}
|
|
250
|
+
if (table->nu != nu) {
|
|
251
|
+
rb_raise(rb_eArgError, "nu does not match QAWS table");
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
table->busy = 1;
|
|
255
|
+
use->table = table->table;
|
|
256
|
+
use->owner = table;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
VALUE integration_qaws_table_use_end(VALUE data) {
|
|
260
|
+
integration_qaws_table_use *use = (integration_qaws_table_use *)data;
|
|
261
|
+
|
|
262
|
+
if (use->owner != NULL) {
|
|
263
|
+
use->owner->busy = 0;
|
|
264
|
+
} else if (use->table != NULL) {
|
|
265
|
+
gsl_integration_qaws_table_free(use->table);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
use->table = NULL;
|
|
269
|
+
use->owner = NULL;
|
|
270
|
+
|
|
271
|
+
return Qnil;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
void integration_qaws_table_init(VALUE integration_module) {
|
|
275
|
+
integration_cQAWSTable =
|
|
276
|
+
rb_define_class_under(integration_module, "QAWSTable", rb_cObject);
|
|
277
|
+
rb_define_alloc_func(integration_cQAWSTable, integration_qaws_table_allocate);
|
|
278
|
+
rb_define_method(integration_cQAWSTable, "initialize",
|
|
279
|
+
integration_qaws_table_initialize, -1);
|
|
280
|
+
rb_define_method(integration_cQAWSTable, "alpha",
|
|
281
|
+
integration_qaws_table_alpha, 0);
|
|
282
|
+
rb_define_method(integration_cQAWSTable, "beta", integration_qaws_table_beta,
|
|
283
|
+
0);
|
|
284
|
+
rb_define_method(integration_cQAWSTable, "mu", integration_qaws_table_mu, 0);
|
|
285
|
+
rb_define_method(integration_cQAWSTable, "nu", integration_qaws_table_nu, 0);
|
|
286
|
+
rb_define_method(integration_cQAWSTable, "closed?",
|
|
287
|
+
integration_qaws_table_closed_p, 0);
|
|
288
|
+
rb_define_method(integration_cQAWSTable, "close",
|
|
289
|
+
integration_qaws_table_close, 0);
|
|
290
|
+
rb_define_singleton_method(integration_cQAWSTable, "open",
|
|
291
|
+
integration_qaws_table_open, -1);
|
|
292
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
#include "integration_internal.h"
|
|
2
|
+
|
|
3
|
+
static VALUE integration_cWorkspace;
|
|
4
|
+
|
|
5
|
+
static void integration_workspace_free(void *data) {
|
|
6
|
+
integration_workspace *workspace = data;
|
|
7
|
+
|
|
8
|
+
if (workspace->workspace != NULL) {
|
|
9
|
+
gsl_integration_workspace_free(workspace->workspace);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
xfree(workspace);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static size_t integration_workspace_memsize(const void *data) {
|
|
16
|
+
return data == NULL ? 0 : sizeof(integration_workspace);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static const rb_data_type_t integration_workspace_type = {
|
|
20
|
+
.wrap_struct_name = "Numo::GSL::Integration::Workspace",
|
|
21
|
+
.function =
|
|
22
|
+
{
|
|
23
|
+
.dmark = NULL,
|
|
24
|
+
.dfree = integration_workspace_free,
|
|
25
|
+
.dsize = integration_workspace_memsize,
|
|
26
|
+
},
|
|
27
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
static VALUE integration_workspace_allocate(VALUE klass) {
|
|
31
|
+
integration_workspace *workspace;
|
|
32
|
+
VALUE object = TypedData_Make_Struct(klass, integration_workspace,
|
|
33
|
+
&integration_workspace_type, workspace);
|
|
34
|
+
|
|
35
|
+
workspace->workspace = NULL;
|
|
36
|
+
workspace->limit = 0;
|
|
37
|
+
workspace->busy = 0;
|
|
38
|
+
|
|
39
|
+
return object;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static VALUE integration_workspace_initialize(int argc, VALUE *argv,
|
|
43
|
+
VALUE self) {
|
|
44
|
+
VALUE options;
|
|
45
|
+
VALUE limit_value;
|
|
46
|
+
ID keywords[] = {rb_intern("limit")};
|
|
47
|
+
VALUE keyword_values[1];
|
|
48
|
+
integration_workspace *workspace;
|
|
49
|
+
|
|
50
|
+
rb_scan_args(argc, argv, "0:", &options);
|
|
51
|
+
if (NIL_P(options)) {
|
|
52
|
+
rb_raise(rb_eArgError, "missing keyword: :limit");
|
|
53
|
+
}
|
|
54
|
+
rb_get_kwargs(options, keywords, 1, 0, keyword_values);
|
|
55
|
+
limit_value = keyword_values[0];
|
|
56
|
+
|
|
57
|
+
if (!RB_INTEGER_TYPE_P(limit_value)) {
|
|
58
|
+
rb_raise(rb_eTypeError, "limit must be an Integer");
|
|
59
|
+
}
|
|
60
|
+
if (RTEST(rb_funcall(limit_value, rb_intern("<="), 1, INT2FIX(0)))) {
|
|
61
|
+
rb_raise(rb_eArgError, "limit must be positive");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
TypedData_Get_Struct(self, integration_workspace, &integration_workspace_type,
|
|
65
|
+
workspace);
|
|
66
|
+
workspace->limit = NUM2SIZET(limit_value);
|
|
67
|
+
workspace->workspace = gsl_integration_workspace_alloc(workspace->limit);
|
|
68
|
+
if (workspace->workspace == NULL) {
|
|
69
|
+
rb_memerror();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return self;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static VALUE integration_workspace_limit(VALUE self) {
|
|
76
|
+
integration_workspace *workspace;
|
|
77
|
+
|
|
78
|
+
TypedData_Get_Struct(self, integration_workspace, &integration_workspace_type,
|
|
79
|
+
workspace);
|
|
80
|
+
|
|
81
|
+
return SIZET2NUM(workspace->limit);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static VALUE integration_workspace_closed_p(VALUE self) {
|
|
85
|
+
integration_workspace *workspace;
|
|
86
|
+
|
|
87
|
+
TypedData_Get_Struct(self, integration_workspace, &integration_workspace_type,
|
|
88
|
+
workspace);
|
|
89
|
+
|
|
90
|
+
return workspace->workspace == NULL ? Qtrue : Qfalse;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static VALUE integration_workspace_close(VALUE self) {
|
|
94
|
+
integration_workspace *workspace;
|
|
95
|
+
|
|
96
|
+
TypedData_Get_Struct(self, integration_workspace, &integration_workspace_type,
|
|
97
|
+
workspace);
|
|
98
|
+
|
|
99
|
+
if (workspace->busy) {
|
|
100
|
+
rb_raise(rb_eRuntimeError, "workspace is already in use");
|
|
101
|
+
}
|
|
102
|
+
if (workspace->workspace != NULL) {
|
|
103
|
+
gsl_integration_workspace_free(workspace->workspace);
|
|
104
|
+
workspace->workspace = NULL;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return Qnil;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static VALUE integration_workspace_yield(VALUE workspace) {
|
|
111
|
+
return rb_yield(workspace);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static VALUE integration_workspace_open(int argc, VALUE *argv, VALUE klass) {
|
|
115
|
+
VALUE workspace;
|
|
116
|
+
|
|
117
|
+
workspace =
|
|
118
|
+
rb_funcallv_kw(klass, rb_intern("new"), argc, argv, RB_PASS_KEYWORDS);
|
|
119
|
+
|
|
120
|
+
return rb_ensure(integration_workspace_yield, workspace,
|
|
121
|
+
integration_workspace_close, workspace);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static integration_workspace *integration_workspace_get(VALUE workspace_value,
|
|
125
|
+
const char *name) {
|
|
126
|
+
integration_workspace *workspace;
|
|
127
|
+
|
|
128
|
+
if (!rb_obj_is_kind_of(workspace_value, integration_cWorkspace)) {
|
|
129
|
+
rb_raise(rb_eTypeError, "%s must be a Numo::GSL::Integration::Workspace",
|
|
130
|
+
name);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
TypedData_Get_Struct(workspace_value, integration_workspace,
|
|
134
|
+
&integration_workspace_type, workspace);
|
|
135
|
+
if (workspace->workspace == NULL) {
|
|
136
|
+
rb_raise(rb_eRuntimeError, "%s is closed", name);
|
|
137
|
+
}
|
|
138
|
+
if (workspace->busy) {
|
|
139
|
+
rb_raise(rb_eRuntimeError, "%s is already in use", name);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return workspace;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
size_t integration_workspace_capacity(VALUE workspace_value, const char *name) {
|
|
146
|
+
return integration_workspace_get(workspace_value, name)->limit;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
void integration_workspace_use_begin_named(VALUE workspace_value, size_t *limit,
|
|
150
|
+
int limit_given,
|
|
151
|
+
integration_workspace_use *use,
|
|
152
|
+
const char *name) {
|
|
153
|
+
integration_workspace *workspace;
|
|
154
|
+
|
|
155
|
+
use->workspace = NULL;
|
|
156
|
+
use->owner = NULL;
|
|
157
|
+
|
|
158
|
+
if (workspace_value == Qundef) {
|
|
159
|
+
use->workspace = gsl_integration_workspace_alloc(*limit);
|
|
160
|
+
if (use->workspace == NULL) {
|
|
161
|
+
rb_memerror();
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
workspace = integration_workspace_get(workspace_value, name);
|
|
167
|
+
if (limit_given && *limit > workspace->limit) {
|
|
168
|
+
rb_raise(rb_eArgError, "limit exceeds %s capacity", name);
|
|
169
|
+
}
|
|
170
|
+
if (!limit_given) {
|
|
171
|
+
*limit = workspace->limit;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
workspace->busy = 1;
|
|
175
|
+
use->workspace = workspace->workspace;
|
|
176
|
+
use->owner = workspace;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
void integration_workspace_use_begin(VALUE workspace_value, size_t *limit,
|
|
180
|
+
int limit_given,
|
|
181
|
+
integration_workspace_use *use) {
|
|
182
|
+
integration_workspace_use_begin_named(workspace_value, limit, limit_given,
|
|
183
|
+
use, "workspace");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
VALUE integration_workspace_use_end(VALUE data) {
|
|
187
|
+
integration_workspace_use *use = (integration_workspace_use *)data;
|
|
188
|
+
|
|
189
|
+
if (use->owner != NULL) {
|
|
190
|
+
use->owner->busy = 0;
|
|
191
|
+
} else if (use->workspace != NULL) {
|
|
192
|
+
gsl_integration_workspace_free(use->workspace);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
use->workspace = NULL;
|
|
196
|
+
use->owner = NULL;
|
|
197
|
+
|
|
198
|
+
return Qnil;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
void integration_workspace_init(VALUE integration_module) {
|
|
202
|
+
integration_cWorkspace =
|
|
203
|
+
rb_define_class_under(integration_module, "Workspace", rb_cObject);
|
|
204
|
+
rb_define_alloc_func(integration_cWorkspace, integration_workspace_allocate);
|
|
205
|
+
rb_define_method(integration_cWorkspace, "initialize",
|
|
206
|
+
integration_workspace_initialize, -1);
|
|
207
|
+
rb_define_method(integration_cWorkspace, "limit", integration_workspace_limit,
|
|
208
|
+
0);
|
|
209
|
+
rb_define_method(integration_cWorkspace, "closed?",
|
|
210
|
+
integration_workspace_closed_p, 0);
|
|
211
|
+
rb_define_method(integration_cWorkspace, "close", integration_workspace_close,
|
|
212
|
+
0);
|
|
213
|
+
rb_define_singleton_method(integration_cWorkspace, "open",
|
|
214
|
+
integration_workspace_open, -1);
|
|
215
|
+
}
|
|
@@ -10,13 +10,73 @@ module Numo
|
|
|
10
10
|
GAUSS61: Integer
|
|
11
11
|
COSINE: Integer
|
|
12
12
|
SINE: Integer
|
|
13
|
+
class Workspace
|
|
14
|
+
def self.open: [T] (limit: Integer) { (Workspace) -> T } -> T
|
|
15
|
+
def initialize: (limit: Integer) -> void
|
|
16
|
+
def limit: () -> Integer
|
|
17
|
+
def close: () -> nil
|
|
18
|
+
def closed?: () -> bool
|
|
19
|
+
end
|
|
20
|
+
class QAWOTable
|
|
21
|
+
def self.open: [T] (
|
|
22
|
+
omega: Numeric,
|
|
23
|
+
length: Numeric,
|
|
24
|
+
sine: Integer,
|
|
25
|
+
levels: Integer
|
|
26
|
+
) { (QAWOTable) -> T } -> T
|
|
27
|
+
def initialize: (
|
|
28
|
+
omega: Numeric,
|
|
29
|
+
length: Numeric,
|
|
30
|
+
sine: Integer,
|
|
31
|
+
levels: Integer
|
|
32
|
+
) -> void
|
|
33
|
+
def omega: () -> Float
|
|
34
|
+
def length: () -> Float
|
|
35
|
+
def sine: () -> Integer
|
|
36
|
+
def levels: () -> Integer
|
|
37
|
+
def close: () -> nil
|
|
38
|
+
def closed?: () -> bool
|
|
39
|
+
end
|
|
40
|
+
class QAWFTable < QAWOTable
|
|
41
|
+
def self.open: [T] (
|
|
42
|
+
omega: Numeric,
|
|
43
|
+
sine: Integer,
|
|
44
|
+
levels: Integer
|
|
45
|
+
) { (QAWFTable) -> T } -> T
|
|
46
|
+
def initialize: (
|
|
47
|
+
omega: Numeric,
|
|
48
|
+
sine: Integer,
|
|
49
|
+
levels: Integer
|
|
50
|
+
) -> void
|
|
51
|
+
end
|
|
52
|
+
class QAWSTable
|
|
53
|
+
def self.open: [T] (
|
|
54
|
+
alpha: Numeric,
|
|
55
|
+
beta: Numeric,
|
|
56
|
+
mu: Integer,
|
|
57
|
+
nu: Integer
|
|
58
|
+
) { (QAWSTable) -> T } -> T
|
|
59
|
+
def initialize: (
|
|
60
|
+
alpha: Numeric,
|
|
61
|
+
beta: Numeric,
|
|
62
|
+
mu: Integer,
|
|
63
|
+
nu: Integer
|
|
64
|
+
) -> void
|
|
65
|
+
def alpha: () -> Float
|
|
66
|
+
def beta: () -> Float
|
|
67
|
+
def mu: () -> Integer
|
|
68
|
+
def nu: () -> Integer
|
|
69
|
+
def close: () -> nil
|
|
70
|
+
def closed?: () -> bool
|
|
71
|
+
end
|
|
13
72
|
def self.qag: (
|
|
14
73
|
Numeric a,
|
|
15
74
|
Numeric b,
|
|
16
75
|
?epsabs: Numeric,
|
|
17
76
|
?epsrel: Numeric,
|
|
18
77
|
?limit: Integer,
|
|
19
|
-
?key: Integer
|
|
78
|
+
?key: Integer,
|
|
79
|
+
?workspace: Workspace
|
|
20
80
|
) { (Float) -> Numeric } -> [Float, Float]
|
|
21
81
|
def self.qng: (
|
|
22
82
|
Numeric a,
|
|
@@ -29,30 +89,35 @@ module Numo
|
|
|
29
89
|
Numeric b,
|
|
30
90
|
?epsabs: Numeric,
|
|
31
91
|
?epsrel: Numeric,
|
|
32
|
-
?limit: Integer
|
|
92
|
+
?limit: Integer,
|
|
93
|
+
?workspace: Workspace
|
|
33
94
|
) { (Float) -> Numeric } -> [Float, Float]
|
|
34
95
|
def self.qagp: (
|
|
35
96
|
Array[Numeric] points,
|
|
36
97
|
?epsabs: Numeric,
|
|
37
98
|
?epsrel: Numeric,
|
|
38
|
-
?limit: Integer
|
|
99
|
+
?limit: Integer,
|
|
100
|
+
?workspace: Workspace
|
|
39
101
|
) { (Float) -> Numeric } -> [Float, Float]
|
|
40
102
|
def self.qagi: (
|
|
41
103
|
?epsabs: Numeric,
|
|
42
104
|
?epsrel: Numeric,
|
|
43
|
-
?limit: Integer
|
|
105
|
+
?limit: Integer,
|
|
106
|
+
?workspace: Workspace
|
|
44
107
|
) { (Float) -> Numeric } -> [Float, Float]
|
|
45
108
|
def self.qagiu: (
|
|
46
109
|
Numeric a,
|
|
47
110
|
?epsabs: Numeric,
|
|
48
111
|
?epsrel: Numeric,
|
|
49
|
-
?limit: Integer
|
|
112
|
+
?limit: Integer,
|
|
113
|
+
?workspace: Workspace
|
|
50
114
|
) { (Float) -> Numeric } -> [Float, Float]
|
|
51
115
|
def self.qagil: (
|
|
52
116
|
Numeric b,
|
|
53
117
|
?epsabs: Numeric,
|
|
54
118
|
?epsrel: Numeric,
|
|
55
|
-
?limit: Integer
|
|
119
|
+
?limit: Integer,
|
|
120
|
+
?workspace: Workspace
|
|
56
121
|
) { (Float) -> Numeric } -> [Float, Float]
|
|
57
122
|
def self.qawc: (
|
|
58
123
|
Numeric a,
|
|
@@ -60,7 +125,8 @@ module Numo
|
|
|
60
125
|
Numeric c,
|
|
61
126
|
?epsabs: Numeric,
|
|
62
127
|
?epsrel: Numeric,
|
|
63
|
-
?limit: Integer
|
|
128
|
+
?limit: Integer,
|
|
129
|
+
?workspace: Workspace
|
|
64
130
|
) { (Float) -> Numeric } -> [Float, Float]
|
|
65
131
|
def self.qaws: (
|
|
66
132
|
Numeric a,
|
|
@@ -71,7 +137,9 @@ module Numo
|
|
|
71
137
|
Integer nu,
|
|
72
138
|
?epsabs: Numeric,
|
|
73
139
|
?epsrel: Numeric,
|
|
74
|
-
?limit: Integer
|
|
140
|
+
?limit: Integer,
|
|
141
|
+
?workspace: Workspace,
|
|
142
|
+
?table: QAWSTable
|
|
75
143
|
) { (Float) -> Numeric } -> [Float, Float]
|
|
76
144
|
def self.qawo: (
|
|
77
145
|
Numeric a,
|
|
@@ -80,14 +148,19 @@ module Numo
|
|
|
80
148
|
Integer sine,
|
|
81
149
|
?epsabs: Numeric,
|
|
82
150
|
?epsrel: Numeric,
|
|
83
|
-
?limit: Integer
|
|
151
|
+
?limit: Integer,
|
|
152
|
+
?workspace: Workspace,
|
|
153
|
+
?table: QAWOTable
|
|
84
154
|
) { (Float) -> Numeric } -> [Float, Float]
|
|
85
155
|
def self.qawf: (
|
|
86
156
|
Numeric a,
|
|
87
157
|
Numeric omega,
|
|
88
158
|
Integer sine,
|
|
89
159
|
?epsabs: Numeric,
|
|
90
|
-
?limit: Integer
|
|
160
|
+
?limit: Integer,
|
|
161
|
+
?workspace: Workspace,
|
|
162
|
+
?cycle_workspace: Workspace,
|
|
163
|
+
?table: QAWFTable
|
|
91
164
|
) { (Float) -> Numeric } -> [Float, Float]
|
|
92
165
|
def self.cquad: (
|
|
93
166
|
Numeric a,
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: numo-gsl-integration
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Takahiro SATOH
|
|
@@ -41,11 +41,15 @@ files:
|
|
|
41
41
|
- ext/numo/gsl/integration/qags.c
|
|
42
42
|
- ext/numo/gsl/integration/qawc.c
|
|
43
43
|
- ext/numo/gsl/integration/qawf.c
|
|
44
|
+
- ext/numo/gsl/integration/qawf_table.c
|
|
44
45
|
- ext/numo/gsl/integration/qawo.c
|
|
46
|
+
- ext/numo/gsl/integration/qawo_table.c
|
|
45
47
|
- ext/numo/gsl/integration/qaws.c
|
|
48
|
+
- ext/numo/gsl/integration/qaws_table.c
|
|
46
49
|
- ext/numo/gsl/integration/qng.c
|
|
47
50
|
- ext/numo/gsl/integration/resources.c
|
|
48
51
|
- ext/numo/gsl/integration/romberg.c
|
|
52
|
+
- ext/numo/gsl/integration/workspace.c
|
|
49
53
|
- lib/numo/gsl/integration.rb
|
|
50
54
|
- lib/numo/gsl/integration/version.rb
|
|
51
55
|
- sig/numo/gsl.rbs
|