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
@@ -0,0 +1,106 @@
|
|
1
|
+
$:.unshift("../lib", "..")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'carray'
|
5
|
+
|
6
|
+
class TestCArrayCAMapping < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_virtual_array
|
9
|
+
a = CArray.int(3,3)
|
10
|
+
idx = CArray.int(3,3).seq!
|
11
|
+
b = a[idx]
|
12
|
+
r = b.parent
|
13
|
+
assert_instance_of(CAMapping, b)
|
14
|
+
assert_equal(true, b.virtual?)
|
15
|
+
assert_equal(a, r)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_basic_features
|
19
|
+
# ---
|
20
|
+
a = CArray.int(3,3).seq!
|
21
|
+
idx = CArray.int(3,3) { 4 }
|
22
|
+
assert_equal(CA_INT([[4,4,4],
|
23
|
+
[4,4,4],
|
24
|
+
[4,4,4]]), a[idx])
|
25
|
+
# ---
|
26
|
+
a = CArray.int(3,3).seq!
|
27
|
+
idx = CArray.int(3,3).seq!.reverse!
|
28
|
+
assert_equal(CA_INT([[8,7,6],
|
29
|
+
[5,4,3],
|
30
|
+
[2,1,0]]), a[idx])
|
31
|
+
a[idx].seq!
|
32
|
+
assert_equal(CA_INT([[8,7,6],
|
33
|
+
[5,4,3],
|
34
|
+
[2,1,0]]), a)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_invalid_args
|
38
|
+
# ---
|
39
|
+
a = CArray.int(3,3).seq!
|
40
|
+
idx = CArray.int(3,3) { 4 }
|
41
|
+
idx[1,1] = UNDEF
|
42
|
+
assert_raise(ArgumentError) { a[idx] }
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_out_of_range
|
46
|
+
# ---
|
47
|
+
a = CArray.int(3,3).seq!
|
48
|
+
idx = CArray.int(3,3) { 9 }
|
49
|
+
assert_raise(IndexError) { a[idx] }
|
50
|
+
|
51
|
+
# ---
|
52
|
+
a = CArray.int(3,3).seq!
|
53
|
+
idx = CArray.int(3,3) { -1 }
|
54
|
+
assert_equal(CA_INT([[8,8,8],
|
55
|
+
[8,8,8],
|
56
|
+
[8,8,8]]), a[idx])
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_mask
|
60
|
+
_ = UNDEF
|
61
|
+
# ---
|
62
|
+
a = CArray.int(3,3).seq!
|
63
|
+
idx = CArray.int(3,3).seq!
|
64
|
+
a[1,1] = UNDEF
|
65
|
+
assert_equal(CA_INT([[0,1,2],
|
66
|
+
[3,_,5],
|
67
|
+
[6,7,8]]), a[idx])
|
68
|
+
a[idx][1,1] = -1
|
69
|
+
assert_equal(CA_INT([[0,1,2],
|
70
|
+
[3,-1,5],
|
71
|
+
[6,7,8]]), a)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_fill
|
75
|
+
_ = UNDEF
|
76
|
+
# ---
|
77
|
+
a = CArray.int(3,3).seq!
|
78
|
+
idx = CArray.int(3,3).seq!
|
79
|
+
a[idx] = 9
|
80
|
+
assert_equal(CA_INT([[9,9,9],
|
81
|
+
[9,9,9],
|
82
|
+
[9,9,9]]), a)
|
83
|
+
a[idx] = UNDEF
|
84
|
+
assert_equal(CA_INT([[_,_,_],
|
85
|
+
[_,_,_],
|
86
|
+
[_,_,_]]), a)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_sync
|
90
|
+
# ---
|
91
|
+
a = CArray.int(3,3).seq!
|
92
|
+
idx = CArray.int(3,3) { 4 }
|
93
|
+
a[idx] = -1 ### not recomended usage
|
94
|
+
assert_equal(CA_INT([[0,1,2],
|
95
|
+
[3,-1,5],
|
96
|
+
[6,7,8]]), a)
|
97
|
+
# ---
|
98
|
+
a = CArray.int(3,3).seq!
|
99
|
+
idx = CArray.int(3,3) { 4 }
|
100
|
+
a[idx].seq! ### not recomended usage
|
101
|
+
assert_equal(CA_INT([[0,1,2],
|
102
|
+
[3,8,5],
|
103
|
+
[6,7,8]]), a)
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/test/test_CAMmap.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
$:.unshift("../lib", "..")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'carray'
|
5
|
+
|
6
|
+
class TestCArrayCARefer < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_virtual_array
|
9
|
+
a = CArray.int(3,3)
|
10
|
+
b = a.refer(CA_INT,[9])
|
11
|
+
r = b.parent
|
12
|
+
assert_instance_of(CARefer, b)
|
13
|
+
assert_equal(true, b.virtual?)
|
14
|
+
assert_equal(a, r)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_basic_features
|
18
|
+
# ---
|
19
|
+
a = CArray.int(3,2).seq!
|
20
|
+
r = a.reshape(2,3)
|
21
|
+
assert_equal(a.data_type, r.data_type)
|
22
|
+
assert_equal([2,3], r.dim)
|
23
|
+
assert_equal(CA_INT([[0,1,2],
|
24
|
+
[3,4,5]]), r)
|
25
|
+
|
26
|
+
# ---
|
27
|
+
# less data number
|
28
|
+
a = CArray.int(3,2).seq!
|
29
|
+
r = a.reshape(2,2)
|
30
|
+
assert_equal(CA_INT([[0,1],
|
31
|
+
[2,3]]), r)
|
32
|
+
|
33
|
+
# ---
|
34
|
+
# data type change (int -> float)
|
35
|
+
a = CArray.int(3,2).seq!
|
36
|
+
r = a.refer(CA_FLOAT32, [2,3])
|
37
|
+
rr = r.refer(CA_INT32, [3,2])
|
38
|
+
assert_equal(CA_FLOAT, r.data_type)
|
39
|
+
assert_equal(a, rr)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_refer_to_virtual_array
|
43
|
+
# ---
|
44
|
+
a = CArray.int(3,3).seq!
|
45
|
+
b = a[1..2,1..2]
|
46
|
+
r = b.reshape(4)
|
47
|
+
assert_equal(CA_INT([4,5,7,8]), r)
|
48
|
+
|
49
|
+
# ---
|
50
|
+
a = CArray.int(3).seq!
|
51
|
+
b = a[:%,3]
|
52
|
+
r = b.reshape(9)
|
53
|
+
assert_equal(CA_INT([0,0,0,1,1,1,2,2,2]), r)
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_invalid_args
|
58
|
+
# ---
|
59
|
+
a = CArray.int8(3,3).seq!
|
60
|
+
assert_raise(RuntimeError) { a.reshape(10) } ### too large data num
|
61
|
+
assert_raise(RuntimeError) { a.refer(CA_INT,[9]) }
|
62
|
+
### larger data type bytes
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_flatten
|
67
|
+
a = CArray.int(3,3).seq!
|
68
|
+
b = CArray.int(9).seq!
|
69
|
+
|
70
|
+
# ---
|
71
|
+
assert_equal(b, a.flatten)
|
72
|
+
assert_equal(b, a.flattened)
|
73
|
+
|
74
|
+
# ---
|
75
|
+
c = a.reverse
|
76
|
+
a.flattened.reverse!
|
77
|
+
assert_equal(c, a)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_refer_variant
|
81
|
+
a = CArray.fixlen(4, :bytes=>4) {"abcd"}
|
82
|
+
b = CA_FIXLEN([["ab", "cd"],
|
83
|
+
["ab", "cd"],
|
84
|
+
["ab", "cd"],
|
85
|
+
["ab", "cd"]], :bytes=>2)
|
86
|
+
c = CA_FIXLEN(["abcdabcd", "abcdabcd"], :bytes=>8)
|
87
|
+
|
88
|
+
# ---
|
89
|
+
assert_equal(b, a.refer(CA_FIXLEN, [4,2], :bytes=>2))
|
90
|
+
assert_equal(c, a.refer(CA_FIXLEN, [2], :bytes=>8))
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
$:.unshift("../lib", "..")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'carray'
|
5
|
+
|
6
|
+
class TestCArrayCARepeat < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_virtual_array
|
9
|
+
a = CArray.int(3)
|
10
|
+
b = a[:%,3]
|
11
|
+
r = b.parent
|
12
|
+
assert_instance_of(CARepeat, b)
|
13
|
+
assert_equal(true, b.virtual?)
|
14
|
+
assert_equal(true, b.read_only?)
|
15
|
+
assert_equal(false, b.attached?)
|
16
|
+
assert_equal(a, r)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_basic_feature
|
20
|
+
# ---
|
21
|
+
a = CArray.int(3).seq!
|
22
|
+
r1 = a[3,:%]
|
23
|
+
r2 = a[:%,3]
|
24
|
+
assert_equal(CA_INT([[0,1,2],
|
25
|
+
[0,1,2],
|
26
|
+
[0,1,2]]), r1)
|
27
|
+
assert_equal(CA_INT([[0,0,0],
|
28
|
+
[1,1,1],
|
29
|
+
[2,2,2]]), r2)
|
30
|
+
# ---
|
31
|
+
b = CArray.int(2,2).seq!
|
32
|
+
assert_equal(CA_INT([[[ 0, 1 ],
|
33
|
+
[ 0, 1 ]],
|
34
|
+
[[ 2, 3 ],
|
35
|
+
[ 2, 3 ]]]), b[:%,2,:%])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_store
|
39
|
+
a = CArray.int(3).seq!
|
40
|
+
r1 = a[3,:%]
|
41
|
+
assert_raise(RuntimeError) { r1[1,1] = 1 }
|
42
|
+
assert_raise(RuntimeError) { r1.seq! }
|
43
|
+
r2 = a[:%,3]
|
44
|
+
assert_raise(RuntimeError) { r1[1,1] = 1 }
|
45
|
+
assert_raise(RuntimeError) { r1.seq! }
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_mask_repeat
|
49
|
+
a = CArray.int(3).seq!
|
50
|
+
a[1] = UNDEF
|
51
|
+
r1 = a[3,:%]
|
52
|
+
x1 = r1.to_ca
|
53
|
+
assert_equal(3, r1.count_masked)
|
54
|
+
assert_equal(3, r1[nil,1].count_masked)
|
55
|
+
assert_equal(3, x1.count_masked)
|
56
|
+
assert_equal(3, x1[nil,1].count_masked)
|
57
|
+
|
58
|
+
r2 = a[:%,3]
|
59
|
+
x2 = r2.to_ca
|
60
|
+
assert_equal(3, r2.count_masked)
|
61
|
+
assert_equal(3, r2[1,nil].count_masked)
|
62
|
+
assert_equal(3, x2.count_masked)
|
63
|
+
assert_equal(3, x2[1,nil].count_masked)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.unshift("../lib", "..")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'carray'
|
5
|
+
|
6
|
+
class TestCArrayCASelect < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_virtual_array
|
9
|
+
a = CArray.int(3,3) { 0 }
|
10
|
+
b = a[a.eq(0)]
|
11
|
+
r = b.parent
|
12
|
+
assert_instance_of(CASelect, b)
|
13
|
+
assert_equal(true, b.virtual?)
|
14
|
+
assert_equal(a, r)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_select_to_a
|
18
|
+
a = CArray.int(3,3).seq!
|
19
|
+
s = a[a >= 4]
|
20
|
+
assert_equal([4, 5, 6, 7, 8], a[s].to_a)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift("../lib", "..")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'carray'
|
5
|
+
|
6
|
+
class TestCArrayCAShift < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_virtual_array
|
9
|
+
a = CArray.int(3,3)
|
10
|
+
b = a.shifted(1,1)
|
11
|
+
r = b.parent
|
12
|
+
assert_instance_of(CAShift, b)
|
13
|
+
assert_equal(true, b.virtual?)
|
14
|
+
assert_equal(a, r)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
$:.unshift("../lib", "..")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'carray'
|
5
|
+
|
6
|
+
class TestCArrayCATranspose < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_virtual_array
|
9
|
+
a = CArray.int(3,3)
|
10
|
+
b = a.transposed
|
11
|
+
r = b.parent
|
12
|
+
assert_instance_of(CATranspose, b)
|
13
|
+
assert_equal(true, b.virtual?)
|
14
|
+
assert_equal(a, r)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_basic_feature
|
18
|
+
# ---
|
19
|
+
a = CArray.int(3,3).seq!
|
20
|
+
t = a.transposed
|
21
|
+
assert_equal(CA_INT([[0,3,6],
|
22
|
+
[1,4,7],
|
23
|
+
[2,5,8]]), t)
|
24
|
+
|
25
|
+
# ---
|
26
|
+
a = CArray.int(2,2,2).seq!
|
27
|
+
t1 = a.transposed(0,1,2)
|
28
|
+
t2 = a.transposed(0,2,1) # 1 <-> 2
|
29
|
+
t3 = a.transposed(2,1,0) # 0 <-> 2
|
30
|
+
t4 = a.transposed(1,0,2) # 0 <-> 1
|
31
|
+
assert_equal(CA_INT([[[0,1],
|
32
|
+
[2,3]],
|
33
|
+
[[4,5],
|
34
|
+
[6,7]]]), t1)
|
35
|
+
assert_equal(CA_INT([[[0,2],
|
36
|
+
[1,3]],
|
37
|
+
[[4,6],
|
38
|
+
[5,7]]]), t2)
|
39
|
+
assert_equal(CA_INT([[[0,4],
|
40
|
+
[2,6]],
|
41
|
+
[[1,5],
|
42
|
+
[3,7]]]), t3)
|
43
|
+
assert_equal(CA_INT([[[0,1],
|
44
|
+
[4,5]],
|
45
|
+
[[2,3],
|
46
|
+
[6,7]]]), t4)
|
47
|
+
|
48
|
+
# ---
|
49
|
+
a = CArray.int(2,2,2).seq!
|
50
|
+
|
51
|
+
x1 = a.transposed(1,2,0) # 0 -> 2, 1 -> 0, 2 -> 1
|
52
|
+
y1 = a.transposed(2,1,0).transposed(1,0,2) # 1 <-> 2; 0 <-> 1
|
53
|
+
assert_equal(y1, x1)
|
54
|
+
|
55
|
+
x2 = a.transposed(2,0,1) # 0 -> 1, 1 -> 2, 2 -> 0
|
56
|
+
y2 = a.transposed(2,1,0).transposed(0,2,1) # 0 <-> 2; 1 <-> 2
|
57
|
+
assert_equal(y2, x2)
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
$:.unshift("../lib", "..")
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'carray'
|
5
|
+
|
6
|
+
module TestCAVirtualMixin
|
7
|
+
|
8
|
+
def test_fetch_index
|
9
|
+
10.times do
|
10
|
+
idx = @ref.dim.map{|x| rand(x)}
|
11
|
+
assert_equal(@ref[*idx], @obj[*idx])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_fetch_addr
|
16
|
+
10.times do
|
17
|
+
addr = rand(@ref.elements)
|
18
|
+
assert_equal(@ref[addr], @obj[addr])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_store_index
|
23
|
+
unless @obj.read_only?
|
24
|
+
10.times do
|
25
|
+
idx = @ref.dim.map{|x| rand(x)}
|
26
|
+
v = rand(10)
|
27
|
+
@ref[*idx] = v
|
28
|
+
@obj[*idx] = v
|
29
|
+
assert_equal(@ref[*idx], @obj[*idx])
|
30
|
+
end
|
31
|
+
assert_equal(@ref, @obj)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_store_addr
|
36
|
+
unless @obj.read_only?
|
37
|
+
10.times do
|
38
|
+
addr = rand(@ref.elements)
|
39
|
+
@ref[addr] = @obj[addr] = rand(10)
|
40
|
+
assert_equal(@ref[addr], @obj[addr])
|
41
|
+
end
|
42
|
+
assert_equal(@ref, @obj)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_attach
|
47
|
+
assert_equal(@ref, @obj)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_sync
|
51
|
+
unless @obj.read_only?
|
52
|
+
assert_equal(@ref.seq!, @obj.seq!)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_copy_data
|
57
|
+
assert_equal(@ref, @obj.to_ca)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_sync_data
|
61
|
+
unless @obj.read_only?
|
62
|
+
val = @ref.reverse
|
63
|
+
@ref[] = val
|
64
|
+
@obj[] = val
|
65
|
+
assert_equal(@ref, @obj)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_fill_data
|
70
|
+
unless @obj.read_only?
|
71
|
+
@obj[] = 1
|
72
|
+
assert_equal(@ref.template{1}, @obj)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_create_mask
|
77
|
+
unless @obj.read_only?
|
78
|
+
5.times do
|
79
|
+
addr = rand(@ref.elements)
|
80
|
+
@ref[addr] = UNDEF
|
81
|
+
@obj[addr] = UNDEF
|
82
|
+
end
|
83
|
+
assert_equal(@ref, @obj)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
class TestCARefer < Test::Unit::TestCase
|
90
|
+
|
91
|
+
include TestCAVirtualMixin
|
92
|
+
|
93
|
+
def setup
|
94
|
+
@ref = CArray.int32(10, 10).seq!
|
95
|
+
orig = CArray.int32(10, 10).seq!
|
96
|
+
@obj = orig[]
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
class TestCABlock < Test::Unit::TestCase
|
102
|
+
|
103
|
+
include TestCAVirtualMixin
|
104
|
+
|
105
|
+
def setup
|
106
|
+
@ref = CArray.int32(10, 10).seq!
|
107
|
+
orig = CArray.int32(10, 10).seq!
|
108
|
+
@obj = orig[0..-1, 0..-1]
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
class TestCASelect < Test::Unit::TestCase
|
114
|
+
|
115
|
+
include TestCAVirtualMixin
|
116
|
+
|
117
|
+
def setup
|
118
|
+
@ref = CArray.int32(10, 10).seq!.flatten
|
119
|
+
orig = CArray.int32(10, 10).seq!
|
120
|
+
@obj = orig[orig.true]
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
class TestCAMapping < Test::Unit::TestCase
|
126
|
+
|
127
|
+
include TestCAVirtualMixin
|
128
|
+
|
129
|
+
def setup
|
130
|
+
@ref = CArray.int32(10, 10).seq!
|
131
|
+
orig = CArray.int32(10, 10).seq!
|
132
|
+
@obj = orig[orig]
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
class TestCAGrid < Test::Unit::TestCase
|
138
|
+
|
139
|
+
include TestCAVirtualMixin
|
140
|
+
|
141
|
+
def setup
|
142
|
+
@ref = CArray.int32(10, 10).seq!
|
143
|
+
orig = CArray.int32(10, 10).seq!
|
144
|
+
idx = CArray.int32(10).seq!
|
145
|
+
@obj = @ref[idx,idx]
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
class TestCARepeat < Test::Unit::TestCase
|
151
|
+
|
152
|
+
include TestCAVirtualMixin
|
153
|
+
|
154
|
+
def setup
|
155
|
+
orig = CArray.int32(10).seq!
|
156
|
+
@ref = CArray.int32(10, 10)
|
157
|
+
10.times do |i|
|
158
|
+
@ref[nil,i] = orig
|
159
|
+
end
|
160
|
+
@obj = orig[:%, 10]
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
class TestCAFake < Test::Unit::TestCase
|
166
|
+
|
167
|
+
include TestCAVirtualMixin
|
168
|
+
|
169
|
+
def setup
|
170
|
+
@ref = CArray.int16(10, 10).seq!
|
171
|
+
orig = CArray.int32(10,10).seq!
|
172
|
+
@obj = orig.as_int16
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
class TestCAFarray < Test::Unit::TestCase
|
178
|
+
|
179
|
+
include TestCAVirtualMixin
|
180
|
+
|
181
|
+
def setup
|
182
|
+
@ref = CArray.int32(10,10).seq!
|
183
|
+
@ref[] = @ref.to_a.transpose
|
184
|
+
orig = CArray.int32(10,10).seq!
|
185
|
+
@obj = orig.t
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
class TestCATranspose < Test::Unit::TestCase
|
191
|
+
|
192
|
+
include TestCAVirtualMixin
|
193
|
+
|
194
|
+
def setup
|
195
|
+
@ref = CArray.int32(10,10).seq!
|
196
|
+
@ref[] = @ref.to_a.transpose
|
197
|
+
orig = CArray.int32(10,10).seq!
|
198
|
+
@obj = orig.transposed
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
class TestCAWindow < Test::Unit::TestCase
|
204
|
+
|
205
|
+
include TestCAVirtualMixin
|
206
|
+
|
207
|
+
def setup
|
208
|
+
@ref = CArray.int32(15,15).seq![0..9, 0..9].to_ca
|
209
|
+
orig = CArray.int32(15,15).seq!
|
210
|
+
@obj = orig.window(0..9, 0..9)
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|