ryeppp 0.0.4 → 0.0.5

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.
@@ -33,6 +33,12 @@ def initialize_yeppp
33
33
  assert(status == YepStatusOk);}
34
34
  end
35
35
 
36
+ def ensure_array_argument(var_name, var_position)
37
+ %{if (TYPE(#{var_name}) != T_ARRAY) {
38
+ rb_raise(rb_eArgError, "#{var_position} argument was not an Array");
39
+ }}
40
+ end
41
+
36
42
  def guard_integer_input_size(var_name, iteration_var_name, allocated_arrays)
37
43
  %{if (rb_funcall(#{var_name}_a[#{iteration_var_name}], '>', 1, #{MAX_SIGNED_INTEGER})) {
38
44
  #{release_array_memory allocated_arrays}
@@ -145,20 +151,18 @@ FUNCS = Proc.new do |verb_name|
145
151
  Yep64{{type}} mult_by;
146
152
  #{declare_yep64_typed_array(%w{x y})}
147
153
 
148
- if (TYPE(x) != T_ARRAY) {
149
- rb_raise(rb_eArgError, "first argument was not an Array");
150
- }
154
+ #{ensure_array_argument('x', 'first')}
151
155
  if (TYPE(multiply_by) != T_FIXNUM && TYPE(multiply_by) != T_BIGNUM && TYPE(multiply_by) != T_FLOAT) {
152
156
  rb_raise(rb_eArgError, "second argument was not an integer or a float");
153
157
  }
154
158
 
155
- /* Allocate arrays of inputs and outputs */
156
- #{allocate_yep64_typed_array(%w{x y}, 'l')}
157
-
158
159
  x_a = RARRAY_PTR(x);
159
160
  l = RARRAY_LEN(x);
160
161
  mult_by = (Yep64{{type}})NUM2DBL(multiply_by);
161
162
 
163
+ /* Allocate arrays of inputs and outputs */
164
+ #{allocate_yep64_typed_array(%w{x y}, 'l')}
165
+
162
166
  #{initialize_yeppp}
163
167
 
164
168
  #{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x y})}
@@ -190,12 +194,8 @@ FUNCS = Proc.new do |verb_name|
190
194
  long l;
191
195
  #{declare_yep64_typed_array(%w{x y z})}
192
196
 
193
- if (TYPE(x) != T_ARRAY) {
194
- rb_raise(rb_eArgError, "first argument was not an Array");
195
- }
196
- if (TYPE(y) != T_ARRAY) {
197
- rb_raise(rb_eArgError, "second argument was not an Array");
198
- }
197
+ #{ensure_array_argument('x', 'first')}
198
+ #{ensure_array_argument('y', 'second')}
199
199
 
200
200
  x_a = RARRAY_PTR(x);
201
201
  y_a = RARRAY_PTR(y);
@@ -236,12 +236,8 @@ DOT_PRODUCT = %{
236
236
  long l;
237
237
  #{declare_yep64_typed_array(%w{x y}, :type => 'f')}
238
238
 
239
- if (TYPE(x) != T_ARRAY) {
240
- rb_raise(rb_eArgError, "first argument was not an Array");
241
- }
242
- if (TYPE(y) != T_ARRAY) {
243
- rb_raise(rb_eArgError, "second argument was not an Array");
244
- }
239
+ #{ensure_array_argument('x', 'first')}
240
+ #{ensure_array_argument('y', 'second')}
245
241
 
246
242
  x_a = RARRAY_PTR(x);
247
243
  y_a = RARRAY_PTR(y);
@@ -278,9 +274,7 @@ MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
278
274
  long l;
279
275
  #{declare_yep64_typed_array(%w{x})}
280
276
 
281
- if (TYPE(x) != T_ARRAY) {
282
- rb_raise(rb_eArgError, "first argument was not an Array");
283
- }
277
+ #{ensure_array_argument('x', 'first')}
284
278
 
285
279
  x_a = RARRAY_PTR(x);
286
280
  l = RARRAY_LEN(x);
@@ -317,12 +311,8 @@ PAIRWISE_MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
317
311
  long l;
318
312
  #{declare_yep64_typed_array(%w{x y z})}
319
313
 
320
- if (TYPE(x) != T_ARRAY) {
321
- rb_raise(rb_eArgError, "first argument was not an Array");
322
- }
323
- if (TYPE(y) != T_ARRAY) {
324
- rb_raise(rb_eArgError, "second argument was not an Array");
325
- }
314
+ #{ensure_array_argument('x', 'first')}
315
+ #{ensure_array_argument('y', 'second')}
326
316
 
327
317
  x_a = RARRAY_PTR(x);
328
318
  y_a = RARRAY_PTR(y);
@@ -363,9 +353,7 @@ CONSTANT_MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
363
353
  Yep64f konst;
364
354
  #{declare_yep64_typed_array(%w{x y})}
365
355
 
366
- if (TYPE(x) != T_ARRAY) {
367
- rb_raise(rb_eArgError, "first argument was not an Array");
368
- }
356
+ #{ensure_array_argument('x', 'first')}
369
357
  if (TYPE(c) != T_FIXNUM && TYPE(c) != T_BIGNUM && TYPE(c) != T_FLOAT) {
370
358
  rb_raise(rb_eArgError, "second argument was not a number");
371
359
  }
@@ -406,9 +394,7 @@ NEGATE = typed_variants(%{
406
394
  long l;
407
395
  #{declare_yep64_typed_array(%w{x y})}
408
396
 
409
- if (TYPE(x) != T_ARRAY) {
410
- rb_raise(rb_eArgError, "first argument was not an Array");
411
- }
397
+ #{ensure_array_argument('x', 'first')}
412
398
 
413
399
  x_a = RARRAY_PTR(x);
414
400
  l = RARRAY_LEN(x);
@@ -444,9 +430,7 @@ SUMS = %w{Sum SumAbs SumSquares}.map do |kind|
444
430
  long l;
445
431
  #{declare_yep64_typed_array(%w{x}, :type => 'f')}
446
432
 
447
- if (TYPE(x) != T_ARRAY) {
448
- rb_raise(rb_eArgError, "first argument was not an Array");
449
- }
433
+ #{ensure_array_argument('x', 'first')}
450
434
 
451
435
  x_a = RARRAY_PTR(x);
452
436
  l = RARRAY_LEN(x);
@@ -482,9 +466,7 @@ MATHS = MATHS_KINDS.map do |kind|
482
466
  long l;
483
467
  #{declare_yep64_typed_array(%w{x y}, :type => 'f')}
484
468
 
485
- if (TYPE(x) != T_ARRAY) {
486
- rb_raise(rb_eArgError, "first argument was not an Array");
487
- }
469
+ #{ensure_array_argument('x', 'first')}
488
470
 
489
471
  x_a = RARRAY_PTR(x);
490
472
  l = RARRAY_LEN(x);
@@ -524,12 +506,8 @@ POLYNOMIAL = %{
524
506
  long y_l;
525
507
  #{declare_yep64_typed_array(%w{x y z}, :type => 'f')}
526
508
 
527
- if (TYPE(x) != T_ARRAY) {
528
- rb_raise(rb_eArgError, "first argument was not an Array");
529
- }
530
- if (TYPE(where) != T_ARRAY) {
531
- rb_raise(rb_eArgError, "second argument was not an Array");
532
- }
509
+ #{ensure_array_argument('x', 'first')}
510
+ #{ensure_array_argument('where', 'second')}
533
511
 
534
512
  x_a = RARRAY_PTR(x);
535
513
  y_a = RARRAY_PTR(where);
data/lib/ryeppp/bench.rb CHANGED
@@ -86,13 +86,20 @@ class Array
86
86
  inline do |builder|
87
87
  builder.c %{
88
88
  static VALUE c_dot_product_f(VALUE v2) {
89
- long n = RARRAY_LEN(self);
89
+ long n;
90
90
  double sum = 0.0;
91
-
92
- VALUE *x_a = RARRAY_PTR(self);
93
- VALUE *y_a = RARRAY_PTR(v2);
94
-
91
+ VALUE *x_a;
92
+ VALUE *y_a;
95
93
  long i;
94
+
95
+ if (TYPE(v2) != T_ARRAY) {
96
+ rb_raise(rb_eTypeError, "first argument was not an Array");
97
+ }
98
+
99
+ x_a = RARRAY_PTR(self);
100
+ y_a = RARRAY_PTR(v2);
101
+ n = RARRAY_LEN(self);
102
+
96
103
  for (i=0; i<n; i++) {
97
104
  if (TYPE(x_a[i]) != T_FIXNUM && TYPE(x_a[i]) != T_BIGNUM && TYPE(x_a[i]) != T_FLOAT) {
98
105
  rb_raise(rb_eTypeError, "input was not all integers and floats");
@@ -131,12 +138,19 @@ class Array
131
138
  }
132
139
  builder.c %{
133
140
  static VALUE c_evaluate_polynomial(VALUE x_v) {
134
- long n = RARRAY_LEN(self);
135
-
136
- VALUE *x_a = RARRAY_PTR(self);
137
- double x = NUM2DBL(x_v);
138
-
141
+ long n;
142
+ VALUE *x_a;
143
+ double x;
139
144
  long i;
145
+
146
+ if (TYPE(x_v) != T_FIXNUM && TYPE(x_v) != T_BIGNUM && TYPE(x_v) != T_FLOAT) {
147
+ rb_raise(rb_eTypeError, "first argument was not an integer or float");
148
+ }
149
+
150
+ x_a = RARRAY_PTR(self);
151
+ n = RARRAY_LEN(self);
152
+ x = NUM2DBL(x_v);
153
+
140
154
  for (i=0; i<n; i++) {
141
155
  if (TYPE(x_a[i]) != T_FIXNUM && TYPE(x_a[i]) != T_BIGNUM && TYPE(x_a[i]) != T_FLOAT) {
142
156
  rb_raise(rb_eTypeError, "input was not all integers and floats");
@@ -150,13 +164,21 @@ class Array
150
164
  builder.include('<math.h>')
151
165
  builder.c %{
152
166
  static VALUE c_evaluate_polynomial_iter(VALUE x_v) {
153
- long n = RARRAY_LEN(self);
154
-
155
- VALUE *x_a = RARRAY_PTR(self);
156
- double x = NUM2DBL(x_v);
157
- double res = 0;
158
-
167
+ long n;
168
+ VALUE *x_a;
169
+ double x;
170
+ double res;
159
171
  long i;
172
+
173
+ if (TYPE(x_v) != T_FIXNUM && TYPE(x_v) != T_BIGNUM && TYPE(x_v) != T_FLOAT) {
174
+ rb_raise(rb_eTypeError, "first argument was not an integer or float");
175
+ }
176
+
177
+ x_a = RARRAY_PTR(self);
178
+ n = RARRAY_LEN(self);
179
+ x = NUM2DBL(x_v);
180
+ res = 0;
181
+
160
182
  for (i=0; i<n; i++) {
161
183
  if (TYPE(x_a[i]) != T_FIXNUM && TYPE(x_a[i]) != T_BIGNUM && TYPE(x_a[i]) != T_FLOAT) {
162
184
  rb_raise(rb_eTypeError, "input was not all integers and floats");
@@ -1,3 +1,3 @@
1
1
  class Ryeppp
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ryeppp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-24 00:00:00.000000000 Z
12
+ date: 2013-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler