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.
@@ -21,24 +21,20 @@ static VALUE integration_run_qagiu(VALUE data) {
21
21
  return Qnil;
22
22
  }
23
23
 
24
- static VALUE integration_run_qagiu_with_workspace(VALUE data) {
25
- integration_qagiu_params *params = (integration_qagiu_params *)data;
26
-
27
- return rb_ensure(integration_run_qagiu, data, integration_free_workspace,
28
- (VALUE)params->workspace);
29
- }
30
-
31
24
  VALUE integration_qagiu(int argc, VALUE *argv, VALUE self) {
32
25
  VALUE a;
33
26
  VALUE options;
27
+ VALUE workspace_value;
34
28
  integration_options parsed_options;
29
+ double a_double;
35
30
  double epsabs;
36
31
  double epsrel;
37
32
  size_t limit;
38
- gsl_integration_workspace *workspace;
33
+ int limit_given;
39
34
  gsl_function function;
40
35
  integration_callback_params params;
41
36
  integration_qagiu_params qagiu_params;
37
+ integration_workspace_use workspace_use;
42
38
  double result;
43
39
  double error;
44
40
  int state = 0;
@@ -46,29 +42,33 @@ VALUE integration_qagiu(int argc, VALUE *argv, VALUE self) {
46
42
  (void)self;
47
43
 
48
44
  rb_scan_args(argc, argv, "1:", &a, &options);
45
+ integration_options_parse_with_workspace(options, &parsed_options, 0.0, 1e-8,
46
+ 1000, &workspace_value,
47
+ &limit_given);
49
48
 
50
- integration_options_parse(options, &parsed_options, 0.0, 1e-8, 1000);
51
-
49
+ a_double = NUM2DBL(a);
52
50
  epsabs = parsed_options.epsabs;
53
51
  epsrel = parsed_options.epsrel;
54
52
  limit = parsed_options.limit;
55
53
 
56
54
  integration_function_init(&function, &params);
57
55
 
58
- workspace = gsl_integration_workspace_alloc(limit);
56
+ integration_workspace_use_begin(workspace_value, &limit, limit_given,
57
+ &workspace_use);
59
58
 
60
59
  qagiu_params.function = &function;
61
- qagiu_params.a = NUM2DBL(a);
60
+ qagiu_params.a = a_double;
62
61
  qagiu_params.epsabs = epsabs;
63
62
  qagiu_params.epsrel = epsrel;
64
63
  qagiu_params.limit = limit;
65
- qagiu_params.workspace = workspace;
64
+ qagiu_params.workspace = workspace_use.workspace;
66
65
  qagiu_params.result = &result;
67
66
  qagiu_params.error = &error;
68
67
 
69
- rb_protect(integration_run_qagiu_with_workspace, (VALUE)&qagiu_params,
70
- &state);
68
+ rb_protect(integration_run_qagiu, (VALUE)&qagiu_params, &state);
69
+ integration_workspace_use_end((VALUE)&workspace_use);
71
70
 
71
+ RB_GC_GUARD(workspace_value);
72
72
  RB_GC_GUARD(params.block);
73
73
  RB_GC_GUARD(params.exception);
74
74
 
@@ -3,13 +3,16 @@
3
3
 
4
4
  typedef struct {
5
5
  VALUE points_array;
6
+ VALUE workspace_value;
6
7
  gsl_function *function;
7
8
  double *points;
8
9
  size_t point_count;
9
10
  double epsabs;
10
11
  double epsrel;
11
12
  size_t limit;
13
+ int limit_given;
12
14
  gsl_integration_workspace *workspace;
15
+ integration_workspace_use workspace_use;
13
16
  double *result;
14
17
  double *error;
15
18
  } integration_qagp_params;
@@ -62,7 +65,9 @@ static VALUE integration_run_qagp(VALUE data) {
62
65
  NUM2DBL(rb_ary_entry(params->points_array, (long)index));
63
66
  }
64
67
 
65
- params->workspace = gsl_integration_workspace_alloc(params->limit);
68
+ integration_workspace_use_begin(params->workspace_value, &params->limit,
69
+ params->limit_given, &params->workspace_use);
70
+ params->workspace = params->workspace_use.workspace;
66
71
 
67
72
  (void)gsl_integration_qagp(params->function, params->points,
68
73
  params->point_count, params->epsabs,
@@ -75,12 +80,11 @@ static VALUE integration_run_qagp(VALUE data) {
75
80
  static VALUE integration_free_qagp_resources(VALUE data) {
76
81
  integration_qagp_params *params = (integration_qagp_params *)data;
77
82
 
78
- if (params->workspace != NULL) {
79
- gsl_integration_workspace_free(params->workspace);
80
- }
83
+ integration_workspace_use_end((VALUE)&params->workspace_use);
81
84
 
82
85
  if (params->points != NULL) {
83
86
  xfree(params->points);
87
+ params->points = NULL;
84
88
  }
85
89
 
86
90
  return Qnil;
@@ -94,13 +98,15 @@ static VALUE integration_run_qagp_with_resources(VALUE data) {
94
98
  VALUE integration_qagp(int argc, VALUE *argv, VALUE self) {
95
99
  VALUE points;
96
100
  VALUE options;
101
+ VALUE workspace_value;
97
102
  integration_options parsed_options;
98
103
  double epsabs;
99
104
  double epsrel;
100
105
  size_t limit;
106
+ int limit_given;
101
107
  gsl_function function;
102
108
  integration_callback_params params;
103
- integration_qagp_params qagp_params;
109
+ integration_qagp_params qagp_params = {0};
104
110
  double result;
105
111
  double error;
106
112
  int state = 0;
@@ -111,7 +117,9 @@ VALUE integration_qagp(int argc, VALUE *argv, VALUE self) {
111
117
 
112
118
  integration_validate_qagp_points(points);
113
119
 
114
- integration_options_parse(options, &parsed_options, 0.0, 1e-8, 1000);
120
+ integration_options_parse_with_workspace(options, &parsed_options, 0.0, 1e-8,
121
+ 1000, &workspace_value,
122
+ &limit_given);
115
123
 
116
124
  epsabs = parsed_options.epsabs;
117
125
  epsrel = parsed_options.epsrel;
@@ -120,19 +128,20 @@ VALUE integration_qagp(int argc, VALUE *argv, VALUE self) {
120
128
  integration_function_init(&function, &params);
121
129
 
122
130
  qagp_params.points_array = points;
131
+ qagp_params.workspace_value = workspace_value;
123
132
  qagp_params.function = &function;
124
- qagp_params.points = NULL;
125
133
  qagp_params.point_count = (size_t)RARRAY_LEN(points);
126
134
  qagp_params.epsabs = epsabs;
127
135
  qagp_params.epsrel = epsrel;
128
136
  qagp_params.limit = limit;
129
- qagp_params.workspace = NULL;
137
+ qagp_params.limit_given = limit_given;
130
138
  qagp_params.result = &result;
131
139
  qagp_params.error = &error;
132
140
 
133
141
  rb_protect(integration_run_qagp_with_resources, (VALUE)&qagp_params, &state);
134
142
 
135
143
  RB_GC_GUARD(points);
144
+ RB_GC_GUARD(workspace_value);
136
145
  RB_GC_GUARD(params.block);
137
146
  RB_GC_GUARD(params.exception);
138
147
 
@@ -22,25 +22,22 @@ static VALUE integration_run_qags(VALUE data) {
22
22
  return Qnil;
23
23
  }
24
24
 
25
- static VALUE integration_run_qags_with_workspace(VALUE data) {
26
- integration_qags_params *params = (integration_qags_params *)data;
27
-
28
- return rb_ensure(integration_run_qags, data, integration_free_workspace,
29
- (VALUE)params->workspace);
30
- }
31
-
32
25
  VALUE integration_qags(int argc, VALUE *argv, VALUE self) {
33
26
  VALUE a;
34
27
  VALUE b;
35
28
  VALUE options;
29
+ VALUE workspace_value;
36
30
  integration_options parsed_options;
31
+ double a_double;
32
+ double b_double;
37
33
  double epsabs;
38
34
  double epsrel;
39
35
  size_t limit;
40
- gsl_integration_workspace *workspace;
36
+ int limit_given;
41
37
  gsl_function function;
42
38
  integration_callback_params params;
43
39
  integration_qags_params qags_params;
40
+ integration_workspace_use workspace_use;
44
41
  double result;
45
42
  double error;
46
43
  int state = 0;
@@ -48,29 +45,35 @@ VALUE integration_qags(int argc, VALUE *argv, VALUE self) {
48
45
  (void)self;
49
46
 
50
47
  rb_scan_args(argc, argv, "2:", &a, &b, &options);
48
+ integration_options_parse_with_workspace(options, &parsed_options, 0.0, 1e-8,
49
+ 1000, &workspace_value,
50
+ &limit_given);
51
51
 
52
- integration_options_parse(options, &parsed_options, 0.0, 1e-8, 1000);
53
-
52
+ a_double = NUM2DBL(a);
53
+ b_double = NUM2DBL(b);
54
54
  epsabs = parsed_options.epsabs;
55
55
  epsrel = parsed_options.epsrel;
56
56
  limit = parsed_options.limit;
57
57
 
58
58
  integration_function_init(&function, &params);
59
59
 
60
- workspace = gsl_integration_workspace_alloc(limit);
60
+ integration_workspace_use_begin(workspace_value, &limit, limit_given,
61
+ &workspace_use);
61
62
 
62
63
  qags_params.function = &function;
63
- qags_params.a = NUM2DBL(a);
64
- qags_params.b = NUM2DBL(b);
64
+ qags_params.a = a_double;
65
+ qags_params.b = b_double;
65
66
  qags_params.epsabs = epsabs;
66
67
  qags_params.epsrel = epsrel;
67
68
  qags_params.limit = limit;
68
- qags_params.workspace = workspace;
69
+ qags_params.workspace = workspace_use.workspace;
69
70
  qags_params.result = &result;
70
71
  qags_params.error = &error;
71
72
 
72
- rb_protect(integration_run_qags_with_workspace, (VALUE)&qags_params, &state);
73
+ rb_protect(integration_run_qags, (VALUE)&qags_params, &state);
74
+ integration_workspace_use_end((VALUE)&workspace_use);
73
75
 
76
+ RB_GC_GUARD(workspace_value);
74
77
  RB_GC_GUARD(params.block);
75
78
  RB_GC_GUARD(params.exception);
76
79
 
@@ -23,26 +23,24 @@ static VALUE integration_run_qawc(VALUE data) {
23
23
  return Qnil;
24
24
  }
25
25
 
26
- static VALUE integration_run_qawc_with_workspace(VALUE data) {
27
- integration_qawc_params *params = (integration_qawc_params *)data;
28
-
29
- return rb_ensure(integration_run_qawc, data, integration_free_workspace,
30
- (VALUE)params->workspace);
31
- }
32
-
33
26
  VALUE integration_qawc(int argc, VALUE *argv, VALUE self) {
34
27
  VALUE a;
35
28
  VALUE b;
36
29
  VALUE c;
37
30
  VALUE options;
31
+ VALUE workspace_value;
38
32
  integration_options parsed_options;
33
+ double a_double;
34
+ double b_double;
35
+ double c_double;
39
36
  double epsabs;
40
37
  double epsrel;
41
38
  size_t limit;
42
- gsl_integration_workspace *workspace;
39
+ int limit_given;
43
40
  gsl_function function;
44
41
  integration_callback_params params;
45
42
  integration_qawc_params qawc_params;
43
+ integration_workspace_use workspace_use;
46
44
  double result;
47
45
  double error;
48
46
  int state = 0;
@@ -50,30 +48,37 @@ VALUE integration_qawc(int argc, VALUE *argv, VALUE self) {
50
48
  (void)self;
51
49
 
52
50
  rb_scan_args(argc, argv, "3:", &a, &b, &c, &options);
51
+ integration_options_parse_with_workspace(options, &parsed_options, 0.0, 1e-8,
52
+ 1000, &workspace_value,
53
+ &limit_given);
53
54
 
54
- integration_options_parse(options, &parsed_options, 0.0, 1e-8, 1000);
55
-
55
+ a_double = NUM2DBL(a);
56
+ b_double = NUM2DBL(b);
57
+ c_double = NUM2DBL(c);
56
58
  epsabs = parsed_options.epsabs;
57
59
  epsrel = parsed_options.epsrel;
58
60
  limit = parsed_options.limit;
59
61
 
60
62
  integration_function_init(&function, &params);
61
63
 
62
- workspace = gsl_integration_workspace_alloc(limit);
64
+ integration_workspace_use_begin(workspace_value, &limit, limit_given,
65
+ &workspace_use);
63
66
 
64
67
  qawc_params.function = &function;
65
- qawc_params.a = NUM2DBL(a);
66
- qawc_params.b = NUM2DBL(b);
67
- qawc_params.c = NUM2DBL(c);
68
+ qawc_params.a = a_double;
69
+ qawc_params.b = b_double;
70
+ qawc_params.c = c_double;
68
71
  qawc_params.epsabs = epsabs;
69
72
  qawc_params.epsrel = epsrel;
70
73
  qawc_params.limit = limit;
71
- qawc_params.workspace = workspace;
74
+ qawc_params.workspace = workspace_use.workspace;
72
75
  qawc_params.result = &result;
73
76
  qawc_params.error = &error;
74
77
 
75
- rb_protect(integration_run_qawc_with_workspace, (VALUE)&qawc_params, &state);
78
+ rb_protect(integration_run_qawc, (VALUE)&qawc_params, &state);
79
+ integration_workspace_use_end((VALUE)&workspace_use);
76
80
 
81
+ RB_GC_GUARD(workspace_value);
77
82
  RB_GC_GUARD(params.block);
78
83
  RB_GC_GUARD(params.exception);
79
84
 
@@ -8,9 +8,14 @@ typedef struct {
8
8
  enum gsl_integration_qawo_enum sine;
9
9
  double epsabs;
10
10
  size_t limit;
11
- gsl_integration_workspace *workspace;
12
- gsl_integration_workspace *cycle_workspace;
13
- gsl_integration_qawo_table *table;
11
+ VALUE workspace_value;
12
+ VALUE cycle_workspace_value;
13
+ VALUE table_value;
14
+ integration_workspace_use workspace_use;
15
+ integration_workspace_use cycle_workspace_use;
16
+ integration_qawo_table_use table_use;
17
+ size_t cycle_workspace_native_limit;
18
+ int cycle_workspace_limit_changed;
14
19
  double *result;
15
20
  double *error;
16
21
  } integration_qawf_params;
@@ -18,17 +23,16 @@ typedef struct {
18
23
  static VALUE integration_free_qawf_resources(VALUE data) {
19
24
  integration_qawf_params *params = (integration_qawf_params *)data;
20
25
 
21
- if (params->table != NULL) {
22
- gsl_integration_qawo_table_free(params->table);
23
- }
26
+ integration_qawo_table_use_end((VALUE)&params->table_use);
24
27
 
25
- if (params->cycle_workspace != NULL) {
26
- gsl_integration_workspace_free(params->cycle_workspace);
28
+ if (params->cycle_workspace_limit_changed) {
29
+ params->cycle_workspace_use.workspace->limit =
30
+ params->cycle_workspace_native_limit;
31
+ params->cycle_workspace_limit_changed = 0;
27
32
  }
28
33
 
29
- if (params->workspace != NULL) {
30
- gsl_integration_workspace_free(params->workspace);
31
- }
34
+ integration_workspace_use_end((VALUE)&params->cycle_workspace_use);
35
+ integration_workspace_use_end((VALUE)&params->workspace_use);
32
36
 
33
37
  return Qnil;
34
38
  }
@@ -36,15 +40,25 @@ static VALUE integration_free_qawf_resources(VALUE data) {
36
40
  static VALUE integration_run_qawf(VALUE data) {
37
41
  integration_qawf_params *params = (integration_qawf_params *)data;
38
42
 
39
- params->table = gsl_integration_qawo_table_alloc(params->omega, 1.0,
40
- params->sine, params->limit);
41
- params->workspace = gsl_integration_workspace_alloc(params->limit);
42
- params->cycle_workspace = gsl_integration_workspace_alloc(params->limit);
43
+ integration_workspace_use_begin(params->workspace_value, &params->limit, 1,
44
+ &params->workspace_use);
45
+ integration_workspace_use_begin_named(
46
+ params->cycle_workspace_value, &params->limit, 1,
47
+ &params->cycle_workspace_use, "cycle_workspace");
48
+
49
+ params->cycle_workspace_native_limit =
50
+ params->cycle_workspace_use.workspace->limit;
51
+ params->cycle_workspace_use.workspace->limit = params->limit;
52
+ params->cycle_workspace_limit_changed = 1;
43
53
 
44
- (void)gsl_integration_qawf(params->function, params->a, params->epsabs,
45
- params->limit, params->workspace,
46
- params->cycle_workspace, params->table,
47
- params->result, params->error);
54
+ integration_qawf_table_use_begin(params->table_value, params->omega,
55
+ params->sine, params->limit,
56
+ &params->table_use);
57
+
58
+ (void)gsl_integration_qawf(
59
+ params->function, params->a, params->epsabs, params->limit,
60
+ params->workspace_use.workspace, params->cycle_workspace_use.workspace,
61
+ params->table_use.table, params->result, params->error);
48
62
 
49
63
  return Qnil;
50
64
  }
@@ -61,13 +75,23 @@ VALUE integration_qawf(int argc, VALUE *argv, VALUE self) {
61
75
  VALUE options;
62
76
  VALUE epsabs_value = Qundef;
63
77
  VALUE limit_value = Qundef;
64
- ID keywords[] = {rb_intern("epsabs"), rb_intern("limit")};
65
- VALUE keyword_values[2];
78
+ VALUE workspace_value = Qundef;
79
+ VALUE cycle_workspace_value = Qundef;
80
+ VALUE table_value = Qundef;
81
+ ID keywords[] = {rb_intern("epsabs"), rb_intern("limit"),
82
+ rb_intern("workspace"), rb_intern("cycle_workspace"),
83
+ rb_intern("table")};
84
+ VALUE keyword_values[5];
66
85
  double epsabs;
67
- size_t limit;
86
+ size_t limit = 1000;
87
+ size_t workspace_capacity = 0;
88
+ size_t cycle_workspace_capacity = 0;
89
+ int limit_given;
90
+ int workspace_given;
91
+ int cycle_workspace_given;
68
92
  gsl_function function;
69
93
  integration_callback_params params;
70
- integration_qawf_params qawf_params;
94
+ integration_qawf_params qawf_params = {0};
71
95
  double result;
72
96
  double error;
73
97
  int state = 0;
@@ -77,25 +101,74 @@ VALUE integration_qawf(int argc, VALUE *argv, VALUE self) {
77
101
  rb_scan_args(argc, argv, "3:", &a, &omega, &sine, &options);
78
102
 
79
103
  if (!NIL_P(options)) {
80
- rb_get_kwargs(options, keywords, 0, 2, keyword_values);
104
+ rb_get_kwargs(options, keywords, 0, 5, keyword_values);
81
105
  epsabs_value = keyword_values[0];
82
106
  limit_value = keyword_values[1];
107
+ workspace_value = keyword_values[2];
108
+ cycle_workspace_value = keyword_values[3];
109
+ table_value = keyword_values[4];
83
110
  }
84
111
 
112
+ qawf_params.a = NUM2DBL(a);
113
+ qawf_params.omega = NUM2DBL(omega);
114
+ if (!RB_INTEGER_TYPE_P(sine)) {
115
+ rb_raise(rb_eTypeError, "sine must be an Integer");
116
+ }
117
+ qawf_params.sine = (enum gsl_integration_qawo_enum)NUM2INT(sine);
118
+ if (qawf_params.sine != GSL_INTEG_SINE &&
119
+ qawf_params.sine != GSL_INTEG_COSINE) {
120
+ rb_raise(rb_eArgError, "sine must be SINE or COSINE");
121
+ }
85
122
  epsabs = epsabs_value == Qundef ? 1e-10 : NUM2DBL(epsabs_value);
86
- limit = limit_value == Qundef ? 1000 : NUM2SIZET(limit_value);
123
+ limit_given = limit_value != Qundef;
124
+ if (limit_given) {
125
+ limit = NUM2SIZET(limit_value);
126
+ }
127
+
128
+ workspace_given = workspace_value != Qundef;
129
+ cycle_workspace_given = cycle_workspace_value != Qundef;
130
+
131
+ if (workspace_given) {
132
+ workspace_capacity =
133
+ integration_workspace_capacity(workspace_value, "workspace");
134
+ }
135
+ if (cycle_workspace_given) {
136
+ cycle_workspace_capacity = integration_workspace_capacity(
137
+ cycle_workspace_value, "cycle_workspace");
138
+ }
139
+ if (workspace_given && cycle_workspace_given &&
140
+ workspace_value == cycle_workspace_value) {
141
+ rb_raise(rb_eArgError,
142
+ "workspace and cycle_workspace must be different objects");
143
+ }
144
+
145
+ if (!limit_given) {
146
+ if (workspace_given && cycle_workspace_given) {
147
+ limit = workspace_capacity < cycle_workspace_capacity
148
+ ? workspace_capacity
149
+ : cycle_workspace_capacity;
150
+ } else if (workspace_given) {
151
+ limit = workspace_capacity;
152
+ } else if (cycle_workspace_given) {
153
+ limit = cycle_workspace_capacity;
154
+ }
155
+ }
156
+
157
+ if (workspace_given && limit > workspace_capacity) {
158
+ rb_raise(rb_eArgError, "limit exceeds workspace capacity");
159
+ }
160
+ if (cycle_workspace_given && limit > cycle_workspace_capacity) {
161
+ rb_raise(rb_eArgError, "limit exceeds cycle_workspace capacity");
162
+ }
87
163
 
88
164
  integration_function_init(&function, &params);
89
165
 
90
166
  qawf_params.function = &function;
91
- qawf_params.a = NUM2DBL(a);
92
- qawf_params.omega = NUM2DBL(omega);
93
- qawf_params.sine = (enum gsl_integration_qawo_enum)NUM2INT(sine);
94
167
  qawf_params.epsabs = epsabs;
95
168
  qawf_params.limit = limit;
96
- qawf_params.workspace = NULL;
97
- qawf_params.cycle_workspace = NULL;
98
- qawf_params.table = NULL;
169
+ qawf_params.workspace_value = workspace_value;
170
+ qawf_params.cycle_workspace_value = cycle_workspace_value;
171
+ qawf_params.table_value = table_value;
99
172
  qawf_params.result = &result;
100
173
  qawf_params.error = &error;
101
174
 
@@ -103,6 +176,9 @@ VALUE integration_qawf(int argc, VALUE *argv, VALUE self) {
103
176
 
104
177
  RB_GC_GUARD(params.block);
105
178
  RB_GC_GUARD(params.exception);
179
+ RB_GC_GUARD(workspace_value);
180
+ RB_GC_GUARD(cycle_workspace_value);
181
+ RB_GC_GUARD(table_value);
106
182
 
107
183
  integration_finish_callback(&params, state);
108
184
 
@@ -0,0 +1,120 @@
1
+ #include "integration_internal.h"
2
+
3
+ #include <float.h>
4
+ #include <math.h>
5
+
6
+ static VALUE integration_cQAWFTable;
7
+
8
+ static double integration_qawf_cycle_length(double omega) {
9
+ double absolute_omega = fabs(omega);
10
+ double length =
11
+ (2.0 * (floor(absolute_omega) / absolute_omega) + 1.0 / absolute_omega) *
12
+ M_PI;
13
+
14
+ if (!isfinite(length) || length <= 0.0) {
15
+ rb_raise(rb_eArgError, "omega produces a non-finite cycle length");
16
+ }
17
+
18
+ return length;
19
+ }
20
+
21
+ static int integration_qawf_table_double_equal(double left, double right) {
22
+ double scale = fmax(fabs(left), fabs(right));
23
+
24
+ return fabs(left - right) <= DBL_EPSILON * fmax(1.0, scale) * 4.0;
25
+ }
26
+
27
+ static VALUE integration_qawf_table_initialize(int argc, VALUE *argv,
28
+ VALUE self) {
29
+ VALUE options;
30
+ VALUE omega_value;
31
+ VALUE sine_value;
32
+ VALUE levels_value;
33
+ VALUE qawo_options;
34
+ VALUE super_argv[1];
35
+ ID keywords[] = {rb_intern("omega"), rb_intern("sine"), rb_intern("levels")};
36
+ VALUE keyword_values[3];
37
+ double omega;
38
+ int sine;
39
+
40
+ rb_scan_args(argc, argv, "0:", &options);
41
+ if (NIL_P(options)) {
42
+ rb_raise(rb_eArgError, "missing keywords: :omega, :sine, :levels");
43
+ }
44
+ rb_get_kwargs(options, keywords, 3, 0, keyword_values);
45
+ omega_value = keyword_values[0];
46
+ sine_value = keyword_values[1];
47
+ levels_value = keyword_values[2];
48
+
49
+ if (!rb_obj_is_kind_of(omega_value, rb_cNumeric)) {
50
+ rb_raise(rb_eTypeError, "omega must be Numeric");
51
+ }
52
+ if (!RB_INTEGER_TYPE_P(sine_value)) {
53
+ rb_raise(rb_eTypeError, "sine must be an Integer");
54
+ }
55
+ if (!RB_INTEGER_TYPE_P(levels_value)) {
56
+ rb_raise(rb_eTypeError, "levels must be an Integer");
57
+ }
58
+
59
+ omega = NUM2DBL(omega_value);
60
+ sine = NUM2INT(sine_value);
61
+ if (!isfinite(omega) || omega == 0.0) {
62
+ rb_raise(rb_eArgError, "omega must be finite and nonzero");
63
+ }
64
+ if (sine != GSL_INTEG_SINE && sine != GSL_INTEG_COSINE) {
65
+ rb_raise(rb_eArgError, "sine must be SINE or COSINE");
66
+ }
67
+ if (RTEST(rb_funcall(levels_value, rb_intern("<="), 1, INT2FIX(0)))) {
68
+ rb_raise(rb_eArgError, "levels must be positive");
69
+ }
70
+
71
+ qawo_options = rb_hash_new();
72
+ rb_hash_aset(qawo_options, ID2SYM(rb_intern("omega")), omega_value);
73
+ rb_hash_aset(qawo_options, ID2SYM(rb_intern("length")),
74
+ DBL2NUM(integration_qawf_cycle_length(omega)));
75
+ rb_hash_aset(qawo_options, ID2SYM(rb_intern("sine")), sine_value);
76
+ rb_hash_aset(qawo_options, ID2SYM(rb_intern("levels")), levels_value);
77
+ super_argv[0] = qawo_options;
78
+
79
+ return rb_call_super_kw(1, super_argv, RB_PASS_KEYWORDS);
80
+ }
81
+
82
+ void integration_qawf_table_use_begin(VALUE table_value, double omega,
83
+ enum gsl_integration_qawo_enum sine,
84
+ size_t levels,
85
+ integration_qawo_table_use *use) {
86
+ double length = omega == 0.0 ? 1.0 : integration_qawf_cycle_length(omega);
87
+
88
+ if (table_value != Qundef) {
89
+ double table_omega;
90
+ enum gsl_integration_qawo_enum table_sine;
91
+
92
+ if (!rb_obj_is_kind_of(table_value, integration_cQAWFTable)) {
93
+ rb_raise(rb_eTypeError,
94
+ "table must be a Numo::GSL::Integration::QAWFTable");
95
+ }
96
+
97
+ table_omega = NUM2DBL(rb_funcall(table_value, rb_intern("omega"), 0));
98
+ table_sine = (enum gsl_integration_qawo_enum)NUM2INT(
99
+ rb_funcall(table_value, rb_intern("sine"), 0));
100
+ if (!integration_qawf_table_double_equal(table_omega, omega)) {
101
+ rb_raise(rb_eArgError, "omega does not match QAWF table");
102
+ }
103
+ if (table_sine != sine) {
104
+ rb_raise(rb_eArgError, "sine does not match QAWF table");
105
+ }
106
+ }
107
+
108
+ integration_qawo_table_use_begin(table_value, omega, length, sine, levels,
109
+ use);
110
+ }
111
+
112
+ void integration_qawf_table_init(VALUE integration_module) {
113
+ VALUE qawo_table_class =
114
+ rb_const_get(integration_module, rb_intern("QAWOTable"));
115
+
116
+ integration_cQAWFTable =
117
+ rb_define_class_under(integration_module, "QAWFTable", qawo_table_class);
118
+ rb_define_method(integration_cQAWFTable, "initialize",
119
+ integration_qawf_table_initialize, -1);
120
+ }