carray 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +56 -0
- data/GPL +340 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +33 -0
- data/LEGAL +50 -0
- data/NOTE +73 -0
- data/Rakefile +20 -0
- data/TODO +5 -0
- data/ca_iter_block.c +242 -0
- data/ca_iter_dimension.c +287 -0
- data/ca_iter_window.c +202 -0
- data/ca_obj_array.c +1189 -0
- data/ca_obj_bitarray.c +523 -0
- data/ca_obj_bitfield.c +636 -0
- data/ca_obj_block.c +885 -0
- data/ca_obj_fake.c +405 -0
- data/ca_obj_farray.c +482 -0
- data/ca_obj_field.c +625 -0
- data/ca_obj_grid.c +738 -0
- data/ca_obj_mapping.c +614 -0
- data/ca_obj_object.c +777 -0
- data/ca_obj_reduce.c +299 -0
- data/ca_obj_refer.c +627 -0
- data/ca_obj_repeat.c +640 -0
- data/ca_obj_select.c +558 -0
- data/ca_obj_shift.c +952 -0
- data/ca_obj_transpose.c +582 -0
- data/ca_obj_unbound_repeat.c +557 -0
- data/ca_obj_window.c +1023 -0
- data/carray.h +1381 -0
- data/carray_access.c +1798 -0
- data/carray_attribute.c +903 -0
- data/carray_call_cfunc.c +1107 -0
- data/carray_cast.c +1155 -0
- data/carray_cast_func.rb +498 -0
- data/carray_class.c +132 -0
- data/carray_conversion.c +518 -0
- data/carray_copy.c +453 -0
- data/carray_core.c +1307 -0
- data/carray_element.c +572 -0
- data/carray_generate.c +681 -0
- data/carray_iterator.c +630 -0
- data/carray_loop.c +462 -0
- data/carray_mask.c +1174 -0
- data/carray_math.rb +834 -0
- data/carray_numeric.c +257 -0
- data/carray_operator.c +582 -0
- data/carray_order.c +1040 -0
- data/carray_random.c +529 -0
- data/carray_sort_addr.c +261 -0
- data/carray_stat.c +2102 -0
- data/carray_stat_proc.rb +1990 -0
- data/carray_test.c +602 -0
- data/carray_undef.c +69 -0
- data/carray_utils.c +740 -0
- data/ext/calculus/carray_calculus.c +792 -0
- data/ext/calculus/carray_interp.c +355 -0
- data/ext/calculus/extconf.rb +12 -0
- data/ext/calculus/lib/autoload/autoload_math_calculus.rb +2 -0
- data/ext/calculus/lib/math/calculus.rb +119 -0
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +31 -0
- data/ext/dataframe/API.txt +11 -0
- data/ext/dataframe/extconf.rb +3 -0
- data/ext/dataframe/lib/carray/autoload/autoload_dataframe_dataframe.rb +14 -0
- data/ext/dataframe/lib/carray/dataframe/dataframe.rb +1104 -0
- data/ext/dataframe/sample/test_uniq_sort.rb +5 -0
- data/ext/fortio/extconf.rb +3 -0
- data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +5 -0
- data/ext/fortio/lib/carray/io/fortran_format.rb +43 -0
- data/ext/fortio/lib/fortio.rb +3 -0
- data/ext/fortio/lib/fortio/fortran_format.rb +603 -0
- data/ext/fortio/lib/fortio/fortran_format.tab.rb +536 -0
- data/ext/fortio/lib/fortio/fortran_format.y +215 -0
- data/ext/fortio/lib/fortio/fortran_namelist.rb +151 -0
- data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +470 -0
- data/ext/fortio/lib/fortio/fortran_namelist.y +213 -0
- data/ext/fortio/lib/fortio/fortran_sequential.rb +345 -0
- data/ext/fortio/ruby_fortio.c +182 -0
- data/ext/fortio/test/test_H.rb +5 -0
- data/ext/fortio/test/test_T.rb +7 -0
- data/ext/fortio/test/test_fortran_format.rb +86 -0
- data/ext/fortio/test/test_namelist.rb +25 -0
- data/ext/fortio/test/test_sequential.rb +13 -0
- data/ext/fortio/test/test_sequential2.rb +13 -0
- data/ext/fortio/work/test.rb +10 -0
- data/ext/fortio/work/test_e.rb +19 -0
- data/ext/fortio/work/test_ep.rb +10 -0
- data/ext/fortio/work/test_parse.rb +12 -0
- data/ext/imagemap/carray_imagemap.c +495 -0
- data/ext/imagemap/doc/call_graph.dot +28 -0
- data/ext/imagemap/draw.c +567 -0
- data/ext/imagemap/extconf.rb +13 -0
- data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +1 -0
- data/ext/imagemap/lib/graphics/imagemap.rb +273 -0
- data/ext/imagemap/lib/image_map.rb +4 -0
- data/ext/imagemap/test/swath_index.rb +83 -0
- data/ext/imagemap/test/swath_warp.rb +99 -0
- data/ext/imagemap/test/test.rb +23 -0
- data/ext/imagemap/test/test_image.rb +42 -0
- data/ext/imagemap/test/test_line.rb +14 -0
- data/ext/imagemap/test/test_rotate.rb +17 -0
- data/ext/imagemap/test/test_triangle.rb +20 -0
- data/ext/imagemap/test/test_warp.rb +26 -0
- data/ext/mathfunc/carray_mathfunc.c +321 -0
- data/ext/mathfunc/extconf.rb +18 -0
- data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +1 -0
- data/ext/mathfunc/lib/math/mathfunc.rb +15 -0
- data/ext/mathfunc/test/test_hypot.rb +5 -0
- data/ext/mathfunc/test/test_j0.rb +22 -0
- data/ext/mathfunc/test/test_jn.rb +8 -0
- data/ext/mathfunc/test/test_sph.rb +9 -0
- data/ext/narray/README +22 -0
- data/ext/narray/ca_wrap_narray.c +491 -0
- data/ext/narray/carray_narray.c +21 -0
- data/ext/narray/extconf.rb +57 -0
- data/ext/narray/lib/autoload/autoload_math_narray.rb +1 -0
- data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +11 -0
- data/ext/narray/lib/math/narray.rb +17 -0
- data/ext/narray/lib/math/narray_miss.rb +45 -0
- data/extconf.rb +3 -25
- data/lib/carray.rb +28 -0
- data/lib/carray/autoload/autoload_base.rb +23 -0
- data/lib/carray/autoload/autoload_graphics_gnuplot.rb +2 -0
- data/lib/carray/autoload/autoload_io_csv.rb +14 -0
- data/lib/carray/autoload/autoload_io_excel.rb +5 -0
- data/lib/carray/autoload/autoload_io_imagemagick.rb +6 -0
- data/lib/carray/autoload/autoload_io_pg.rb +6 -0
- data/lib/carray/autoload/autoload_io_sqlite3.rb +12 -0
- data/lib/carray/autoload/autoload_io_table.rb +1 -0
- data/lib/carray/autoload/autoload_math_histogram.rb +5 -0
- data/lib/carray/autoload/autoload_math_interp.rb +4 -0
- data/lib/carray/autoload/autoload_math_recurrence.rb +6 -0
- data/lib/carray/autoload/autoload_object_iterator.rb +1 -0
- data/lib/carray/autoload/autoload_object_link.rb +1 -0
- data/lib/carray/autoload/autoload_object_pack.rb +2 -0
- data/lib/carray/base/autoload.rb +94 -0
- data/lib/carray/base/basic.rb +1051 -0
- data/lib/carray/base/inspect.rb +252 -0
- data/lib/carray/base/iterator.rb +367 -0
- data/lib/carray/base/math.rb +403 -0
- data/lib/carray/base/obsolete.rb +93 -0
- data/lib/carray/base/serialize.rb +260 -0
- data/lib/carray/base/struct.rb +634 -0
- data/lib/carray/graphics/gnuplot.rb +2116 -0
- data/lib/carray/info.rb +112 -0
- data/lib/carray/io/csv.rb +560 -0
- data/lib/carray/io/excel.rb +26 -0
- data/lib/carray/io/imagemagick.rb +231 -0
- data/lib/carray/io/pg.rb +101 -0
- data/lib/carray/io/sqlite3.rb +202 -0
- data/lib/carray/io/table.rb +77 -0
- data/lib/carray/math/histogram.rb +179 -0
- data/lib/carray/math/interp.rb +57 -0
- data/lib/carray/math/interp/adapter_gsl_spline.rb +47 -0
- data/lib/carray/math/recurrence.rb +95 -0
- data/lib/carray/mkmf.rb +145 -0
- data/lib/carray/object/ca_obj_iterator.rb +52 -0
- data/lib/carray/object/ca_obj_link.rb +52 -0
- data/lib/carray/object/ca_obj_pack.rb +101 -0
- data/mkmath.rb +731 -0
- data/mt19937ar.c +182 -0
- data/mt19937ar.h +86 -0
- data/rdoc_main.rb +27 -0
- data/rdoc_math.rb +5 -0
- data/rdoc_stat.rb +31 -0
- data/ruby_carray.c +242 -0
- data/ruby_ccomplex.c +497 -0
- data/ruby_float_func.c +83 -0
- data/spec/CABlockIterator/CABlockIterator_spec.rb +113 -0
- data/spec/CArray/bug/store_spec.rb +27 -0
- data/spec/CArray/index/repeat_spec.rb +10 -0
- data/spec/CArray/method/eq_spec.rb +80 -0
- data/spec/CArray/method/is_nan_spec.rb +12 -0
- data/spec/CArray/method/ne_spec.rb +18 -0
- data/spec/CArray/method/round_spec.rb +11 -0
- data/spec/CArray/object/_attribute_spec.rb +32 -0
- data/spec/CArray/object/s_new_spec.rb +31 -0
- data/spec/CArray/serialize/Serialization_spec.rb +89 -0
- data/spec/spec_all.rb +11 -0
- data/test/test_ALL.rb +50 -0
- data/test/test_CABitfield.rb +59 -0
- data/test/test_CABlock.rb +208 -0
- data/test/test_CAField.rb +40 -0
- data/test/test_CAGrid.rb +76 -0
- data/test/test_CAMapping.rb +106 -0
- data/test/test_CAMmap.rb +11 -0
- data/test/test_CARefer.rb +94 -0
- data/test/test_CARepeat.rb +66 -0
- data/test/test_CASelect.rb +23 -0
- data/test/test_CAShift.rb +17 -0
- data/test/test_CATranspose.rb +61 -0
- data/test/test_CAVirtual.rb +214 -0
- data/test/test_CAWindow.rb +55 -0
- data/test/test_CAWrap.rb +9 -0
- data/test/test_CArray.rb +228 -0
- data/test/test_CComplex.rb +83 -0
- data/test/test_CScalar.rb +91 -0
- data/test/test_attribute.rb +281 -0
- data/test/test_block_iterator.rb +17 -0
- data/test/test_boolean.rb +99 -0
- data/test/test_cast.rb +33 -0
- data/test/test_class.rb +85 -0
- data/test/test_complex.rb +43 -0
- data/test/test_composite.rb +125 -0
- data/test/test_convert.rb +79 -0
- data/test/test_copy.rb +141 -0
- data/test/test_creation.rb +85 -0
- data/test/test_element.rb +146 -0
- data/test/test_extream.rb +55 -0
- data/test/test_generate.rb +75 -0
- data/test/test_index.rb +71 -0
- data/test/test_mask.rb +578 -0
- data/test/test_math.rb +98 -0
- data/test/test_narray.rb +64 -0
- data/test/test_order.rb +147 -0
- data/test/test_random.rb +15 -0
- data/test/test_ref_store.rb +211 -0
- data/test/test_stat.rb +414 -0
- data/test/test_struct.rb +72 -0
- data/test/test_virtual.rb +49 -0
- data/utils/ca_ase.rb +21 -0
- data/utils/ca_methods.rb +15 -0
- data/utils/cast_checker.rb +30 -0
- data/utils/create_rdoc.sh +9 -0
- data/utils/diff_method.rb +52 -0
- data/utils/extract_rdoc.rb +27 -0
- data/utils/make_tgz.sh +3 -0
- data/utils/remove_resource_fork.sh +5 -0
- data/version.h +3 -3
- metadata +266 -1
data/ruby_float_func.c
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
ruby_numeric.c
|
4
|
+
|
5
|
+
This file is part of Ruby/CArray extension library.
|
6
|
+
You can redistribute it and/or modify it under the terms of
|
7
|
+
the Ruby Licence.
|
8
|
+
|
9
|
+
Copyright (C) 2005 Hiroki Motoyoshi
|
10
|
+
|
11
|
+
---------------------------------------------------------------------------- */
|
12
|
+
|
13
|
+
#include "ruby.h"
|
14
|
+
#include <math.h>
|
15
|
+
|
16
|
+
#define rb_num_func(name) \
|
17
|
+
static VALUE rb_num_ ## name (VALUE self) \
|
18
|
+
{ return rb_float_new(name(NUM2DBL(self))); }
|
19
|
+
|
20
|
+
rb_num_func(sqrt);
|
21
|
+
rb_num_func(exp);
|
22
|
+
rb_num_func(log);
|
23
|
+
rb_num_func(log10);
|
24
|
+
|
25
|
+
rb_num_func(sin);
|
26
|
+
rb_num_func(cos);
|
27
|
+
rb_num_func(tan);
|
28
|
+
rb_num_func(sinh);
|
29
|
+
rb_num_func(cosh);
|
30
|
+
rb_num_func(tanh);
|
31
|
+
|
32
|
+
rb_num_func(asin);
|
33
|
+
rb_num_func(acos);
|
34
|
+
rb_num_func(atan);
|
35
|
+
rb_num_func(asinh);
|
36
|
+
rb_num_func(acosh);
|
37
|
+
rb_num_func(atanh);
|
38
|
+
|
39
|
+
static VALUE
|
40
|
+
rb_num_rad (VALUE self)
|
41
|
+
{ return rb_float_new(0.0174532925199433*NUM2DBL(self)); }
|
42
|
+
|
43
|
+
static VALUE
|
44
|
+
rb_num_deg (VALUE self)
|
45
|
+
{ return rb_float_new(57.2957795130823*NUM2DBL(self)); }
|
46
|
+
|
47
|
+
static VALUE
|
48
|
+
rb_num_distance (VALUE self, VALUE other)
|
49
|
+
{
|
50
|
+
double fs = NUM2DBL(self), fo = NUM2DBL(other);
|
51
|
+
return rb_float_new(fabs(fs - fo));
|
52
|
+
}
|
53
|
+
|
54
|
+
void
|
55
|
+
Init_numeric_float_function ()
|
56
|
+
{
|
57
|
+
VALUE mod = rb_define_module_under(rb_cNumeric, "FloatFunction");
|
58
|
+
|
59
|
+
rb_define_method(mod, "sqrt", rb_num_sqrt, 0);
|
60
|
+
rb_define_method(mod, "exp", rb_num_exp, 0);
|
61
|
+
rb_define_method(mod, "log", rb_num_log, 0);
|
62
|
+
rb_define_method(mod, "log10", rb_num_log10, 0);
|
63
|
+
rb_define_method(mod, "sin", rb_num_sin, 0);
|
64
|
+
rb_define_method(mod, "cos", rb_num_cos, 0);
|
65
|
+
rb_define_method(mod, "tan", rb_num_tan, 0);
|
66
|
+
rb_define_method(mod, "sinh", rb_num_sinh, 0);
|
67
|
+
rb_define_method(mod, "cosh", rb_num_cosh, 0);
|
68
|
+
rb_define_method(mod, "tanh", rb_num_tanh, 0);
|
69
|
+
rb_define_method(mod, "asin", rb_num_asin, 0);
|
70
|
+
rb_define_method(mod, "acos", rb_num_acos, 0);
|
71
|
+
rb_define_method(mod, "atan", rb_num_atan, 0);
|
72
|
+
rb_define_method(mod, "asinh", rb_num_asinh, 0);
|
73
|
+
rb_define_method(mod, "acosh", rb_num_acosh, 0);
|
74
|
+
rb_define_method(mod, "atanh", rb_num_atanh, 0);
|
75
|
+
rb_define_method(mod, "rad", rb_num_rad, 0);
|
76
|
+
rb_define_method(mod, "deg", rb_num_deg, 0);
|
77
|
+
rb_define_method(mod, "distance", rb_num_distance, 1);
|
78
|
+
|
79
|
+
rb_include_module(rb_cFloat, mod);
|
80
|
+
rb_include_module(rb_cFixnum, mod);
|
81
|
+
rb_include_module(rb_cBignum, mod);
|
82
|
+
}
|
83
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require "carray"
|
2
|
+
|
3
|
+
describe CABlockIterator do
|
4
|
+
|
5
|
+
describe "each method" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@original = CArray.object(4,4).seq!
|
9
|
+
@it = @original.blocks(0..1, 0..1)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should call 4-times its block" do
|
13
|
+
count = 0
|
14
|
+
@it.each do |blk|
|
15
|
+
count += 1
|
16
|
+
end
|
17
|
+
( count ).should == 4
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have the block parameter of 2x2 CABlock object" do
|
21
|
+
@it.each do |blk|
|
22
|
+
( blk ).should be_an_instance_of(CABlock)
|
23
|
+
( blk.data_type ).should == CA_OBJECT
|
24
|
+
( blk.dim ).should == [2,2]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "reference method []" do
|
31
|
+
|
32
|
+
before do
|
33
|
+
@original = CArray.object(4,4).seq!
|
34
|
+
@it = @original.blocks(0..1, 0..1)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return a 2x2 CABlock object" do
|
38
|
+
blk = @it[0]
|
39
|
+
( blk ).should be_an_instance_of(CABlock)
|
40
|
+
( blk.data_type ).should == CA_OBJECT
|
41
|
+
( blk ).should == CA_OBJECT([[0,1],[4,5]])
|
42
|
+
blk = @it[1,0]
|
43
|
+
( blk ).should be_an_instance_of(CABlock)
|
44
|
+
( blk.data_type ).should == CA_OBJECT
|
45
|
+
( blk ).should == CA_OBJECT([[8,9],[12,13]])
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return a 2x2 CABlock object" do
|
49
|
+
( @it[0] ).should == @it.kernel_at_addr(0, @it.reference)
|
50
|
+
( @it[1,0] ).should == @it.kernel_at_index([1,0], @it.reference)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "store method []=" do
|
56
|
+
|
57
|
+
before do
|
58
|
+
@original = CArray.object(4,4).seq!
|
59
|
+
@it = @original.blocks(0..1, 0..1)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return a 2x2 CABlock object" do
|
63
|
+
@it[0] = 1
|
64
|
+
@it[1,0] = 2
|
65
|
+
( @it.reference ).should == CA_OBJECT( [ [ 1, 1, 2, 3 ],
|
66
|
+
[ 1, 1, 6, 7 ],
|
67
|
+
[ 2, 2, 10, 11 ],
|
68
|
+
[ 2, 2, 14, 15 ] ] )
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "pick method" do
|
74
|
+
|
75
|
+
before do
|
76
|
+
@original = CArray.object(4,4).seq!
|
77
|
+
@it = @original.blocks(0..1, 0..1)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return a 2x2 CABlock object" do
|
81
|
+
blk = @it.pick(0)
|
82
|
+
( blk ).should be_an_instance_of(CArray)
|
83
|
+
( blk.data_type ).should == CA_OBJECT
|
84
|
+
( blk ).should == CA_OBJECT([[0,2],[8,10]])
|
85
|
+
blk = @it.pick(1,0)
|
86
|
+
( blk ).should be_an_instance_of(CArray)
|
87
|
+
( blk.data_type ).should == CA_OBJECT
|
88
|
+
( blk ).should == CA_OBJECT([[4,6],[12,14]])
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "put method" do
|
94
|
+
|
95
|
+
before do
|
96
|
+
@original = CArray.object(4,4).seq!
|
97
|
+
@it = @original.blocks(0..1, 0..1)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should store value via 2x2 CBlock object" do
|
101
|
+
@it.put(0,1)
|
102
|
+
@it.put(0,1,2)
|
103
|
+
( @it.pick(0) ).should == CA_OBJECT([[1,1],[1,1]])
|
104
|
+
( @it.pick(0,1) ).should == CA_OBJECT([[2,2],[2,2]])
|
105
|
+
( @it.reference ).should == CA_OBJECT([[ 1, 2, 1, 2 ],
|
106
|
+
[ 4, 5, 6, 7 ],
|
107
|
+
[ 1, 2, 1, 2 ],
|
108
|
+
[ 12, 13, 14, 15 ]])
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
require "carray"
|
3
|
+
|
4
|
+
describe "CArray#[]" do
|
5
|
+
|
6
|
+
it "should return one element array with [nil,-1]" do
|
7
|
+
ca = CArray.int(4,4).seq!
|
8
|
+
( ca[[nil,-1]].elements ).should == 1
|
9
|
+
( ca[[nil,-1]] ).should == ca[[0]]
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return self[[0],nil] with [nil,-1], nil" do
|
13
|
+
ca = CArray.int(4,4).seq!
|
14
|
+
( ca[[nil,-1],nil] ).should == ca[[0],nil]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return self[[0],nil] with nil, [nil,-1]" do
|
18
|
+
ca = CArray.int(4,4).seq!
|
19
|
+
( ca[nil,[nil,-1]] ).should == ca[nil,[0]]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return self[[0],nil] with [nil,-1], [nil,-1]" do
|
23
|
+
ca = CArray.int(4,4).seq!
|
24
|
+
( ca[[nil,-1],[nil,-1]] ).should == ca[[0],[0]]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
|
2
|
+
require "carray"
|
3
|
+
|
4
|
+
describe "CArray#eq" do
|
5
|
+
|
6
|
+
it "returns 1 if self and other equal (int)" do
|
7
|
+
ca123 = CA_INT([123])
|
8
|
+
|
9
|
+
( (ca123).eq(123 )[0] ).should == 1
|
10
|
+
( (ca123).eq(ca123)[0] ).should == 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns 1 if self and other equal (object)" do
|
14
|
+
ca123 = CA_OBJECT(["123"])
|
15
|
+
|
16
|
+
( (ca123).eq("123")[0] ).should == 1
|
17
|
+
( (ca123).eq(ca123)[0] ).should == 1
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns 1 if self and other equal (fixlen)" do
|
21
|
+
ca123 = CA_FIXLEN(["123"], :bytes=>3)
|
22
|
+
|
23
|
+
( (ca123).eq("123")[0] ).should == 1
|
24
|
+
( (ca123).eq(ca123)[0] ).should == 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns 0 if self and other equal (int)" do
|
28
|
+
ca123 = CA_INT([123])
|
29
|
+
ca124 = CA_INT([124])
|
30
|
+
|
31
|
+
( (ca123).eq(124 )[0] ).should == 0
|
32
|
+
( (ca123).eq(ca124)[0] ).should == 0
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns 0 if self and other equal (object)" do
|
36
|
+
ca123 = CA_OBJECT(["123"])
|
37
|
+
ca124 = CA_OBJECT(["124"])
|
38
|
+
|
39
|
+
( (ca123).eq("124")[0] ).should == 0
|
40
|
+
( (ca123).eq(ca124)[0] ).should == 0
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns 0 if self and other equal (fixlen)" do
|
44
|
+
ca123 = CA_FIXLEN(["123"], :bytes=>3)
|
45
|
+
ca124 = CA_FIXLEN(["124"], :bytes=>3)
|
46
|
+
ca12 = CA_FIXLEN(["12"], :bytes=>3)
|
47
|
+
|
48
|
+
( (ca123).eq("124")[0] ).should == 0
|
49
|
+
( (ca123).eq(ca124)[0] ).should == 0
|
50
|
+
|
51
|
+
( (ca123).eq("12")[0] ).should == 0
|
52
|
+
( (ca123).eq(ca12)[0] ).should == 0
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns 0 if self is a NaN" do
|
56
|
+
nan = 0.0/0.0
|
57
|
+
|
58
|
+
( (nan ).eq(CA_DOUBLE([0.0]))[0] ).should == 0
|
59
|
+
( (CA_DOUBLE([nan])).eq(0.0 )[0] ).should == 0
|
60
|
+
( (CA_DOUBLE([nan])).eq(CA_DOUBLE([0.0]))[0] ).should == 0
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns 0 if self and other are NaN" do
|
64
|
+
nan = 0.0/0.0
|
65
|
+
|
66
|
+
( (nan ).eq(CA_DOUBLE([nan]))[0] ).should == 0
|
67
|
+
( (CA_DOUBLE([nan])).eq(nan )[0] ).should == 0
|
68
|
+
( (CA_DOUBLE([nan])).eq(CA_DOUBLE([nan]))[0] ).should == 0
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns 0 if other is a NaN" do
|
72
|
+
nan = 0.0/0.0
|
73
|
+
|
74
|
+
( (0.0 ).eq(CA_DOUBLE([nan]))[0] ).should == 0
|
75
|
+
( (CA_DOUBLE([0.0])).eq(nan )[0] ).should == 0
|
76
|
+
( (CA_DOUBLE([0.0])).eq(CA_DOUBLE([nan]))[0] ).should == 0
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
require "carray"
|
3
|
+
|
4
|
+
describe "CArray#is_nan" do
|
5
|
+
it "returns 1 if self is not a valid IEEE floating-point number" do
|
6
|
+
CA_DOUBLE(0.0).is_nan[0].should == 0
|
7
|
+
CA_DOUBLE(-1.5).is_nan[0].should == 0
|
8
|
+
(CA_DOUBLE(0.0)/CA_DOUBLE(0.0)).is_nan[0].should == 1
|
9
|
+
CA_DOUBLE(0.0/0.0).is_nan[0].should == 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
require "carray"
|
3
|
+
|
4
|
+
describe "CArray#ne" do
|
5
|
+
it "returns 0 if self is not a valid IEEE floating-point number" do
|
6
|
+
nan = 0.0/0.0
|
7
|
+
0.0.ne(CA_DOUBLE(nan))[0].should == 1
|
8
|
+
nan.ne(CA_DOUBLE(nan))[0].should == 1
|
9
|
+
nan.ne(CA_DOUBLE(0.0))[0].should == 1
|
10
|
+
CA_DOUBLE(nan).ne(0.0)[0].should == 1
|
11
|
+
CA_DOUBLE(nan).ne(nan)[0].should == 1
|
12
|
+
CA_DOUBLE(0.0).ne(nan)[0].should == 1
|
13
|
+
CA_DOUBLE(nan).ne(CA_DOUBLE(0.0))[0].should == 1
|
14
|
+
CA_DOUBLE(nan).ne(CA_DOUBLE(nan))[0].should == 1
|
15
|
+
CA_DOUBLE(0.0).ne(CA_DOUBLE(nan))[0].should == 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require "carray"
|
3
|
+
|
4
|
+
describe "CArray#elements" do
|
5
|
+
|
6
|
+
it "should return element number of array" do
|
7
|
+
ca = CArray.int32(2,3,4)
|
8
|
+
( ca.elements ).should == 2*3*4
|
9
|
+
( ca.length ).should == 2*3*4
|
10
|
+
( ca.size ).should == 2*3*4
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "CArray#data_type" do
|
16
|
+
|
17
|
+
it "should return data type of array" do
|
18
|
+
ca = CArray.int32(2,3,4)
|
19
|
+
( ca.data_type ).should == CA_INT32
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "CArray#dim" do
|
25
|
+
|
26
|
+
it "should return a array contains the shape of array" do
|
27
|
+
ca = CArray.int32(2,3,4)
|
28
|
+
( ca.dim ).should == [2,3,4]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
require "carray"
|
3
|
+
|
4
|
+
describe "CArray.new" do
|
5
|
+
|
6
|
+
it "should return a CA_INT type carray if CA_INT is specified as data_type" do
|
7
|
+
ca = CArray.new(CA_INT, [2,3,4])
|
8
|
+
( ca.class ).should == CArray
|
9
|
+
( ca.data_type ).should == CA_INT
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return a CA_FIXLEN type carray if CA_FIXLEN is specified as data_type" do
|
13
|
+
ca = CArray.new(CA_FIXLEN, [2,3,4], :bytes=>3)
|
14
|
+
( ca.class ).should == CArray
|
15
|
+
( ca.data_type ).should == CA_FIXLEN
|
16
|
+
( ca.bytes ).should == 3
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return a carray filled by 0 when data_type == CA_INT" do
|
20
|
+
ca = CArray.new(CA_INT, [2,3,4])
|
21
|
+
( ca[0] ).should == 0
|
22
|
+
( ca.all_equal?(0) ).should == true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return a carray filled by string filled by 0 when data_type == CA_FIXLEN" do
|
26
|
+
ca = CArray.new(CA_FIXLEN, [2,3,4], :bytes=>3)
|
27
|
+
( ca[0] ).should == "\0\0\0"
|
28
|
+
( ca.all_equal?("\0\0\0") ).should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "carray"
|
2
|
+
|
3
|
+
describe CArray do
|
4
|
+
|
5
|
+
describe "loaded from binary format (int32 type)" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@original = CArray.int32(10,10) { 10 }
|
9
|
+
@original[5,5] = UNDEF
|
10
|
+
CArray.save(@original, "test.ca")
|
11
|
+
@it = CArray.load("test.ca")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should equal to original" do
|
15
|
+
( @it ).should == @original
|
16
|
+
( @it.has_mask? ).should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should dump string of same contents with file from which it was loaded" do
|
20
|
+
( CArray.dump(@it) ).should == File.read("test.ca")
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
File.unlink("test.ca")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "loaded from binary format (object type)" do
|
30
|
+
|
31
|
+
before do
|
32
|
+
@original = CArray.object(10,10) { 3.times { Time.now } }
|
33
|
+
@original[5,5] = UNDEF
|
34
|
+
CArray.save(@original, "test.ca")
|
35
|
+
@it = CArray.load("test.ca")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should equal to original" do
|
39
|
+
( @it ).should == @original
|
40
|
+
( @it.has_mask? ).should == true
|
41
|
+
end
|
42
|
+
|
43
|
+
after do
|
44
|
+
File.unlink("test.ca")
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "loaded by marshal (int32 type)" do
|
50
|
+
|
51
|
+
before do
|
52
|
+
@original = CArray.int32(10,10) { 10 }
|
53
|
+
@original[5,5] = UNDEF
|
54
|
+
open("test.ca", "w") { |io| Marshal.dump(@original, io) }
|
55
|
+
@it = open("test.ca") { |io| Marshal.load(io) }
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should equal to original" do
|
59
|
+
( @it ).should == @original
|
60
|
+
( @it.has_mask? ).should == true
|
61
|
+
end
|
62
|
+
|
63
|
+
after do
|
64
|
+
File.unlink("test.ca")
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "loaded by marshal (object type)" do
|
70
|
+
|
71
|
+
before do
|
72
|
+
@original = CArray.object(10,10) { 3.times { Time.now } }
|
73
|
+
@original[5,5] = UNDEF
|
74
|
+
open("test.ca", "w") { |io| Marshal.dump(@original, io) }
|
75
|
+
@it = open("test.ca") { |io| Marshal.load(io) }
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should equal to original" do
|
79
|
+
( @it ).should == @original
|
80
|
+
( @it.has_mask? ).should == true
|
81
|
+
end
|
82
|
+
|
83
|
+
after do
|
84
|
+
File.unlink("test.ca")
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|