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
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
typedef struct {
|
|
4
4
|
gsl_function *function;
|
|
5
|
+
VALUE workspace_value;
|
|
6
|
+
VALUE table_value;
|
|
5
7
|
double a;
|
|
6
8
|
double b;
|
|
7
9
|
double omega;
|
|
@@ -10,8 +12,11 @@ typedef struct {
|
|
|
10
12
|
double epsabs;
|
|
11
13
|
double epsrel;
|
|
12
14
|
size_t limit;
|
|
15
|
+
int limit_given;
|
|
13
16
|
gsl_integration_workspace *workspace;
|
|
17
|
+
integration_workspace_use workspace_use;
|
|
14
18
|
gsl_integration_qawo_table *table;
|
|
19
|
+
integration_qawo_table_use table_use;
|
|
15
20
|
double *result;
|
|
16
21
|
double *error;
|
|
17
22
|
} integration_qawo_params;
|
|
@@ -19,13 +24,8 @@ typedef struct {
|
|
|
19
24
|
static VALUE integration_free_qawo_resources(VALUE data) {
|
|
20
25
|
integration_qawo_params *params = (integration_qawo_params *)data;
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (params->workspace != NULL) {
|
|
27
|
-
gsl_integration_workspace_free(params->workspace);
|
|
28
|
-
}
|
|
27
|
+
integration_qawo_table_use_end((VALUE)¶ms->table_use);
|
|
28
|
+
integration_workspace_use_end((VALUE)¶ms->workspace_use);
|
|
29
29
|
|
|
30
30
|
return Qnil;
|
|
31
31
|
}
|
|
@@ -33,9 +33,13 @@ static VALUE integration_free_qawo_resources(VALUE data) {
|
|
|
33
33
|
static VALUE integration_run_qawo(VALUE data) {
|
|
34
34
|
integration_qawo_params *params = (integration_qawo_params *)data;
|
|
35
35
|
|
|
36
|
-
params->
|
|
37
|
-
|
|
38
|
-
params->workspace =
|
|
36
|
+
integration_workspace_use_begin(params->workspace_value, ¶ms->limit,
|
|
37
|
+
params->limit_given, ¶ms->workspace_use);
|
|
38
|
+
params->workspace = params->workspace_use.workspace;
|
|
39
|
+
integration_qawo_table_use_begin(params->table_value, params->omega,
|
|
40
|
+
params->b - params->a, params->sine,
|
|
41
|
+
params->limit, ¶ms->table_use);
|
|
42
|
+
params->table = params->table_use.table;
|
|
39
43
|
|
|
40
44
|
(void)gsl_integration_qawo(params->function, params->a, params->epsabs,
|
|
41
45
|
params->epsrel, params->limit, params->workspace,
|
|
@@ -55,13 +59,25 @@ VALUE integration_qawo(int argc, VALUE *argv, VALUE self) {
|
|
|
55
59
|
VALUE omega;
|
|
56
60
|
VALUE sine;
|
|
57
61
|
VALUE options;
|
|
58
|
-
|
|
62
|
+
VALUE epsabs_value = Qundef;
|
|
63
|
+
VALUE epsrel_value = Qundef;
|
|
64
|
+
VALUE limit_value = Qundef;
|
|
65
|
+
VALUE workspace_value = Qundef;
|
|
66
|
+
VALUE table_value = Qundef;
|
|
67
|
+
ID keywords[] = {rb_intern("epsabs"), rb_intern("epsrel"), rb_intern("limit"),
|
|
68
|
+
rb_intern("workspace"), rb_intern("table")};
|
|
69
|
+
VALUE keyword_values[5];
|
|
70
|
+
double a_double;
|
|
71
|
+
double b_double;
|
|
72
|
+
double omega_double;
|
|
73
|
+
int sine_integer;
|
|
59
74
|
double epsabs;
|
|
60
75
|
double epsrel;
|
|
61
76
|
size_t limit;
|
|
77
|
+
int limit_given;
|
|
62
78
|
gsl_function function;
|
|
63
79
|
integration_callback_params params;
|
|
64
|
-
integration_qawo_params qawo_params;
|
|
80
|
+
integration_qawo_params qawo_params = {0};
|
|
65
81
|
double result;
|
|
66
82
|
double error;
|
|
67
83
|
int state = 0;
|
|
@@ -70,29 +86,44 @@ VALUE integration_qawo(int argc, VALUE *argv, VALUE self) {
|
|
|
70
86
|
|
|
71
87
|
rb_scan_args(argc, argv, "4:", &a, &b, &omega, &sine, &options);
|
|
72
88
|
|
|
73
|
-
|
|
89
|
+
if (!NIL_P(options)) {
|
|
90
|
+
rb_get_kwargs(options, keywords, 0, 5, keyword_values);
|
|
91
|
+
epsabs_value = keyword_values[0];
|
|
92
|
+
epsrel_value = keyword_values[1];
|
|
93
|
+
limit_value = keyword_values[2];
|
|
94
|
+
workspace_value = keyword_values[3];
|
|
95
|
+
table_value = keyword_values[4];
|
|
96
|
+
}
|
|
74
97
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
a_double = NUM2DBL(a);
|
|
99
|
+
b_double = NUM2DBL(b);
|
|
100
|
+
omega_double = NUM2DBL(omega);
|
|
101
|
+
sine_integer = NUM2INT(sine);
|
|
102
|
+
epsabs = epsabs_value == Qundef ? 0.0 : NUM2DBL(epsabs_value);
|
|
103
|
+
epsrel = epsrel_value == Qundef ? 1e-8 : NUM2DBL(epsrel_value);
|
|
104
|
+
limit = limit_value == Qundef ? 1000 : NUM2SIZET(limit_value);
|
|
105
|
+
limit_given = limit_value != Qundef;
|
|
78
106
|
|
|
79
107
|
integration_function_init(&function, ¶ms);
|
|
80
108
|
|
|
81
109
|
qawo_params.function = &function;
|
|
82
|
-
qawo_params.
|
|
83
|
-
qawo_params.
|
|
84
|
-
qawo_params.
|
|
85
|
-
qawo_params.
|
|
110
|
+
qawo_params.workspace_value = workspace_value;
|
|
111
|
+
qawo_params.table_value = table_value;
|
|
112
|
+
qawo_params.a = a_double;
|
|
113
|
+
qawo_params.b = b_double;
|
|
114
|
+
qawo_params.omega = omega_double;
|
|
115
|
+
qawo_params.sine = (enum gsl_integration_qawo_enum)sine_integer;
|
|
86
116
|
qawo_params.epsabs = epsabs;
|
|
87
117
|
qawo_params.epsrel = epsrel;
|
|
88
118
|
qawo_params.limit = limit;
|
|
89
|
-
qawo_params.
|
|
90
|
-
qawo_params.table = NULL;
|
|
119
|
+
qawo_params.limit_given = limit_given;
|
|
91
120
|
qawo_params.result = &result;
|
|
92
121
|
qawo_params.error = &error;
|
|
93
122
|
|
|
94
123
|
rb_protect(integration_run_qawo_with_resources, (VALUE)&qawo_params, &state);
|
|
95
124
|
|
|
125
|
+
RB_GC_GUARD(workspace_value);
|
|
126
|
+
RB_GC_GUARD(table_value);
|
|
96
127
|
RB_GC_GUARD(params.block);
|
|
97
128
|
RB_GC_GUARD(params.exception);
|
|
98
129
|
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
#include "integration_internal.h"
|
|
2
|
+
|
|
3
|
+
#include <float.h>
|
|
4
|
+
#include <math.h>
|
|
5
|
+
|
|
6
|
+
static VALUE integration_cQAWOTable;
|
|
7
|
+
|
|
8
|
+
static int integration_qawo_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_qawo_table_free(void *data) {
|
|
15
|
+
integration_qawo_table *table = data;
|
|
16
|
+
|
|
17
|
+
if (table->table != NULL) {
|
|
18
|
+
gsl_integration_qawo_table_free(table->table);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
xfree(table);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static size_t integration_qawo_table_memsize(const void *data) {
|
|
25
|
+
const integration_qawo_table *table = data;
|
|
26
|
+
|
|
27
|
+
if (table == NULL) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return sizeof(integration_qawo_table) +
|
|
32
|
+
(table->table == NULL ? 0
|
|
33
|
+
: sizeof(gsl_integration_qawo_table) +
|
|
34
|
+
25 * table->levels * sizeof(double));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static const rb_data_type_t integration_qawo_table_type = {
|
|
38
|
+
.wrap_struct_name = "Numo::GSL::Integration::QAWOTable",
|
|
39
|
+
.function =
|
|
40
|
+
{
|
|
41
|
+
.dmark = NULL,
|
|
42
|
+
.dfree = integration_qawo_table_free,
|
|
43
|
+
.dsize = integration_qawo_table_memsize,
|
|
44
|
+
},
|
|
45
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
static VALUE integration_qawo_table_allocate(VALUE klass) {
|
|
49
|
+
integration_qawo_table *table;
|
|
50
|
+
VALUE object = TypedData_Make_Struct(klass, integration_qawo_table,
|
|
51
|
+
&integration_qawo_table_type, table);
|
|
52
|
+
|
|
53
|
+
table->table = NULL;
|
|
54
|
+
table->omega = 0.0;
|
|
55
|
+
table->length = 0.0;
|
|
56
|
+
table->sine = GSL_INTEG_COSINE;
|
|
57
|
+
table->levels = 0;
|
|
58
|
+
table->busy = 0;
|
|
59
|
+
|
|
60
|
+
return object;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static VALUE integration_qawo_table_initialize(int argc, VALUE *argv,
|
|
64
|
+
VALUE self) {
|
|
65
|
+
VALUE options;
|
|
66
|
+
VALUE omega_value;
|
|
67
|
+
VALUE length_value;
|
|
68
|
+
VALUE sine_value;
|
|
69
|
+
VALUE levels_value;
|
|
70
|
+
ID keywords[] = {rb_intern("omega"), rb_intern("length"), rb_intern("sine"),
|
|
71
|
+
rb_intern("levels")};
|
|
72
|
+
VALUE keyword_values[4];
|
|
73
|
+
double omega;
|
|
74
|
+
double length;
|
|
75
|
+
int sine;
|
|
76
|
+
size_t levels;
|
|
77
|
+
integration_qawo_table *table;
|
|
78
|
+
|
|
79
|
+
rb_scan_args(argc, argv, "0:", &options);
|
|
80
|
+
|
|
81
|
+
if (NIL_P(options)) {
|
|
82
|
+
rb_raise(rb_eArgError, "missing keywords: :omega, :length, :sine, :levels");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
rb_get_kwargs(options, keywords, 4, 0, keyword_values);
|
|
86
|
+
omega_value = keyword_values[0];
|
|
87
|
+
length_value = keyword_values[1];
|
|
88
|
+
sine_value = keyword_values[2];
|
|
89
|
+
levels_value = keyword_values[3];
|
|
90
|
+
|
|
91
|
+
if (!rb_obj_is_kind_of(omega_value, rb_cNumeric)) {
|
|
92
|
+
rb_raise(rb_eTypeError, "omega must be Numeric");
|
|
93
|
+
}
|
|
94
|
+
if (!rb_obj_is_kind_of(length_value, rb_cNumeric)) {
|
|
95
|
+
rb_raise(rb_eTypeError, "length must be Numeric");
|
|
96
|
+
}
|
|
97
|
+
if (!RB_INTEGER_TYPE_P(sine_value)) {
|
|
98
|
+
rb_raise(rb_eTypeError, "sine must be an Integer");
|
|
99
|
+
}
|
|
100
|
+
if (!RB_INTEGER_TYPE_P(levels_value)) {
|
|
101
|
+
rb_raise(rb_eTypeError, "levels must be an Integer");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
omega = NUM2DBL(omega_value);
|
|
105
|
+
length = NUM2DBL(length_value);
|
|
106
|
+
sine = NUM2INT(sine_value);
|
|
107
|
+
|
|
108
|
+
if (length <= 0.0) {
|
|
109
|
+
rb_raise(rb_eArgError, "length must be positive");
|
|
110
|
+
}
|
|
111
|
+
if (sine != GSL_INTEG_SINE && sine != GSL_INTEG_COSINE) {
|
|
112
|
+
rb_raise(rb_eArgError, "sine must be SINE or COSINE");
|
|
113
|
+
}
|
|
114
|
+
if (RTEST(rb_funcall(levels_value, rb_intern("<="), 1, INT2FIX(0)))) {
|
|
115
|
+
rb_raise(rb_eArgError, "levels must be positive");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
levels = NUM2SIZET(levels_value);
|
|
119
|
+
TypedData_Get_Struct(self, integration_qawo_table,
|
|
120
|
+
&integration_qawo_table_type, table);
|
|
121
|
+
if (table->table != NULL) {
|
|
122
|
+
rb_raise(rb_eRuntimeError, "table is already initialized");
|
|
123
|
+
}
|
|
124
|
+
table->omega = omega;
|
|
125
|
+
table->length = length;
|
|
126
|
+
table->sine = (enum gsl_integration_qawo_enum)sine;
|
|
127
|
+
table->levels = levels;
|
|
128
|
+
table->table = gsl_integration_qawo_table_alloc(table->omega, table->length,
|
|
129
|
+
table->sine, table->levels);
|
|
130
|
+
|
|
131
|
+
if (table->table == NULL) {
|
|
132
|
+
rb_memerror();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return self;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static VALUE integration_qawo_table_omega(VALUE self) {
|
|
139
|
+
integration_qawo_table *table;
|
|
140
|
+
|
|
141
|
+
TypedData_Get_Struct(self, integration_qawo_table,
|
|
142
|
+
&integration_qawo_table_type, table);
|
|
143
|
+
|
|
144
|
+
return DBL2NUM(table->omega);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static VALUE integration_qawo_table_length(VALUE self) {
|
|
148
|
+
integration_qawo_table *table;
|
|
149
|
+
|
|
150
|
+
TypedData_Get_Struct(self, integration_qawo_table,
|
|
151
|
+
&integration_qawo_table_type, table);
|
|
152
|
+
|
|
153
|
+
return DBL2NUM(table->length);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static VALUE integration_qawo_table_sine(VALUE self) {
|
|
157
|
+
integration_qawo_table *table;
|
|
158
|
+
|
|
159
|
+
TypedData_Get_Struct(self, integration_qawo_table,
|
|
160
|
+
&integration_qawo_table_type, table);
|
|
161
|
+
|
|
162
|
+
return INT2NUM(table->sine);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
static VALUE integration_qawo_table_levels(VALUE self) {
|
|
166
|
+
integration_qawo_table *table;
|
|
167
|
+
|
|
168
|
+
TypedData_Get_Struct(self, integration_qawo_table,
|
|
169
|
+
&integration_qawo_table_type, table);
|
|
170
|
+
|
|
171
|
+
return SIZET2NUM(table->levels);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static VALUE integration_qawo_table_closed_p(VALUE self) {
|
|
175
|
+
integration_qawo_table *table;
|
|
176
|
+
|
|
177
|
+
TypedData_Get_Struct(self, integration_qawo_table,
|
|
178
|
+
&integration_qawo_table_type, table);
|
|
179
|
+
|
|
180
|
+
return table->table == NULL ? Qtrue : Qfalse;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
static VALUE integration_qawo_table_close(VALUE self) {
|
|
184
|
+
integration_qawo_table *table;
|
|
185
|
+
|
|
186
|
+
TypedData_Get_Struct(self, integration_qawo_table,
|
|
187
|
+
&integration_qawo_table_type, table);
|
|
188
|
+
|
|
189
|
+
if (table->busy) {
|
|
190
|
+
rb_raise(rb_eRuntimeError, "table is already in use");
|
|
191
|
+
}
|
|
192
|
+
if (table->table != NULL) {
|
|
193
|
+
gsl_integration_qawo_table_free(table->table);
|
|
194
|
+
table->table = NULL;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return Qnil;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
static VALUE integration_qawo_table_yield(VALUE table) {
|
|
201
|
+
return rb_yield(table);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
static VALUE integration_qawo_table_open(int argc, VALUE *argv, VALUE klass) {
|
|
205
|
+
VALUE table;
|
|
206
|
+
|
|
207
|
+
table = rb_funcallv_kw(klass, rb_intern("new"), argc, argv, RB_PASS_KEYWORDS);
|
|
208
|
+
|
|
209
|
+
return rb_ensure(integration_qawo_table_yield, table,
|
|
210
|
+
integration_qawo_table_close, table);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
void integration_qawo_table_use_begin(VALUE table_value, double omega,
|
|
214
|
+
double length,
|
|
215
|
+
enum gsl_integration_qawo_enum sine,
|
|
216
|
+
size_t levels,
|
|
217
|
+
integration_qawo_table_use *use) {
|
|
218
|
+
integration_qawo_table *table;
|
|
219
|
+
|
|
220
|
+
use->table = NULL;
|
|
221
|
+
use->owner = NULL;
|
|
222
|
+
|
|
223
|
+
if (table_value == Qundef) {
|
|
224
|
+
use->table = gsl_integration_qawo_table_alloc(omega, length, sine, levels);
|
|
225
|
+
if (use->table == NULL) {
|
|
226
|
+
rb_memerror();
|
|
227
|
+
}
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (!rb_obj_is_kind_of(table_value, integration_cQAWOTable)) {
|
|
232
|
+
rb_raise(rb_eTypeError,
|
|
233
|
+
"table must be a Numo::GSL::Integration::QAWOTable");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
TypedData_Get_Struct(table_value, integration_qawo_table,
|
|
237
|
+
&integration_qawo_table_type, table);
|
|
238
|
+
|
|
239
|
+
if (table->table == NULL) {
|
|
240
|
+
rb_raise(rb_eRuntimeError, "table is closed");
|
|
241
|
+
}
|
|
242
|
+
if (table->busy) {
|
|
243
|
+
rb_raise(rb_eRuntimeError, "table is already in use");
|
|
244
|
+
}
|
|
245
|
+
if (!integration_qawo_table_double_equal(table->omega, omega)) {
|
|
246
|
+
rb_raise(rb_eArgError, "omega does not match QAWO table");
|
|
247
|
+
}
|
|
248
|
+
if (!integration_qawo_table_double_equal(table->length, length)) {
|
|
249
|
+
rb_raise(rb_eArgError, "interval length does not match QAWO table");
|
|
250
|
+
}
|
|
251
|
+
if (table->sine != sine) {
|
|
252
|
+
rb_raise(rb_eArgError, "sine does not match QAWO table");
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
table->busy = 1;
|
|
256
|
+
use->table = table->table;
|
|
257
|
+
use->owner = table;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
VALUE integration_qawo_table_use_end(VALUE data) {
|
|
261
|
+
integration_qawo_table_use *use = (integration_qawo_table_use *)data;
|
|
262
|
+
|
|
263
|
+
if (use->owner != NULL) {
|
|
264
|
+
use->owner->busy = 0;
|
|
265
|
+
} else if (use->table != NULL) {
|
|
266
|
+
gsl_integration_qawo_table_free(use->table);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
use->table = NULL;
|
|
270
|
+
use->owner = NULL;
|
|
271
|
+
|
|
272
|
+
return Qnil;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
void integration_qawo_table_init(VALUE integration_module) {
|
|
276
|
+
integration_cQAWOTable =
|
|
277
|
+
rb_define_class_under(integration_module, "QAWOTable", rb_cObject);
|
|
278
|
+
rb_define_alloc_func(integration_cQAWOTable, integration_qawo_table_allocate);
|
|
279
|
+
rb_define_method(integration_cQAWOTable, "initialize",
|
|
280
|
+
integration_qawo_table_initialize, -1);
|
|
281
|
+
rb_define_method(integration_cQAWOTable, "omega",
|
|
282
|
+
integration_qawo_table_omega, 0);
|
|
283
|
+
rb_define_method(integration_cQAWOTable, "length",
|
|
284
|
+
integration_qawo_table_length, 0);
|
|
285
|
+
rb_define_method(integration_cQAWOTable, "sine", integration_qawo_table_sine,
|
|
286
|
+
0);
|
|
287
|
+
rb_define_method(integration_cQAWOTable, "levels",
|
|
288
|
+
integration_qawo_table_levels, 0);
|
|
289
|
+
rb_define_method(integration_cQAWOTable, "closed?",
|
|
290
|
+
integration_qawo_table_closed_p, 0);
|
|
291
|
+
rb_define_method(integration_cQAWOTable, "close",
|
|
292
|
+
integration_qawo_table_close, 0);
|
|
293
|
+
rb_define_singleton_method(integration_cQAWOTable, "open",
|
|
294
|
+
integration_qawo_table_open, -1);
|
|
295
|
+
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
typedef struct {
|
|
4
4
|
gsl_function *function;
|
|
5
|
+
VALUE workspace_value;
|
|
6
|
+
VALUE table_value;
|
|
5
7
|
double a;
|
|
6
8
|
double b;
|
|
7
9
|
double alpha;
|
|
@@ -11,8 +13,11 @@ typedef struct {
|
|
|
11
13
|
double epsabs;
|
|
12
14
|
double epsrel;
|
|
13
15
|
size_t limit;
|
|
16
|
+
int limit_given;
|
|
14
17
|
gsl_integration_workspace *workspace;
|
|
18
|
+
integration_workspace_use workspace_use;
|
|
15
19
|
gsl_integration_qaws_table *table;
|
|
20
|
+
integration_qaws_table_use table_use;
|
|
16
21
|
double *result;
|
|
17
22
|
double *error;
|
|
18
23
|
} integration_qaws_params;
|
|
@@ -20,13 +25,8 @@ typedef struct {
|
|
|
20
25
|
static VALUE integration_free_qaws_resources(VALUE data) {
|
|
21
26
|
integration_qaws_params *params = (integration_qaws_params *)data;
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (params->workspace != NULL) {
|
|
28
|
-
gsl_integration_workspace_free(params->workspace);
|
|
29
|
-
}
|
|
28
|
+
integration_qaws_table_use_end((VALUE)¶ms->table_use);
|
|
29
|
+
integration_workspace_use_end((VALUE)¶ms->workspace_use);
|
|
30
30
|
|
|
31
31
|
return Qnil;
|
|
32
32
|
}
|
|
@@ -34,9 +34,13 @@ static VALUE integration_free_qaws_resources(VALUE data) {
|
|
|
34
34
|
static VALUE integration_run_qaws(VALUE data) {
|
|
35
35
|
integration_qaws_params *params = (integration_qaws_params *)data;
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
params->workspace =
|
|
37
|
+
integration_workspace_use_begin(params->workspace_value, ¶ms->limit,
|
|
38
|
+
params->limit_given, ¶ms->workspace_use);
|
|
39
|
+
params->workspace = params->workspace_use.workspace;
|
|
40
|
+
integration_qaws_table_use_begin(params->table_value, params->alpha,
|
|
41
|
+
params->beta, params->mu, params->nu,
|
|
42
|
+
¶ms->table_use);
|
|
43
|
+
params->table = params->table_use.table;
|
|
40
44
|
|
|
41
45
|
(void)gsl_integration_qaws(params->function, params->a, params->b,
|
|
42
46
|
params->table, params->epsabs, params->epsrel,
|
|
@@ -59,13 +63,27 @@ VALUE integration_qaws(int argc, VALUE *argv, VALUE self) {
|
|
|
59
63
|
VALUE mu;
|
|
60
64
|
VALUE nu;
|
|
61
65
|
VALUE options;
|
|
62
|
-
|
|
66
|
+
VALUE epsabs_value = Qundef;
|
|
67
|
+
VALUE epsrel_value = Qundef;
|
|
68
|
+
VALUE limit_value = Qundef;
|
|
69
|
+
VALUE workspace_value = Qundef;
|
|
70
|
+
VALUE table_value = Qundef;
|
|
71
|
+
ID keywords[] = {rb_intern("epsabs"), rb_intern("epsrel"), rb_intern("limit"),
|
|
72
|
+
rb_intern("workspace"), rb_intern("table")};
|
|
73
|
+
VALUE keyword_values[5];
|
|
74
|
+
double a_double;
|
|
75
|
+
double b_double;
|
|
76
|
+
double alpha_double;
|
|
77
|
+
double beta_double;
|
|
78
|
+
int mu_integer;
|
|
79
|
+
int nu_integer;
|
|
63
80
|
double epsabs;
|
|
64
81
|
double epsrel;
|
|
65
82
|
size_t limit;
|
|
83
|
+
int limit_given;
|
|
66
84
|
gsl_function function;
|
|
67
85
|
integration_callback_params params;
|
|
68
|
-
integration_qaws_params qaws_params;
|
|
86
|
+
integration_qaws_params qaws_params = {0};
|
|
69
87
|
double result;
|
|
70
88
|
double error;
|
|
71
89
|
int state = 0;
|
|
@@ -74,31 +92,48 @@ VALUE integration_qaws(int argc, VALUE *argv, VALUE self) {
|
|
|
74
92
|
|
|
75
93
|
rb_scan_args(argc, argv, "6:", &a, &b, &alpha, &beta, &mu, &nu, &options);
|
|
76
94
|
|
|
77
|
-
|
|
95
|
+
if (!NIL_P(options)) {
|
|
96
|
+
rb_get_kwargs(options, keywords, 0, 5, keyword_values);
|
|
97
|
+
epsabs_value = keyword_values[0];
|
|
98
|
+
epsrel_value = keyword_values[1];
|
|
99
|
+
limit_value = keyword_values[2];
|
|
100
|
+
workspace_value = keyword_values[3];
|
|
101
|
+
table_value = keyword_values[4];
|
|
102
|
+
}
|
|
78
103
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
104
|
+
a_double = NUM2DBL(a);
|
|
105
|
+
b_double = NUM2DBL(b);
|
|
106
|
+
alpha_double = NUM2DBL(alpha);
|
|
107
|
+
beta_double = NUM2DBL(beta);
|
|
108
|
+
mu_integer = NUM2INT(mu);
|
|
109
|
+
nu_integer = NUM2INT(nu);
|
|
110
|
+
epsabs = epsabs_value == Qundef ? 0.0 : NUM2DBL(epsabs_value);
|
|
111
|
+
epsrel = epsrel_value == Qundef ? 1e-8 : NUM2DBL(epsrel_value);
|
|
112
|
+
limit = limit_value == Qundef ? 1000 : NUM2SIZET(limit_value);
|
|
113
|
+
limit_given = limit_value != Qundef;
|
|
82
114
|
|
|
83
115
|
integration_function_init(&function, ¶ms);
|
|
84
116
|
|
|
85
117
|
qaws_params.function = &function;
|
|
86
|
-
qaws_params.
|
|
87
|
-
qaws_params.
|
|
88
|
-
qaws_params.
|
|
89
|
-
qaws_params.
|
|
90
|
-
qaws_params.
|
|
91
|
-
qaws_params.
|
|
118
|
+
qaws_params.workspace_value = workspace_value;
|
|
119
|
+
qaws_params.table_value = table_value;
|
|
120
|
+
qaws_params.a = a_double;
|
|
121
|
+
qaws_params.b = b_double;
|
|
122
|
+
qaws_params.alpha = alpha_double;
|
|
123
|
+
qaws_params.beta = beta_double;
|
|
124
|
+
qaws_params.mu = mu_integer;
|
|
125
|
+
qaws_params.nu = nu_integer;
|
|
92
126
|
qaws_params.epsabs = epsabs;
|
|
93
127
|
qaws_params.epsrel = epsrel;
|
|
94
128
|
qaws_params.limit = limit;
|
|
95
|
-
qaws_params.
|
|
96
|
-
qaws_params.table = NULL;
|
|
129
|
+
qaws_params.limit_given = limit_given;
|
|
97
130
|
qaws_params.result = &result;
|
|
98
131
|
qaws_params.error = &error;
|
|
99
132
|
|
|
100
133
|
rb_protect(integration_run_qaws_with_resources, (VALUE)&qaws_params, &state);
|
|
101
134
|
|
|
135
|
+
RB_GC_GUARD(workspace_value);
|
|
136
|
+
RB_GC_GUARD(table_value);
|
|
102
137
|
RB_GC_GUARD(params.block);
|
|
103
138
|
RB_GC_GUARD(params.exception);
|
|
104
139
|
|