ryeppp 0.0.6 → 0.0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/extensiontask"
3
3
  require "rspec/core/rake_task"
4
+ require "version_bumper"
4
5
 
5
6
  spec = Gem::Specification.load('ryeppp.gemspec')
6
7
  Rake::ExtensionTask.new('ryeppp', spec)
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.7.0.0
@@ -1,6 +1,3 @@
1
- MAX_SIGNED_INTEGER = 2**63 - 1
2
- MIN_SIGNED_INTEGER = -1 * MAX_SIGNED_INTEGER
3
-
4
1
  class String
5
2
  def pluralize
6
3
  "#{self}#{self.size > 0 && self[-1] == 'e' ? 's' : 'es'}"
@@ -39,17 +36,6 @@ def ensure_array_argument(var_name, var_position)
39
36
  }}
40
37
  end
41
38
 
42
- def guard_integer_input_size(var_name, iteration_var_name, allocated_arrays)
43
- %{if (rb_funcall(#{var_name}_a[#{iteration_var_name}], '>', 1, #{MAX_SIGNED_INTEGER})) {
44
- #{release_array_memory allocated_arrays}
45
- rb_raise(rb_eRangeError, "input was too large for 64-bit signed integer");
46
- }
47
- if (rb_funcall(#{var_name}_a[#{iteration_var_name}], '<', 1, #{MIN_SIGNED_INTEGER})) {
48
- #{release_array_memory allocated_arrays}
49
- rb_raise(rb_eRangeError, "input was too small for 64-bit signed integer");
50
- }}
51
- end
52
-
53
39
  def load_ruby_array_from_yeppp_array(var_name, iteration_var_name, len_var_name, type)
54
40
  %{/* Load the Ruby Array */
55
41
  new_ary = rb_ary_new2(#{len_var_name});
@@ -81,7 +67,6 @@ def load_ruby_array_into_yeppp_array(var_name, iteration_var_name, len_var_name,
81
67
  #{release_array_memory opts[:allocated_arrays]}
82
68
  rb_raise(rb_eTypeError, "input was not all #{permitted_types.map(&:to_s).map(&:pluralize).join(' and ')}");
83
69
  }
84
- #{guard_integer_input_size(var_name, iteration_var_name, opts[:allocated_arrays])}
85
70
  yep_#{var_name}[#{opts[:reverse] ? "#{len_var_name} - #{iteration_var_name} - 1" : iteration_var_name}] = (Yep64#{type})NUM2#{type == 'f' ? 'DBL' : 'LONG'}(#{var_name}_a[#{iteration_var_name}]);
86
71
  }}
87
72
  end
@@ -92,7 +77,6 @@ def load_ruby_array_into_yeppp_array_parameterized(var_name, iteration_var_name,
92
77
  #{release_array_memory opts[:allocated_arrays]}
93
78
  rb_raise(rb_eTypeError, "input was not all {{ruby_klass_human}}");
94
79
  }
95
- #{guard_integer_input_size(var_name, iteration_var_name, opts[:allocated_arrays])}
96
80
  yep_#{var_name}[#{iteration_var_name}] = (Yep64{{type}})NUM2{{ruby_type}}(#{var_name}_a[#{iteration_var_name}]);
97
81
  }}
98
82
  end
@@ -150,7 +134,7 @@ FUNCS = Proc.new do |verb_name|
150
134
  long l;
151
135
  Yep64{{type}} mult_by;
152
136
  #{declare_yep64_typed_array(%w{x})}
153
-
137
+
154
138
  #{ensure_array_argument('x', 'first')}
155
139
  if (TYPE(multiply_by) != T_FIXNUM && TYPE(multiply_by) != T_BIGNUM && TYPE(multiply_by) != T_FLOAT) {
156
140
  rb_raise(rb_eArgError, "second argument was not an integer or a float");
@@ -162,21 +146,21 @@ FUNCS = Proc.new do |verb_name|
162
146
 
163
147
  /* Allocate arrays of inputs and outputs */
164
148
  #{allocate_yep64_typed_array(%w{x}, 'l')}
165
-
149
+
166
150
  #{initialize_yeppp}
167
-
151
+
168
152
  #{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x})}
169
-
153
+
170
154
  /* Perform the operation */
171
155
  status = yepCore_Multiply_IV64{{type}}S64{{type}}_IV64{{type}}(yep_x, mult_by, (YepSize)l);
172
156
  assert(status == YepStatusOk);
173
157
 
174
158
  #{load_ruby_array_from_yeppp_array_parameterized('x', 'i', 'l')}
175
-
159
+
176
160
  #{deinitialize_yeppp}
177
-
161
+
178
162
  #{release_array_memory(%w{x})}
179
-
163
+
180
164
  return new_ary;
181
165
  }
182
166
  }).strip.freeze
@@ -193,7 +177,7 @@ FUNCS = Proc.new do |verb_name|
193
177
  VALUE *y_a;
194
178
  long l;
195
179
  #{declare_yep64_typed_array(%w{x y})}
196
-
180
+
197
181
  #{ensure_array_argument('x', 'first')}
198
182
  #{ensure_array_argument('y', 'second')}
199
183
 
@@ -201,22 +185,26 @@ FUNCS = Proc.new do |verb_name|
201
185
  y_a = RARRAY_PTR(y);
202
186
  l = RARRAY_LEN(x);
203
187
 
188
+ if (l != RARRAY_LEN(y)) {
189
+ rb_raise(rb_eArgError, "given array arguments have different lengths");
190
+ }
191
+
204
192
  /* Allocate arrays of inputs and outputs */
205
193
  #{allocate_yep64_typed_array(%w{x y}, 'l')}
206
194
 
207
195
  #{initialize_yeppp}
208
-
196
+
209
197
  #{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x y})}
210
198
  #{load_ruby_array_into_yeppp_array_parameterized('y', 'i', 'l', :allocated_arrays => %w{x y})}
211
-
199
+
212
200
  /* Perform the #{verb_name} */
213
201
  status = yepCore_#{verb_name}_IV64{{type}}V64{{type}}_IV64{{type}}(yep_x, yep_y, (YepSize)l);
214
202
  assert(status == YepStatusOk);
215
203
 
216
204
  #{load_ruby_array_from_yeppp_array_parameterized('x', 'i', 'l')}
217
-
205
+
218
206
  #{deinitialize_yeppp}
219
-
207
+
220
208
  #{release_array_memory(%w{x y})}
221
209
 
222
210
  return new_ary;
@@ -235,7 +223,7 @@ DOT_PRODUCT = %{
235
223
  VALUE *y_a;
236
224
  long l;
237
225
  #{declare_yep64_typed_array(%w{x y}, :type => 'f')}
238
-
226
+
239
227
  #{ensure_array_argument('x', 'first')}
240
228
  #{ensure_array_argument('y', 'second')}
241
229
 
@@ -243,22 +231,26 @@ DOT_PRODUCT = %{
243
231
  y_a = RARRAY_PTR(y);
244
232
  l = RARRAY_LEN(x);
245
233
 
234
+ if (l != RARRAY_LEN(y)) {
235
+ rb_raise(rb_eArgError, "given array arguments have different lengths");
236
+ }
237
+
246
238
  /* Allocate arrays of inputs and outputs */
247
239
  #{allocate_yep64_typed_array(%w{x y}, 'l', :type => 'f')}
248
240
 
249
241
  #{initialize_yeppp}
250
-
242
+
251
243
  #{load_ruby_array_into_yeppp_array('x', 'i', 'l', 'f', [:integer, :float], :allocated_arrays => %w{x y})}
252
244
  #{load_ruby_array_into_yeppp_array('y', 'i', 'l', 'f', [:integer, :float], :allocated_arrays => %w{x y})}
253
-
245
+
254
246
  /* Perform the operation */
255
247
  status = yepCore_DotProduct_V64fV64f_S64f(yep_x, yep_y, &dp, (YepSize)l);
256
248
  assert(status == YepStatusOk);
257
249
 
258
250
  #{deinitialize_yeppp}
259
-
251
+
260
252
  #{release_array_memory(%w{x y})}
261
-
253
+
262
254
  return DBL2NUM((double)dp);
263
255
  }
264
256
  }.strip
@@ -283,17 +275,17 @@ MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
283
275
  #{allocate_yep64_typed_array('x', 'l')}
284
276
 
285
277
  #{initialize_yeppp}
286
-
278
+
287
279
  #{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x})}
288
-
280
+
289
281
  /* Perform the operation */
290
282
  status = yepCore_#{kind}_V64{{type}}_S64{{type}}(yep_x, &#{kind.downcase}, (YepSize)l);
291
283
  assert(status == YepStatusOk);
292
284
 
293
285
  #{deinitialize_yeppp}
294
-
286
+
295
287
  #{release_array_memory(%w{x})}
296
-
288
+
297
289
  return {{ruby_type}}2NUM(({{c_type}})#{kind.downcase});
298
290
  }
299
291
  }.strip
@@ -310,7 +302,7 @@ PAIRWISE_MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
310
302
  VALUE *y_a;
311
303
  long l;
312
304
  #{declare_yep64_typed_array(%w{x y})}
313
-
305
+
314
306
  #{ensure_array_argument('x', 'first')}
315
307
  #{ensure_array_argument('y', 'second')}
316
308
 
@@ -318,14 +310,18 @@ PAIRWISE_MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
318
310
  y_a = RARRAY_PTR(y);
319
311
  l = RARRAY_LEN(x);
320
312
 
313
+ if (l != RARRAY_LEN(y)) {
314
+ rb_raise(rb_eArgError, "given array arguments have different lengths");
315
+ }
316
+
321
317
  /* Allocate arrays of inputs and outputs */
322
318
  #{allocate_yep64_typed_array(%w{x y}, 'l')}
323
319
 
324
320
  #{initialize_yeppp}
325
-
321
+
326
322
  #{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x y})}
327
323
  #{load_ruby_array_into_yeppp_array_parameterized('y', 'i', 'l', :allocated_arrays => %w{x y})}
328
-
324
+
329
325
  /* Perform the operation */
330
326
  status = yepCore_#{kind}_IV64{{type}}V64{{type}}_IV64{{type}}(yep_x, yep_y, (YepSize)l);
331
327
  assert(status == YepStatusOk);
@@ -333,9 +329,9 @@ PAIRWISE_MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
333
329
  #{load_ruby_array_from_yeppp_array_parameterized('x', 'i', 'l')}
334
330
 
335
331
  #{deinitialize_yeppp}
336
-
332
+
337
333
  #{release_array_memory(%w{x y})}
338
-
334
+
339
335
  return new_ary;
340
336
  }
341
337
  }.strip
@@ -352,7 +348,7 @@ CONSTANT_MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
352
348
  long l;
353
349
  Yep64f konst;
354
350
  #{declare_yep64_typed_array(%w{x})}
355
-
351
+
356
352
  #{ensure_array_argument('x', 'first')}
357
353
  if (TYPE(c) != T_FIXNUM && TYPE(c) != T_BIGNUM && TYPE(c) != T_FLOAT) {
358
354
  rb_raise(rb_eArgError, "second argument was not a number");
@@ -366,9 +362,9 @@ CONSTANT_MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
366
362
  #{allocate_yep64_typed_array(%w{x}, 'l')}
367
363
 
368
364
  #{initialize_yeppp}
369
-
365
+
370
366
  #{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x})}
371
-
367
+
372
368
  /* Perform the operation */
373
369
  status = yepCore_#{kind}_IV64{{type}}S64{{type}}_IV64{{type}}(yep_x, konst, (YepSize)l);
374
370
  assert(status == YepStatusOk);
@@ -376,9 +372,9 @@ CONSTANT_MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
376
372
  #{load_ruby_array_from_yeppp_array_parameterized('x', 'i', 'l')}
377
373
 
378
374
  #{deinitialize_yeppp}
379
-
375
+
380
376
  #{release_array_memory(%w{x})}
381
-
377
+
382
378
  return new_ary;
383
379
  }
384
380
  }.strip
@@ -401,21 +397,21 @@ NEGATE = typed_variants(%{
401
397
 
402
398
  /* Allocate arrays of inputs and outputs */
403
399
  #{allocate_yep64_typed_array(%w{x}, 'l')}
404
-
400
+
405
401
  #{initialize_yeppp}
406
-
402
+
407
403
  #{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x})}
408
-
404
+
409
405
  /* Perform the negation */
410
406
  status = yepCore_Negate_IV64{{type}}_IV64{{type}}(yep_x, (YepSize)l);
411
407
  assert(status == YepStatusOk);
412
-
408
+
413
409
  #{load_ruby_array_from_yeppp_array_parameterized('x', 'i', 'l')}
414
-
410
+
415
411
  #{deinitialize_yeppp}
416
-
412
+
417
413
  #{release_array_memory(%w{x})}
418
-
414
+
419
415
  return new_ary;
420
416
  }
421
417
  }).freeze
@@ -447,7 +443,7 @@ SUMS = %w{Sum SumAbs SumSquares}.map do |kind|
447
443
  assert(status == YepStatusOk);
448
444
 
449
445
  #{deinitialize_yeppp}
450
-
446
+
451
447
  #{release_array_memory(%w{x})}
452
448
 
453
449
  return DBL2NUM((double)sum);
@@ -485,7 +481,7 @@ MATHS = MATHS_KINDS.map do |kind|
485
481
  #{load_ruby_array_from_yeppp_array('y', 'i', 'l', 'f')}
486
482
 
487
483
  #{deinitialize_yeppp}
488
-
484
+
489
485
  #{release_array_memory(%w{x y})}
490
486
 
491
487
  return new_ary;
@@ -532,9 +528,9 @@ POLYNOMIAL = %{
532
528
  #{load_ruby_array_from_yeppp_array('z', 'i', 'y_l', 'f')}
533
529
 
534
530
  #{deinitialize_yeppp}
535
-
531
+
536
532
  #{release_array_memory(%w{x y z})}
537
-
533
+
538
534
  return new_ary;
539
535
  }
540
536
  }.strip.freeze
@@ -1,6 +1,2 @@
1
1
  require "ryeppp/version"
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), 'ryeppp.so')
3
-
4
- #module Carray
5
- # # Your code goes here...
6
- #end
@@ -1,10 +1,13 @@
1
1
  require 'benchmark'
2
2
  require 'inline'
3
+ require 'trollop'
3
4
 
4
5
  $:<< './lib'
5
6
  require 'ryeppp'
6
7
 
7
- VERBOSE = %w{1 t true y yes}.include?(ENV['VERBOSE'])
8
+ $opts = Trollop::options do
9
+ opt :verbose, 'Verbose'
10
+ end
8
11
 
9
12
  def puts_with_pounds(s)
10
13
  puts "\n\n#{s} #{'#' * (79 - s.size)}"
@@ -25,7 +28,7 @@ class Array
25
28
  long n = RARRAY_LEN(self);
26
29
  VALUE *x_a = RARRAY_PTR(self);
27
30
  double minimum = x_a[0];
28
-
31
+
29
32
  long i;
30
33
  for (i=1; i<n; i++) {
31
34
  if (TYPE(x_a[i]) != T_FIXNUM && TYPE(x_a[i]) != T_BIGNUM && TYPE(x_a[i]) != T_FLOAT) {
@@ -44,7 +47,7 @@ class Array
44
47
  long n = RARRAY_LEN(self);
45
48
  VALUE *x_a = RARRAY_PTR(self);
46
49
  long minimum = x_a[0];
47
-
50
+
48
51
  long i;
49
52
  for (i=1; i<n; i++) {
50
53
  if (TYPE(x_a[i]) != T_FIXNUM && TYPE(x_a[i]) != T_BIGNUM && TYPE(x_a[i]) != T_FLOAT) {
@@ -63,7 +66,7 @@ class Array
63
66
  long n = RARRAY_LEN(self);
64
67
  VALUE *x_a = RARRAY_PTR(self);
65
68
  double maximum = x_a[0];
66
-
69
+
67
70
  long i;
68
71
  for (i=1; i<n; i++) {
69
72
  if (TYPE(x_a[i]) != T_FIXNUM && TYPE(x_a[i]) != T_BIGNUM && TYPE(x_a[i]) != T_FLOAT) {
@@ -82,7 +85,7 @@ class Array
82
85
  long n = RARRAY_LEN(self);
83
86
  VALUE *x_a = RARRAY_PTR(self);
84
87
  long maximum = x_a[0];
85
-
88
+
86
89
  long i;
87
90
  for (i=1; i<n; i++) {
88
91
  if (TYPE(x_a[i]) != T_FIXNUM && TYPE(x_a[i]) != T_BIGNUM && TYPE(x_a[i]) != T_FLOAT) {
@@ -113,7 +116,7 @@ class Array
113
116
  VALUE *x_a = RARRAY_PTR(self);
114
117
  VALUE *x_b = RARRAY_PTR(b);
115
118
  VALUE new_ary = rb_ary_new2(n);
116
-
119
+
117
120
  long i;
118
121
 
119
122
  if (n != RARRAY_LEN(b)) {
@@ -131,7 +134,7 @@ class Array
131
134
  VALUE *x_a = RARRAY_PTR(self);
132
135
  VALUE *x_b = RARRAY_PTR(b);
133
136
  VALUE new_ary = rb_ary_new2(n);
134
-
137
+
135
138
  long i;
136
139
 
137
140
  if (n != RARRAY_LEN(b)) {
@@ -157,7 +160,7 @@ class Array
157
160
  VALUE *x_a = RARRAY_PTR(self);
158
161
  double konst = NUM2DBL(c);
159
162
  VALUE new_ary = rb_ary_new2(n);
160
-
163
+
161
164
  long i;
162
165
  for (i=0; i<n; i++) {
163
166
  rb_ary_push(new_ary, (NUM2DBL(x_a[i]) < konst) ? x_a[i] : c);
@@ -171,7 +174,7 @@ class Array
171
174
  VALUE *x_a = RARRAY_PTR(self);
172
175
  double konst = NUM2DBL(c);
173
176
  VALUE new_ary = rb_ary_new2(n);
174
-
177
+
175
178
  long i;
176
179
  for (i=0; i<n; i++) {
177
180
  rb_ary_push(new_ary, (NUM2DBL(x_a[i]) > konst) ? x_a[i] : c);
@@ -203,7 +206,7 @@ class Array
203
206
  long n = RARRAY_LEN(self);
204
207
  VALUE *x_a = RARRAY_PTR(self);
205
208
  VALUE new_ary = rb_ary_new2(n);
206
-
209
+
207
210
  long i;
208
211
  for (i=0; i<n; i++) {
209
212
  rb_ary_push(new_ary, DBL2NUM(log(NUM2DBL(x_a[i]))));
@@ -216,7 +219,7 @@ class Array
216
219
  long n = RARRAY_LEN(self);
217
220
  VALUE *x_a = RARRAY_PTR(self);
218
221
  VALUE new_ary = rb_ary_new2(n);
219
-
222
+
220
223
  long i;
221
224
  for (i=0; i<n; i++) {
222
225
  rb_ary_push(new_ary, DBL2NUM(pow(2.717, NUM2DBL(x_a[i]))));
@@ -229,7 +232,7 @@ class Array
229
232
  long n = RARRAY_LEN(self);
230
233
  VALUE *x_a = RARRAY_PTR(self);
231
234
  VALUE new_ary = rb_ary_new2(n);
232
-
235
+
233
236
  long i;
234
237
  for (i=0; i<n; i++) {
235
238
  rb_ary_push(new_ary, DBL2NUM(sin(NUM2DBL(x_a[i]))));
@@ -242,7 +245,7 @@ class Array
242
245
  long n = RARRAY_LEN(self);
243
246
  VALUE *x_a = RARRAY_PTR(self);
244
247
  VALUE new_ary = rb_ary_new2(n);
245
-
248
+
246
249
  long i;
247
250
  for (i=0; i<n; i++) {
248
251
  rb_ary_push(new_ary, DBL2NUM(cos(NUM2DBL(x_a[i]))));
@@ -255,7 +258,7 @@ class Array
255
258
  long n = RARRAY_LEN(self);
256
259
  VALUE *x_a = RARRAY_PTR(self);
257
260
  VALUE new_ary = rb_ary_new2(n);
258
-
261
+
259
262
  long i;
260
263
  for (i=0; i<n; i++) {
261
264
  rb_ary_push(new_ary, DBL2NUM(tan(NUM2DBL(x_a[i]))));
@@ -279,9 +282,9 @@ class Array
279
282
  static VALUE c_sum() {
280
283
  long n = RARRAY_LEN(self);
281
284
  double sum = 0.0;
282
-
285
+
283
286
  VALUE *x_a = RARRAY_PTR(self);
284
-
287
+
285
288
  long i;
286
289
  for (i=0; i<n; i++) {
287
290
  if (TYPE(x_a[i]) != T_FIXNUM && TYPE(x_a[i]) != T_BIGNUM && TYPE(x_a[i]) != T_FLOAT) {
@@ -298,9 +301,9 @@ class Array
298
301
  static VALUE c_sumabs() {
299
302
  long n = RARRAY_LEN(self);
300
303
  double sum = 0.0;
301
-
304
+
302
305
  VALUE *x_a = RARRAY_PTR(self);
303
-
306
+
304
307
  long i;
305
308
  for (i=0; i<n; i++) {
306
309
  if (TYPE(x_a[i]) != T_FIXNUM && TYPE(x_a[i]) != T_BIGNUM && TYPE(x_a[i]) != T_FLOAT) {
@@ -317,9 +320,9 @@ class Array
317
320
  static VALUE c_sumsquares() {
318
321
  long n = RARRAY_LEN(self);
319
322
  double sum = 0.0;
320
-
323
+
321
324
  VALUE *x_a = RARRAY_PTR(self);
322
-
325
+
323
326
  long i;
324
327
  for (i=0; i<n; i++) {
325
328
  if (TYPE(x_a[i]) != T_FIXNUM && TYPE(x_a[i]) != T_BIGNUM && TYPE(x_a[i]) != T_FLOAT) {
@@ -400,7 +403,7 @@ class Array
400
403
  if (TYPE(x_v) != T_FIXNUM && TYPE(x_v) != T_BIGNUM && TYPE(x_v) != T_FLOAT) {
401
404
  rb_raise(rb_eTypeError, "first argument was not an integer or float");
402
405
  }
403
-
406
+
404
407
  x_a = RARRAY_PTR(self);
405
408
  n = RARRAY_LEN(self);
406
409
  x = NUM2DBL(x_v);
@@ -453,7 +456,7 @@ V_s = (0..1_024*1_024).to_a.map{Random.rand(1_024)}
453
456
  # Dot Product
454
457
  puts_with_pounds "Dot Product"
455
458
  n = 1
456
- if VERBOSE
459
+ if $opts[:verbose]
457
460
  puts "dot_product_f: #{V_f.dot_product_f(V_f)}"
458
461
  puts "c_dot_product_f: #{V_f.c_dot_product_f(V_f)}"
459
462
  puts "Ryeppp.dotproduct_v64fv64f_s64f: #{Ryeppp.dotproduct_v64fv64f_s64f(V_f, V_f)}"
@@ -481,12 +484,12 @@ end
481
484
  puts_with_pounds "Pairwise Min and Max"
482
485
  Benchmark.bm(WIDTH) do |x|
483
486
  %w{min max}.each do |prefix|
484
- x.report("#{prefix}_v64fv64f_v64f:") { n.times { V_f.send("#{prefix}_v64fv64f_v64f", V_f) } }
485
- x.report("c_#{prefix}_v64fv64f_v64f:") { n.times { V_f.send("c_#{prefix}_v64fv64f_v64f", V_f) } }
486
- x.report("Ryeppp.#{prefix}_v64fv64f_v64f:") { n.times { Ryeppp.send("#{prefix}_v64fv64f_v64f", V_f, V_f) } }
487
- x.report("#{prefix}_v64fs64f_v64f:") { n.times { V_f.send("#{prefix}_v64fs64f_v64f", K) } }
488
- x.report("c_#{prefix}_v64fs64f_v64f:") { n.times { V_f.send("c_#{prefix}_v64fs64f_v64f", K) } }
489
- x.report("Ryeppp.#{prefix}_v64fs64f_v64f:") { n.times { Ryeppp.send("#{prefix}_v64fs64f_v64f", V_f, K) } }
487
+ x.report("#{prefix}_v64fv64f_v64f:") { n.times { V_f.send("#{prefix}_v64fv64f_v64f", V_f) } }
488
+ x.report("c_#{prefix}_v64fv64f_v64f:") { n.times { V_f.send("c_#{prefix}_v64fv64f_v64f", V_f) } }
489
+ x.report("Ryeppp.#{prefix}_v64fv64f_v64f:") { n.times { Ryeppp.send("#{prefix}_v64fv64f_v64f", V_f, V_f) } }
490
+ x.report("#{prefix}_v64fs64f_v64f:") { n.times { V_f.send("#{prefix}_v64fs64f_v64f", K) } }
491
+ x.report("c_#{prefix}_v64fs64f_v64f:") { n.times { V_f.send("c_#{prefix}_v64fs64f_v64f", K) } }
492
+ x.report("Ryeppp.#{prefix}_v64fs64f_v64f:") { n.times { Ryeppp.send("#{prefix}_v64fs64f_v64f", V_f, K) } }
490
493
  end
491
494
  end
492
495
 
@@ -518,7 +521,7 @@ n = 1
518
521
  P_SMALL = (0..1_024).to_a.map{Random.rand}
519
522
  P_LARGE = (0..1_024*1_024).to_a.map{Random.rand}
520
523
  X = Random.rand
521
- if VERBOSE
524
+ if $opts[:verbose]
522
525
  puts "evaluate_polynomial: #{P_SMALL.evaluate_polynomial(X)}"
523
526
  puts "evaluate_polynomial_iter: #{P_SMALL.evaluate_polynomial_iter(X)}"
524
527
  puts "c_evaluate_polynomial: #{P_SMALL.c_evaluate_polynomial(X)}"
@@ -1,3 +1,3 @@
1
1
  class Ryeppp
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7.0"
3
3
  end
@@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rspec", ">= 2.13.0"
27
27
  spec.add_development_dependency "rspec", ">= 2.13.0"
28
28
  spec.add_development_dependency "RubyInline", "~> 3.12.2"
29
+ spec.add_development_dependency "trollop", "~> 2.0"
30
+ spec.add_development_dependency "version_bumper", "~> 0.3.0"
29
31
  end
@@ -1,36 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
+ SMALLEST_TOO_BIG_INTEGER = 2**63
4
+ BIGGEST_TOO_SMALL_INTEGER = -2**63 - 1
5
+
3
6
  describe Ryeppp do
4
7
  # Addition
5
8
  it 'should add vectors of Fixnums' do
6
9
  Ryeppp.add_v64sv64s_v64s([1], [2]).should eq([3])
7
10
  expect{Ryeppp.add_v64sv64s_v64s([1, 'a'], [2, 'b'])}.to raise_error(TypeError)
8
- expect{Ryeppp.add_v64sv64s_v64s([2**63], [1])}.to raise_error(RangeError)
9
- expect{Ryeppp.add_v64sv64s_v64s([-2**63], [1])}.to raise_error(RangeError)
11
+ expect{Ryeppp.add_v64sv64s_v64s([SMALLEST_TOO_BIG_INTEGER], [1])}.to raise_error(RangeError)
12
+ expect{Ryeppp.add_v64sv64s_v64s([BIGGEST_TOO_SMALL_INTEGER], [1])}.to raise_error(RangeError)
13
+ expect{Ryeppp.add_v64sv64s_v64s([1], [2, 3])}.to raise_error(ArgumentError)
10
14
  end
11
15
  it 'should add vectors of Floats' do
12
16
  Ryeppp.add_v64fv64f_v64f([1.1], [1.1]).should eq([2.2])
13
17
  expect{Ryeppp.add_v64fv64f_v64f([1.1, 'a'], [2.2, 'b'])}.to raise_error(TypeError)
18
+ expect{Ryeppp.add_v64fv64f_v64f([1.1], [2.2, 3.3])}.to raise_error(ArgumentError)
14
19
  end
15
20
 
16
21
  # Subtraction
17
22
  it 'should subtract vectors of Fixnums' do
18
23
  Ryeppp.subtract_v64sv64s_v64s([1], [2]).should eq([-1])
19
24
  expect{Ryeppp.subtract_v64sv64s_v64s([1, 'a'], [2, 'b'])}.to raise_error(TypeError)
20
- expect{Ryeppp.subtract_v64sv64s_v64s([2**63], [2])}.to raise_error(RangeError)
21
- expect{Ryeppp.subtract_v64sv64s_v64s([-2**63], [2])}.to raise_error(RangeError)
25
+ expect{Ryeppp.subtract_v64sv64s_v64s([SMALLEST_TOO_BIG_INTEGER], [2])}.to raise_error(RangeError)
26
+ expect{Ryeppp.subtract_v64sv64s_v64s([BIGGEST_TOO_SMALL_INTEGER], [2])}.to raise_error(RangeError)
27
+ expect{Ryeppp.subtract_v64sv64s_v64s([1], [2, 3])}.to raise_error(ArgumentError)
22
28
  end
23
29
  it 'should subtract vectors of Floats' do
24
30
  Ryeppp.subtract_v64fv64f_v64f([1.1], [1.1]).should eq([0])
25
31
  expect{Ryeppp.subtract_v64fv64f_v64f([1.1, 'a'], [2.2, 'b'])}.to raise_error(TypeError)
32
+ expect{Ryeppp.subtract_v64fv64f_v64f([1.1], [2.2, 3.3])}.to raise_error(ArgumentError)
26
33
  end
27
34
 
28
35
  # Multiplication
29
36
  it 'should multiply a vector of Fixnums by a constant' do
30
37
  Ryeppp.multiply_v64ss64s_v64s([1, 2, 3], 2).should eq([2, 4, 6])
31
38
  expect{Ryeppp.multiply_v64ss64s_v64s([1, 'a'], 2)}.to raise_error(TypeError)
32
- expect{Ryeppp.multiply_v64ss64s_v64s([2**63], 2)}.to raise_error(RangeError)
33
- expect{Ryeppp.multiply_v64ss64s_v64s([-2**63], 2)}.to raise_error(RangeError)
39
+ expect{Ryeppp.multiply_v64ss64s_v64s([SMALLEST_TOO_BIG_INTEGER], 2)}.to raise_error(RangeError)
40
+ expect{Ryeppp.multiply_v64ss64s_v64s([BIGGEST_TOO_SMALL_INTEGER], 2)}.to raise_error(RangeError)
34
41
  expect{Ryeppp.multiply_v64ss64s_v64s(2, 2)}.to raise_error(ArgumentError)
35
42
  expect{Ryeppp.multiply_v64ss64s_v64s([1, 2], 'a')}.to raise_error(ArgumentError)
36
43
  end
@@ -42,14 +49,16 @@ describe Ryeppp do
42
49
  it 'should multiply vectors of Fixnums' do
43
50
  Ryeppp.multiply_v64sv64s_v64s([2], [3]).should eq([6])
44
51
  expect{Ryeppp.multiply_v64sv64s_v64s([1, 'a'], [2, 'b'])}.to raise_error(TypeError)
45
- expect{Ryeppp.multiply_v64sv64s_v64s([2**63], [2])}.to raise_error(RangeError)
46
- expect{Ryeppp.multiply_v64sv64s_v64s([-2**63], [2])}.to raise_error(RangeError)
52
+ expect{Ryeppp.multiply_v64sv64s_v64s([SMALLEST_TOO_BIG_INTEGER], [2])}.to raise_error(RangeError)
53
+ expect{Ryeppp.multiply_v64sv64s_v64s([BIGGEST_TOO_SMALL_INTEGER], [2])}.to raise_error(RangeError)
47
54
  expect{Ryeppp.multiply_v64sv64s_v64s(2, [2])}.to raise_error(ArgumentError)
48
55
  expect{Ryeppp.multiply_v64sv64s_v64s([2], 2)}.to raise_error(ArgumentError)
56
+ expect{Ryeppp.multiply_v64sv64s_v64s([1], [2, 3])}.to raise_error(ArgumentError)
49
57
  end
50
58
  it 'should multiply vectors of Floats' do
51
59
  Ryeppp.multiply_v64fv64f_v64f([2.5], [3.5]).should eq([8.75])
52
60
  expect{Ryeppp.multiply_v64fv64f_v64f([1.1, 'a'], [2.2, 'b'])}.to raise_error(TypeError)
61
+ expect{Ryeppp.multiply_v64fv64f_v64f([1.1], [2.2, 3.3])}.to raise_error(ArgumentError)
53
62
  end
54
63
 
55
64
  # Dot Product
@@ -58,14 +67,15 @@ describe Ryeppp do
58
67
  expect{Ryeppp.dotproduct_v64fv64f_s64f([1, 2, 'a'], [4, 5, 'b'])}.to raise_error(TypeError)
59
68
  expect{Ryeppp.dotproduct_v64fv64f_s64f(2, [2])}.to raise_error(ArgumentError)
60
69
  expect{Ryeppp.dotproduct_v64fv64f_s64f([2], 2)}.to raise_error(ArgumentError)
70
+ expect{Ryeppp.dotproduct_v64fv64f_s64f([1], [2, 3])}.to raise_error(ArgumentError)
61
71
  end
62
72
 
63
73
  # Minimum
64
74
  it 'should find the minimum in a vector of Fixnums' do
65
75
  Ryeppp.min_v64s_s64s([3, 2, 1]).should eq(1)
66
76
  expect{Ryeppp.min_v64s_s64s([1, 'a'])}.to raise_error(TypeError)
67
- expect{Ryeppp.min_v64s_s64s([2**63])}.to raise_error(RangeError)
68
- expect{Ryeppp.min_v64s_s64s([-2**63])}.to raise_error(RangeError)
77
+ expect{Ryeppp.min_v64s_s64s([SMALLEST_TOO_BIG_INTEGER])}.to raise_error(RangeError)
78
+ expect{Ryeppp.min_v64s_s64s([BIGGEST_TOO_SMALL_INTEGER])}.to raise_error(RangeError)
69
79
  expect{Ryeppp.min_v64s_s64s(2)}.to raise_error(ArgumentError)
70
80
  end
71
81
  it 'should find the minimum in a vector of Floats' do
@@ -78,8 +88,8 @@ describe Ryeppp do
78
88
  it 'should find the maximum in a vector of Fixnums' do
79
89
  Ryeppp.max_v64s_s64s([3, 2, 1]).should eq(3)
80
90
  expect{Ryeppp.max_v64s_s64s([1, 'a'])}.to raise_error(TypeError)
81
- expect{Ryeppp.max_v64s_s64s([2**63])}.to raise_error(RangeError)
82
- expect{Ryeppp.max_v64s_s64s([-2**63])}.to raise_error(RangeError)
91
+ expect{Ryeppp.max_v64s_s64s([SMALLEST_TOO_BIG_INTEGER])}.to raise_error(RangeError)
92
+ expect{Ryeppp.max_v64s_s64s([BIGGEST_TOO_SMALL_INTEGER])}.to raise_error(RangeError)
83
93
  expect{Ryeppp.max_v64s_s64s(2)}.to raise_error(ArgumentError)
84
94
  end
85
95
  it 'should find the maximum in a vector of Floats' do
@@ -94,6 +104,7 @@ describe Ryeppp do
94
104
  expect{Ryeppp.min_v64fv64f_v64f([1.0, 'a'], [2.0, 'b'])}.to raise_error(TypeError)
95
105
  expect{Ryeppp.min_v64fv64f_v64f(1.0, [2.0, 'b'])}.to raise_error(ArgumentError)
96
106
  expect{Ryeppp.min_v64fv64f_v64f([1.0], 1)}.to raise_error(ArgumentError)
107
+ expect{Ryeppp.min_v64fv64f_v64f([1.0], [2.0, 3.0])}.to raise_error(ArgumentError)
97
108
  end
98
109
  # Pairwise Maxima
99
110
  it 'should find the pairwise maxima in vectors of Floats' do
@@ -101,6 +112,7 @@ describe Ryeppp do
101
112
  expect{Ryeppp.max_v64fv64f_v64f([1.0, 'a'], [2.0, 'b'])}.to raise_error(TypeError)
102
113
  expect{Ryeppp.max_v64fv64f_v64f(1.0, [2.0, 'b'])}.to raise_error(ArgumentError)
103
114
  expect{Ryeppp.max_v64fv64f_v64f([1.0, 'a'], 2.0)}.to raise_error(ArgumentError)
115
+ expect{Ryeppp.max_v64fv64f_v64f([1.0], [2.0, 3.0])}.to raise_error(ArgumentError)
104
116
  end
105
117
 
106
118
  # Constant Minima
@@ -122,8 +134,8 @@ describe Ryeppp do
122
134
  it 'should negate vectors of Fixnums' do
123
135
  Ryeppp.negate_v64s_s64s([1]).should eq([-1])
124
136
  expect{Ryeppp.negate_v64s_s64s([1, 'a'])}.to raise_error(TypeError)
125
- expect{Ryeppp.negate_v64s_s64s([2**63])}.to raise_error(RangeError)
126
- expect{Ryeppp.negate_v64s_s64s([-2**63])}.to raise_error(RangeError)
137
+ expect{Ryeppp.negate_v64s_s64s([SMALLEST_TOO_BIG_INTEGER])}.to raise_error(RangeError)
138
+ expect{Ryeppp.negate_v64s_s64s([BIGGEST_TOO_SMALL_INTEGER])}.to raise_error(RangeError)
127
139
  expect{Ryeppp.negate_v64s_s64s(1)}.to raise_error(ArgumentError)
128
140
  end
129
141
  it 'should negate vectors of Floats' do
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.6
4
+ version: 0.0.7.0
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-10-06 00:00:00.000000000 Z
12
+ date: 2014-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -107,6 +107,38 @@ dependencies:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
109
  version: 3.12.2
110
+ - !ruby/object:Gem::Dependency
111
+ name: trollop
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ prerelease: false
119
+ type: :development
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '2.0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: version_bumper
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 0.3.0
134
+ prerelease: false
135
+ type: :development
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 0.3.0
110
142
  description: This gem provides bindings to the Yeppp! library. According to the documentation,
111
143
  "Yeppp! is a high-performance SIMD-optimized mathematical library for x86, ARM,
112
144
  and MIPS processors on Windows, Android, Mac OS X, and GNU/Linux systems."
@@ -123,6 +155,7 @@ files:
123
155
  - LICENSE.txt
124
156
  - README.md
125
157
  - Rakefile
158
+ - VERSION
126
159
  - ext/ryeppp/extconf.rb
127
160
  - ext/templates/ryeppp.c.rb
128
161
  - lib/ryeppp.rb