ryeppp 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/templates/ryeppp.c.rb +180 -68
- data/lib/ryeppp/version.rb +1 -1
- data/spec/ryeppp_spec.rb +31 -0
- metadata +1 -1
data/ext/templates/ryeppp.c.rb
CHANGED
@@ -7,12 +7,18 @@ class String
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def declare_yep64_typed_array(var_names, opts={})
|
11
11
|
var_names = Array(var_names)
|
12
12
|
type = opts[:type] || '{{type}}'
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
var_names.map{|vn| %{Yep64#{type} *yep_#{vn};}}.join("\n")
|
14
|
+
end
|
15
|
+
def allocate_yep64_typed_array(var_names, len_var_name, opts={})
|
16
|
+
var_names = Array(var_names)
|
17
|
+
type = opts[:type] || '{{type}}'
|
18
|
+
var_names.map{|vn| %{
|
19
|
+
yep_#{vn} = (Yep64#{type}*)calloc(#{len_var_name}, sizeof(Yep64#{type}));
|
20
|
+
assert(yep_#{vn} != NULL);
|
21
|
+
}}.join("\n")
|
16
22
|
end
|
17
23
|
|
18
24
|
def deinitialize_yeppp
|
@@ -27,11 +33,13 @@ def initialize_yeppp
|
|
27
33
|
assert(status == YepStatusOk);}
|
28
34
|
end
|
29
35
|
|
30
|
-
def guard_integer_input_size(var_name, iteration_var_name)
|
36
|
+
def guard_integer_input_size(var_name, iteration_var_name, allocated_arrays)
|
31
37
|
%{if (rb_funcall(#{var_name}_a[#{iteration_var_name}], '>', 1, #{MAX_SIGNED_INTEGER})) {
|
38
|
+
#{release_array_memory allocated_arrays}
|
32
39
|
rb_raise(rb_eRangeError, "input was too large for 64-bit signed integer");
|
33
40
|
}
|
34
41
|
if (rb_funcall(#{var_name}_a[#{iteration_var_name}], '<', 1, #{MIN_SIGNED_INTEGER})) {
|
42
|
+
#{release_array_memory allocated_arrays}
|
35
43
|
rb_raise(rb_eRangeError, "input was too small for 64-bit signed integer");
|
36
44
|
}}
|
37
45
|
end
|
@@ -64,19 +72,21 @@ def load_ruby_array_into_yeppp_array(var_name, iteration_var_name, len_var_name,
|
|
64
72
|
%{/* Load #{var_name}_a into yep_#{var_name}. */
|
65
73
|
for (#{iteration_var_name}=0; #{iteration_var_name}<#{len_var_name}; #{iteration_var_name}++) {
|
66
74
|
if (#{pt}) {
|
75
|
+
#{release_array_memory opts[:allocated_arrays]}
|
67
76
|
rb_raise(rb_eTypeError, "input was not all #{permitted_types.map(&:to_s).map(&:pluralize).join(' and ')}");
|
68
77
|
}
|
69
|
-
#{guard_integer_input_size(var_name, iteration_var_name)}
|
78
|
+
#{guard_integer_input_size(var_name, iteration_var_name, opts[:allocated_arrays])}
|
70
79
|
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}]);
|
71
80
|
}}
|
72
81
|
end
|
73
|
-
def load_ruby_array_into_yeppp_array_parameterized(var_name, iteration_var_name, len_var_name)
|
82
|
+
def load_ruby_array_into_yeppp_array_parameterized(var_name, iteration_var_name, len_var_name, opts={})
|
74
83
|
%{/* Load #{var_name}_a into yep_#{var_name}. */
|
75
84
|
for (#{iteration_var_name}=0; #{iteration_var_name}<#{len_var_name}; #{iteration_var_name}++) {
|
76
85
|
if (TYPE(#{var_name}_a[#{iteration_var_name}]) != {{ruby_klass}} && TYPE(#{var_name}_a[#{iteration_var_name}]) != {{alt_ruby_klass}}) {
|
86
|
+
#{release_array_memory opts[:allocated_arrays]}
|
77
87
|
rb_raise(rb_eTypeError, "input was not all {{ruby_klass_human}}");
|
78
88
|
}
|
79
|
-
#{guard_integer_input_size(var_name, iteration_var_name)}
|
89
|
+
#{guard_integer_input_size(var_name, iteration_var_name, opts[:allocated_arrays])}
|
80
90
|
yep_#{var_name}[#{iteration_var_name}] = (Yep64{{type}})NUM2{{ruby_type}}(#{var_name}_a[#{iteration_var_name}]);
|
81
91
|
}}
|
82
92
|
end
|
@@ -130,16 +140,28 @@ FUNCS = Proc.new do |verb_name|
|
|
130
140
|
enum YepStatus status;
|
131
141
|
long i;
|
132
142
|
VALUE new_ary;
|
133
|
-
VALUE *x_a
|
134
|
-
long l
|
135
|
-
Yep64{{type}} mult_by
|
143
|
+
VALUE *x_a;
|
144
|
+
long l;
|
145
|
+
Yep64{{type}} mult_by;
|
146
|
+
#{declare_yep64_typed_array(%w{x y})}
|
136
147
|
|
148
|
+
if (TYPE(x) != T_ARRAY) {
|
149
|
+
rb_raise(rb_eArgError, "first argument was not an Array");
|
150
|
+
}
|
151
|
+
if (TYPE(multiply_by) != T_FIXNUM && TYPE(multiply_by) != T_BIGNUM && TYPE(multiply_by) != T_FLOAT) {
|
152
|
+
rb_raise(rb_eArgError, "second argument was not an integer or a float");
|
153
|
+
}
|
154
|
+
|
137
155
|
/* Allocate arrays of inputs and outputs */
|
138
|
-
#{
|
139
|
-
|
156
|
+
#{allocate_yep64_typed_array(%w{x y}, 'l')}
|
157
|
+
|
158
|
+
x_a = RARRAY_PTR(x);
|
159
|
+
l = RARRAY_LEN(x);
|
160
|
+
mult_by = (Yep64{{type}})NUM2DBL(multiply_by);
|
161
|
+
|
140
162
|
#{initialize_yeppp}
|
141
163
|
|
142
|
-
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l')}
|
164
|
+
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x y})}
|
143
165
|
|
144
166
|
/* Perform the operation */
|
145
167
|
status = yepCore_Multiply_V64{{type}}S64{{type}}_V64{{type}}(yep_x, mult_by, yep_y, (YepSize)l);
|
@@ -163,19 +185,31 @@ FUNCS = Proc.new do |verb_name|
|
|
163
185
|
enum YepStatus status;
|
164
186
|
VALUE new_ary;
|
165
187
|
long i;
|
166
|
-
VALUE *x_a
|
167
|
-
VALUE *y_a
|
168
|
-
long l
|
188
|
+
VALUE *x_a;
|
189
|
+
VALUE *y_a;
|
190
|
+
long l;
|
191
|
+
#{declare_yep64_typed_array(%w{x y z})}
|
169
192
|
|
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
|
+
}
|
199
|
+
|
200
|
+
x_a = RARRAY_PTR(x);
|
201
|
+
y_a = RARRAY_PTR(y);
|
202
|
+
l = RARRAY_LEN(x);
|
203
|
+
|
170
204
|
/* Allocate arrays of inputs and outputs */
|
171
|
-
#{
|
205
|
+
#{allocate_yep64_typed_array(%w{x y z}, 'l')}
|
172
206
|
|
173
207
|
#{initialize_yeppp}
|
174
208
|
|
175
|
-
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l')}
|
176
|
-
#{load_ruby_array_into_yeppp_array_parameterized('y', 'i', 'l')}
|
209
|
+
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x y z})}
|
210
|
+
#{load_ruby_array_into_yeppp_array_parameterized('y', 'i', 'l', :allocated_arrays => %w{x y z})}
|
177
211
|
|
178
|
-
/* Perform the
|
212
|
+
/* Perform the #{verb_name} */
|
179
213
|
status = yepCore_#{verb_name}_V64{{type}}V64{{type}}_V64{{type}}(yep_x, yep_y, yep_z, (YepSize)l);
|
180
214
|
assert(status == YepStatusOk);
|
181
215
|
|
@@ -197,17 +231,29 @@ DOT_PRODUCT = %{
|
|
197
231
|
enum YepStatus status;
|
198
232
|
long i;
|
199
233
|
Yep64f dp;
|
200
|
-
VALUE *x_a
|
201
|
-
VALUE *y_a
|
202
|
-
long l
|
234
|
+
VALUE *x_a;
|
235
|
+
VALUE *y_a;
|
236
|
+
long l;
|
237
|
+
#{declare_yep64_typed_array(%w{x y}, :type => 'f')}
|
203
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
|
+
}
|
245
|
+
|
246
|
+
x_a = RARRAY_PTR(x);
|
247
|
+
y_a = RARRAY_PTR(y);
|
248
|
+
l = RARRAY_LEN(x);
|
249
|
+
|
204
250
|
/* Allocate arrays of inputs and outputs */
|
205
|
-
#{
|
251
|
+
#{allocate_yep64_typed_array(%w{x y}, 'l', :type => 'f')}
|
206
252
|
|
207
253
|
#{initialize_yeppp}
|
208
254
|
|
209
|
-
#{load_ruby_array_into_yeppp_array('x', 'i', 'l', 'f', [:integer, :float])}
|
210
|
-
#{load_ruby_array_into_yeppp_array('y', 'i', 'l', 'f', [:integer, :float])}
|
255
|
+
#{load_ruby_array_into_yeppp_array('x', 'i', 'l', 'f', [:integer, :float], :allocated_arrays => %w{x y})}
|
256
|
+
#{load_ruby_array_into_yeppp_array('y', 'i', 'l', 'f', [:integer, :float], :allocated_arrays => %w{x y})}
|
211
257
|
|
212
258
|
/* Perform the operation */
|
213
259
|
status = yepCore_DotProduct_V64fV64f_S64f(yep_x, yep_y, &dp, (YepSize)l);
|
@@ -228,15 +274,23 @@ MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
|
|
228
274
|
enum YepStatus status;
|
229
275
|
long i;
|
230
276
|
Yep64{{type}} #{kind.downcase};
|
231
|
-
VALUE *x_a
|
232
|
-
long l
|
233
|
-
|
277
|
+
VALUE *x_a;
|
278
|
+
long l;
|
279
|
+
#{declare_yep64_typed_array(%w{x})}
|
280
|
+
|
281
|
+
if (TYPE(x) != T_ARRAY) {
|
282
|
+
rb_raise(rb_eArgError, "first argument was not an Array");
|
283
|
+
}
|
284
|
+
|
285
|
+
x_a = RARRAY_PTR(x);
|
286
|
+
l = RARRAY_LEN(x);
|
287
|
+
|
234
288
|
/* Allocate arrays of inputs and outputs */
|
235
|
-
#{
|
289
|
+
#{allocate_yep64_typed_array('x', 'l')}
|
236
290
|
|
237
291
|
#{initialize_yeppp}
|
238
292
|
|
239
|
-
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l')}
|
293
|
+
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x})}
|
240
294
|
|
241
295
|
/* Perform the operation */
|
242
296
|
status = yepCore_#{kind}_V64{{type}}_S64{{type}}(yep_x, &#{kind.downcase}, (YepSize)l);
|
@@ -258,17 +312,29 @@ PAIRWISE_MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
|
|
258
312
|
enum YepStatus status;
|
259
313
|
long i;
|
260
314
|
VALUE new_ary;
|
261
|
-
VALUE *x_a
|
262
|
-
VALUE *y_a
|
263
|
-
long l
|
264
|
-
|
315
|
+
VALUE *x_a;
|
316
|
+
VALUE *y_a;
|
317
|
+
long l;
|
318
|
+
#{declare_yep64_typed_array(%w{x y z})}
|
319
|
+
|
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
|
+
}
|
326
|
+
|
327
|
+
x_a = RARRAY_PTR(x);
|
328
|
+
y_a = RARRAY_PTR(y);
|
329
|
+
l = RARRAY_LEN(x);
|
330
|
+
|
265
331
|
/* Allocate arrays of inputs and outputs */
|
266
|
-
#{
|
332
|
+
#{allocate_yep64_typed_array(%w{x y z}, 'l')}
|
267
333
|
|
268
334
|
#{initialize_yeppp}
|
269
335
|
|
270
|
-
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l')}
|
271
|
-
#{load_ruby_array_into_yeppp_array_parameterized('y', 'i', 'l')}
|
336
|
+
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x y z})}
|
337
|
+
#{load_ruby_array_into_yeppp_array_parameterized('y', 'i', 'l', :allocated_arrays => %w{x y z})}
|
272
338
|
|
273
339
|
/* Perform the operation */
|
274
340
|
status = yepCore_#{kind}_V64{{type}}V64{{type}}_V64{{type}}(yep_x, yep_y, yep_z, (YepSize)l);
|
@@ -292,16 +358,28 @@ CONSTANT_MIN_MAX = typed_variants(%w{Min Max}.map do |kind|
|
|
292
358
|
enum YepStatus status;
|
293
359
|
long i;
|
294
360
|
VALUE new_ary;
|
295
|
-
VALUE *x_a
|
296
|
-
long l
|
297
|
-
Yep64f konst
|
361
|
+
VALUE *x_a;
|
362
|
+
long l;
|
363
|
+
Yep64f konst;
|
364
|
+
#{declare_yep64_typed_array(%w{x y})}
|
298
365
|
|
366
|
+
if (TYPE(x) != T_ARRAY) {
|
367
|
+
rb_raise(rb_eArgError, "first argument was not an Array");
|
368
|
+
}
|
369
|
+
if (TYPE(c) != T_FIXNUM && TYPE(c) != T_BIGNUM && TYPE(c) != T_FLOAT) {
|
370
|
+
rb_raise(rb_eArgError, "second argument was not a number");
|
371
|
+
}
|
372
|
+
|
373
|
+
x_a = RARRAY_PTR(x);
|
374
|
+
l = RARRAY_LEN(x);
|
375
|
+
konst = (Yep64f)NUM2{{ruby_type}}(c);
|
376
|
+
|
299
377
|
/* Allocate arrays of inputs and outputs */
|
300
|
-
#{
|
378
|
+
#{allocate_yep64_typed_array(%w{x y}, 'l')}
|
301
379
|
|
302
380
|
#{initialize_yeppp}
|
303
381
|
|
304
|
-
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l')}
|
382
|
+
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x y})}
|
305
383
|
|
306
384
|
/* Perform the operation */
|
307
385
|
status = yepCore_#{kind}_V64{{type}}S64{{type}}_V64{{type}}(yep_x, konst, yep_y, (YepSize)l);
|
@@ -324,15 +402,23 @@ NEGATE = typed_variants(%{
|
|
324
402
|
enum YepStatus status;
|
325
403
|
long i;
|
326
404
|
VALUE new_ary;
|
327
|
-
VALUE *x_a
|
328
|
-
long l
|
329
|
-
|
405
|
+
VALUE *x_a;
|
406
|
+
long l;
|
407
|
+
#{declare_yep64_typed_array(%w{x y})}
|
408
|
+
|
409
|
+
if (TYPE(x) != T_ARRAY) {
|
410
|
+
rb_raise(rb_eArgError, "first argument was not an Array");
|
411
|
+
}
|
412
|
+
|
413
|
+
x_a = RARRAY_PTR(x);
|
414
|
+
l = RARRAY_LEN(x);
|
415
|
+
|
330
416
|
/* Allocate arrays of inputs and outputs */
|
331
|
-
#{
|
417
|
+
#{allocate_yep64_typed_array(%w{x y}, 'l')}
|
332
418
|
|
333
419
|
#{initialize_yeppp}
|
334
420
|
|
335
|
-
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l')}
|
421
|
+
#{load_ruby_array_into_yeppp_array_parameterized('x', 'i', 'l', :allocated_arrays => %w{x y})}
|
336
422
|
|
337
423
|
/* Perform the negation */
|
338
424
|
status = yepCore_Negate_V64{{type}}_V64{{type}}(yep_x, yep_y, (YepSize)l);
|
@@ -354,15 +440,23 @@ SUMS = %w{Sum SumAbs SumSquares}.map do |kind|
|
|
354
440
|
enum YepStatus status;
|
355
441
|
long i;
|
356
442
|
Yep64f sum;
|
357
|
-
|
358
|
-
|
443
|
+
VALUE *x_a;
|
444
|
+
long l;
|
445
|
+
#{declare_yep64_typed_array(%w{x}, :type => 'f')}
|
446
|
+
|
447
|
+
if (TYPE(x) != T_ARRAY) {
|
448
|
+
rb_raise(rb_eArgError, "first argument was not an Array");
|
449
|
+
}
|
450
|
+
|
451
|
+
x_a = RARRAY_PTR(x);
|
452
|
+
l = RARRAY_LEN(x);
|
359
453
|
|
360
454
|
/* Allocate arrays of inputs and outputs */
|
361
|
-
#{
|
455
|
+
#{allocate_yep64_typed_array('x', 'l', :type => 'f')}
|
362
456
|
|
363
457
|
#{initialize_yeppp}
|
364
458
|
|
365
|
-
#{load_ruby_array_into_yeppp_array('x', 'i', 'l', 'f', [:integer, :float])}
|
459
|
+
#{load_ruby_array_into_yeppp_array('x', 'i', 'l', 'f', [:integer, :float], :allocated_arrays => %w{x})}
|
366
460
|
|
367
461
|
/* Perform the operation */
|
368
462
|
status = yepCore_#{kind}_V64f_S64f(yep_x, &sum, (YepSize)l);
|
@@ -384,15 +478,23 @@ MATHS = MATHS_KINDS.map do |kind|
|
|
384
478
|
enum YepStatus status;
|
385
479
|
long i;
|
386
480
|
VALUE new_ary;
|
387
|
-
|
388
|
-
|
481
|
+
VALUE *x_a;
|
482
|
+
long l;
|
483
|
+
#{declare_yep64_typed_array(%w{x y}, :type => 'f')}
|
484
|
+
|
485
|
+
if (TYPE(x) != T_ARRAY) {
|
486
|
+
rb_raise(rb_eArgError, "first argument was not an Array");
|
487
|
+
}
|
488
|
+
|
489
|
+
x_a = RARRAY_PTR(x);
|
490
|
+
l = RARRAY_LEN(x);
|
389
491
|
|
390
492
|
/* Allocate arrays of inputs and outputs */
|
391
|
-
#{
|
493
|
+
#{allocate_yep64_typed_array(%w{x y}, 'l', :type => 'f')}
|
392
494
|
|
393
495
|
#{initialize_yeppp}
|
394
496
|
|
395
|
-
#{load_ruby_array_into_yeppp_array('x', 'i', 'l', 'f', [:integer, :float])}
|
497
|
+
#{load_ruby_array_into_yeppp_array('x', 'i', 'l', 'f', [:integer, :float], :allocated_arrays => %w{x y})}
|
396
498
|
|
397
499
|
/* Perform the operation */
|
398
500
|
status = yepMath_#{kind}_V64f_V64f(yep_x, yep_y, (YepSize)l);
|
@@ -416,24 +518,34 @@ POLYNOMIAL = %{
|
|
416
518
|
enum YepStatus status;
|
417
519
|
long i;
|
418
520
|
VALUE new_ary;
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
521
|
+
VALUE *x_a;
|
522
|
+
VALUE *y_a;
|
523
|
+
long x_l;
|
524
|
+
long y_l;
|
525
|
+
#{declare_yep64_typed_array(%w{x y z}, :type => 'f')}
|
526
|
+
|
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
|
+
}
|
533
|
+
|
534
|
+
x_a = RARRAY_PTR(x);
|
535
|
+
y_a = RARRAY_PTR(where);
|
536
|
+
x_l = RARRAY_LEN(x);
|
537
|
+
y_l = RARRAY_LEN(where);
|
423
538
|
|
424
539
|
/* Allocate arrays of inputs and outputs */
|
425
|
-
#{
|
426
|
-
#{
|
427
|
-
assert(yep_x != NULL);
|
428
|
-
assert(yep_y != NULL);
|
429
|
-
assert(yep_z != NULL);
|
540
|
+
#{allocate_yep64_typed_array(%w{x}, 'x_l', :type => 'f')}
|
541
|
+
#{allocate_yep64_typed_array(%w{y z}, 'y_l', :type => 'f')}
|
430
542
|
|
431
543
|
#{initialize_yeppp}
|
432
544
|
|
433
545
|
// Yeppp! polynomial evaluation works in reverse standard form, so we have
|
434
546
|
// to load yep_x in reverse.
|
435
|
-
#{load_ruby_array_into_yeppp_array('x', 'i', 'x_l', 'f', [:integer, :float], :reverse => true)}
|
436
|
-
#{load_ruby_array_into_yeppp_array('y', 'i', 'y_l', 'f', [:integer, :float])}
|
547
|
+
#{load_ruby_array_into_yeppp_array('x', 'i', 'x_l', 'f', [:integer, :float], :reverse => true, :allocated_arrays => %w{x y z})}
|
548
|
+
#{load_ruby_array_into_yeppp_array('y', 'i', 'y_l', 'f', [:integer, :float], :allocated_arrays => %w{x y z})}
|
437
549
|
|
438
550
|
/* Perform the operation */
|
439
551
|
status = yepMath_EvaluatePolynomial_V64fV64f_V64f(yep_x, yep_y, yep_z, (YepSize)x_l, (YepSize)y_l);
|
data/lib/ryeppp/version.rb
CHANGED
data/spec/ryeppp_spec.rb
CHANGED
@@ -31,16 +31,21 @@ describe Ryeppp do
|
|
31
31
|
expect{Ryeppp.multiply_v64ss64s_v64s([1, 'a'], 2)}.to raise_error(TypeError)
|
32
32
|
expect{Ryeppp.multiply_v64ss64s_v64s([2**63], 2)}.to raise_error(RangeError)
|
33
33
|
expect{Ryeppp.multiply_v64ss64s_v64s([-2**63], 2)}.to raise_error(RangeError)
|
34
|
+
expect{Ryeppp.multiply_v64ss64s_v64s(2, 2)}.to raise_error(ArgumentError)
|
35
|
+
expect{Ryeppp.multiply_v64ss64s_v64s([1, 2], 'a')}.to raise_error(ArgumentError)
|
34
36
|
end
|
35
37
|
it 'should multiply a vector of Floats by a constant' do
|
36
38
|
Ryeppp.multiply_v64fs64f_v64f([1.0, 2.0, 3.0], 2.0).should eq([2.0, 4.0, 6.0])
|
37
39
|
expect{Ryeppp.multiply_v64fs64f_v64f([1, 'a'], 2)}.to raise_error(TypeError)
|
40
|
+
expect{Ryeppp.multiply_v64fs64f_v64f([1, 2], 'a')}.to raise_error(ArgumentError)
|
38
41
|
end
|
39
42
|
it 'should multiply vectors of Fixnums' do
|
40
43
|
Ryeppp.multiply_v64sv64s_v64s([2], [3]).should eq([6])
|
41
44
|
expect{Ryeppp.multiply_v64sv64s_v64s([1, 'a'], [2, 'b'])}.to raise_error(TypeError)
|
42
45
|
expect{Ryeppp.multiply_v64sv64s_v64s([2**63], [2])}.to raise_error(RangeError)
|
43
46
|
expect{Ryeppp.multiply_v64sv64s_v64s([-2**63], [2])}.to raise_error(RangeError)
|
47
|
+
expect{Ryeppp.multiply_v64sv64s_v64s(2, [2])}.to raise_error(ArgumentError)
|
48
|
+
expect{Ryeppp.multiply_v64sv64s_v64s([2], 2)}.to raise_error(ArgumentError)
|
44
49
|
end
|
45
50
|
it 'should multiply vectors of Floats' do
|
46
51
|
Ryeppp.multiply_v64fv64f_v64f([2.5], [3.5]).should eq([8.75])
|
@@ -51,6 +56,8 @@ describe Ryeppp do
|
|
51
56
|
it 'should do the dot product of vectors of Floats' do
|
52
57
|
Ryeppp.dotproduct_v64fv64f_s64f([1, 2, 3], [4, 5, 6]).should eq(32.0)
|
53
58
|
expect{Ryeppp.dotproduct_v64fv64f_s64f([1, 2, 'a'], [4, 5, 'b'])}.to raise_error(TypeError)
|
59
|
+
expect{Ryeppp.dotproduct_v64fv64f_s64f(2, [2])}.to raise_error(ArgumentError)
|
60
|
+
expect{Ryeppp.dotproduct_v64fv64f_s64f([2], 2)}.to raise_error(ArgumentError)
|
54
61
|
end
|
55
62
|
|
56
63
|
# Minimum
|
@@ -59,10 +66,12 @@ describe Ryeppp do
|
|
59
66
|
expect{Ryeppp.min_v64s_s64s([1, 'a'])}.to raise_error(TypeError)
|
60
67
|
expect{Ryeppp.min_v64s_s64s([2**63])}.to raise_error(RangeError)
|
61
68
|
expect{Ryeppp.min_v64s_s64s([-2**63])}.to raise_error(RangeError)
|
69
|
+
expect{Ryeppp.min_v64s_s64s(2)}.to raise_error(ArgumentError)
|
62
70
|
end
|
63
71
|
it 'should find the minimum in a vector of Floats' do
|
64
72
|
Ryeppp.min_v64f_s64f([1.0, 2.0, 3.0]).should eq(1.0)
|
65
73
|
expect{Ryeppp.min_v64f_s64f([1.0, 'a'])}.to raise_error(TypeError)
|
74
|
+
expect{Ryeppp.min_v64f_s64f(1.0)}.to raise_error(ArgumentError)
|
66
75
|
end
|
67
76
|
|
68
77
|
# Maximum
|
@@ -71,32 +80,42 @@ describe Ryeppp do
|
|
71
80
|
expect{Ryeppp.max_v64s_s64s([1, 'a'])}.to raise_error(TypeError)
|
72
81
|
expect{Ryeppp.max_v64s_s64s([2**63])}.to raise_error(RangeError)
|
73
82
|
expect{Ryeppp.max_v64s_s64s([-2**63])}.to raise_error(RangeError)
|
83
|
+
expect{Ryeppp.max_v64s_s64s(2)}.to raise_error(ArgumentError)
|
74
84
|
end
|
75
85
|
it 'should find the maximum in a vector of Floats' do
|
76
86
|
Ryeppp.max_v64f_s64f([1.0, 2.0, 3.0]).should eq(3.0)
|
77
87
|
expect{Ryeppp.max_v64f_s64f([1.0, 'a'])}.to raise_error(TypeError)
|
88
|
+
expect{Ryeppp.max_v64f_s64f(1.0)}.to raise_error(ArgumentError)
|
78
89
|
end
|
79
90
|
|
80
91
|
# Pairwise Minima
|
81
92
|
it 'should find the pairwise minima in vectors of Floats' do
|
82
93
|
Ryeppp.min_v64fv64f_v64f([1.0, 2.0, 3.0], [3.0, 2.0, 1.0]).should eq([1.0, 2.0, 1.0])
|
83
94
|
expect{Ryeppp.min_v64fv64f_v64f([1.0, 'a'], [2.0, 'b'])}.to raise_error(TypeError)
|
95
|
+
expect{Ryeppp.min_v64fv64f_v64f(1.0, [2.0, 'b'])}.to raise_error(ArgumentError)
|
96
|
+
expect{Ryeppp.min_v64fv64f_v64f([1.0], 1)}.to raise_error(ArgumentError)
|
84
97
|
end
|
85
98
|
# Pairwise Maxima
|
86
99
|
it 'should find the pairwise maxima in vectors of Floats' do
|
87
100
|
Ryeppp.max_v64fv64f_v64f([1.0, 2.0, 3.0], [3.0, 2.0, 1.0]).should eq([3.0, 2.0, 3.0])
|
88
101
|
expect{Ryeppp.max_v64fv64f_v64f([1.0, 'a'], [2.0, 'b'])}.to raise_error(TypeError)
|
102
|
+
expect{Ryeppp.max_v64fv64f_v64f(1.0, [2.0, 'b'])}.to raise_error(ArgumentError)
|
103
|
+
expect{Ryeppp.max_v64fv64f_v64f([1.0, 'a'], 2.0)}.to raise_error(ArgumentError)
|
89
104
|
end
|
90
105
|
|
91
106
|
# Constant Minima
|
92
107
|
it 'should find the minima in a vector of Floats and a constant' do
|
93
108
|
Ryeppp.min_v64fs64f_v64f([1.0, 2.0, 3.0], 2.0).should eq([1.0, 2.0, 2.0])
|
94
109
|
expect{Ryeppp.min_v64fs64f_v64f([1.0, 'a'], 2.0)}.to raise_error(TypeError)
|
110
|
+
expect{Ryeppp.min_v64fs64f_v64f(1.0, 2.0)}.to raise_error(ArgumentError)
|
111
|
+
expect{Ryeppp.min_v64fs64f_v64f([1.0], 'a')}.to raise_error(ArgumentError)
|
95
112
|
end
|
96
113
|
# Constant Maxima
|
97
114
|
it 'should find the maxima in a vector of Floats and a constant' do
|
98
115
|
Ryeppp.max_v64fs64f_v64f([1.0, 2.0, 3.0], 2.5).should eq([2.5, 2.5, 3.0])
|
99
116
|
expect{Ryeppp.max_v64fs64f_v64f([1.0, 'a'], 2.5)}.to raise_error(TypeError)
|
117
|
+
expect{Ryeppp.max_v64fs64f_v64f(1.0, 2.5)}.to raise_error(ArgumentError)
|
118
|
+
expect{Ryeppp.max_v64fs64f_v64f([1.0, 'a'], 'a')}.to raise_error(ArgumentError)
|
100
119
|
end
|
101
120
|
|
102
121
|
# Negation
|
@@ -105,52 +124,62 @@ describe Ryeppp do
|
|
105
124
|
expect{Ryeppp.negate_v64s_s64s([1, 'a'])}.to raise_error(TypeError)
|
106
125
|
expect{Ryeppp.negate_v64s_s64s([2**63])}.to raise_error(RangeError)
|
107
126
|
expect{Ryeppp.negate_v64s_s64s([-2**63])}.to raise_error(RangeError)
|
127
|
+
expect{Ryeppp.negate_v64s_s64s(1)}.to raise_error(ArgumentError)
|
108
128
|
end
|
109
129
|
it 'should negate vectors of Floats' do
|
110
130
|
Ryeppp.negate_v64f_s64f([1.1]).should eq([-1.1])
|
111
131
|
expect{Ryeppp.negate_v64f_s64f([1.1, 'a'])}.to raise_error(TypeError)
|
132
|
+
expect{Ryeppp.negate_v64f_s64f(1.1)}.to raise_error(ArgumentError)
|
112
133
|
end
|
113
134
|
|
114
135
|
# Sum
|
115
136
|
it 'should sum a vector of Floats' do
|
116
137
|
Ryeppp.sum_v64f_s64f([1, 2, 3]).should eq(6.0)
|
117
138
|
expect{Ryeppp.sum_v64f_s64f([1, 'a'])}.to raise_error(TypeError)
|
139
|
+
expect{Ryeppp.sum_v64f_s64f(1)}.to raise_error(ArgumentError)
|
118
140
|
end
|
119
141
|
# Sum Absolute Values
|
120
142
|
it 'should sum absolute values of a vector of Floats' do
|
121
143
|
Ryeppp.sumabs_v64f_s64f([1.0, -1.0, 2.0]).should eq(4.0)
|
122
144
|
expect{Ryeppp.sumabs_v64f_s64f([1.0, -1.0, 'a'])}.to raise_error(TypeError)
|
145
|
+
expect{Ryeppp.sumabs_v64f_s64f(1.0)}.to raise_error(ArgumentError)
|
123
146
|
end
|
124
147
|
# Sum Square Values
|
125
148
|
it 'should sum square values of a vector of Floats' do
|
126
149
|
Ryeppp.sumsquares_v64f_s64f([1.0, -1.0, 2.0]).should eq(6.0)
|
127
150
|
expect{Ryeppp.sumsquares_v64f_s64f([1.0, -1.0, 'a'])}.to raise_error(TypeError)
|
151
|
+
expect{Ryeppp.sumsquares_v64f_s64f(1.0)}.to raise_error(ArgumentError)
|
128
152
|
end
|
129
153
|
|
130
154
|
# Log
|
131
155
|
it 'should find the natural logarithm of elements of a vector of Floats' do
|
132
156
|
Ryeppp.log_v64f_v64f([1.0, 2.0, 3.0]).map{|o| o.round(5)}.should eq([0.0, 0.69315, 1.09861])
|
133
157
|
expect{Ryeppp.log_v64f_v64f([1.0, 'a'])}.to raise_error(TypeError)
|
158
|
+
expect{Ryeppp.log_v64f_v64f(1.0)}.to raise_error(ArgumentError)
|
134
159
|
end
|
135
160
|
# Exp
|
136
161
|
it 'should find the base e exponent of elements of a vector of Floats' do
|
137
162
|
Ryeppp.exp_v64f_v64f([1.0, 2.0, 3.0]).map{|o| o.round(5)}.should eq([2.71828, 7.38906, 20.08554])
|
138
163
|
expect{Ryeppp.exp_v64f_v64f([1.0, 'a'])}.to raise_error(TypeError)
|
164
|
+
expect{Ryeppp.exp_v64f_v64f(1.0)}.to raise_error(ArgumentError)
|
139
165
|
end
|
140
166
|
# Sin
|
141
167
|
it 'should find the sine of elements of a vector of Floats' do
|
142
168
|
Ryeppp.sin_v64f_v64f([1.0, 2.0, 3.0]).map{|o| o.round(5)}.should eq([0.84147, 0.9093, 0.14112])
|
143
169
|
expect{Ryeppp.sin_v64f_v64f([1.0, 'a'])}.to raise_error(TypeError)
|
170
|
+
expect{Ryeppp.sin_v64f_v64f(1.0)}.to raise_error(ArgumentError)
|
144
171
|
end
|
145
172
|
# Cos
|
146
173
|
it 'should find the cosine of elements of a vector of Floats' do
|
147
174
|
Ryeppp.cos_v64f_v64f([1.0, 2.0, 3.0]).map{|o| o.round(5)}.should eq([0.5403, -0.41615, -0.98999])
|
148
175
|
expect{Ryeppp.cos_v64f_v64f([1.0, 'a'])}.to raise_error(TypeError)
|
176
|
+
expect{Ryeppp.cos_v64f_v64f(1.0)}.to raise_error(ArgumentError)
|
149
177
|
end
|
150
178
|
# Tan
|
151
179
|
it 'should find the tangent of elements of a vector of Floats' do
|
152
180
|
Ryeppp.tan_v64f_v64f([1.0, 2.0, 3.0]).map{|o| o.round(5)}.should eq([1.55741, -2.18504, -0.14255])
|
153
181
|
expect{Ryeppp.tan_v64f_v64f([1.0, 'a'])}.to raise_error(TypeError)
|
182
|
+
expect{Ryeppp.tan_v64f_v64f(1.0)}.to raise_error(ArgumentError)
|
154
183
|
end
|
155
184
|
|
156
185
|
# Polynomial
|
@@ -162,5 +191,7 @@ describe Ryeppp do
|
|
162
191
|
# evaluated at x=0, x=1, and x=2.
|
163
192
|
Ryeppp.evaluatepolynomial_v64fv64f_v64f([-5, -4, 2, 1], [0, 1, 2]).should eq([1.0, -6.0, -51.0])
|
164
193
|
expect{Ryeppp.evaluatepolynomial_v64fv64f_v64f([1, 'a'], [0, 1])}.to raise_error(TypeError)
|
194
|
+
expect{Ryeppp.evaluatepolynomial_v64fv64f_v64f(1, [0, 1])}.to raise_error(ArgumentError)
|
195
|
+
expect{Ryeppp.evaluatepolynomial_v64fv64f_v64f([1], 0)}.to raise_error(ArgumentError)
|
165
196
|
end
|
166
197
|
end
|