carray 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSES → LICENSE} +0 -0
  3. data/NEWS.md +42 -0
  4. data/README.md +5 -5
  5. data/TODO.md +16 -0
  6. data/carray.gemspec +9 -5
  7. data/ext/ca_iter_block.c +3 -5
  8. data/ext/ca_iter_dimension.c +4 -5
  9. data/ext/ca_iter_window.c +2 -4
  10. data/ext/ca_obj_array.c +394 -124
  11. data/ext/ca_obj_bitarray.c +3 -5
  12. data/ext/ca_obj_bitfield.c +3 -5
  13. data/ext/ca_obj_block.c +6 -8
  14. data/ext/ca_obj_fake.c +3 -5
  15. data/ext/ca_obj_farray.c +3 -5
  16. data/ext/ca_obj_field.c +15 -17
  17. data/ext/ca_obj_grid.c +5 -6
  18. data/ext/ca_obj_mapping.c +2 -4
  19. data/ext/ca_obj_object.c +3 -5
  20. data/ext/ca_obj_reduce.c +2 -4
  21. data/ext/ca_obj_refer.c +5 -7
  22. data/ext/ca_obj_repeat.c +2 -4
  23. data/ext/ca_obj_select.c +2 -4
  24. data/ext/ca_obj_shift.c +3 -5
  25. data/ext/ca_obj_transpose.c +3 -5
  26. data/ext/ca_obj_unbound_repeat.c +58 -81
  27. data/ext/ca_obj_window.c +7 -9
  28. data/ext/carray.h +13 -8
  29. data/ext/carray_access.c +111 -18
  30. data/ext/carray_attribute.c +136 -197
  31. data/ext/carray_call_cfunc.c +1 -3
  32. data/ext/carray_cast.c +344 -143
  33. data/ext/carray_cast_func.rb +1 -2
  34. data/ext/carray_class.c +28 -36
  35. data/ext/carray_conversion.c +49 -59
  36. data/ext/carray_copy.c +16 -32
  37. data/ext/carray_core.c +51 -44
  38. data/ext/carray_element.c +25 -44
  39. data/ext/carray_generate.c +71 -50
  40. data/ext/carray_iterator.c +13 -15
  41. data/ext/carray_loop.c +53 -82
  42. data/ext/carray_mask.c +87 -117
  43. data/ext/carray_math.rb +8 -10
  44. data/ext/carray_mathfunc.c +1 -3
  45. data/ext/carray_numeric.c +19 -3
  46. data/ext/carray_operator.c +45 -32
  47. data/ext/carray_order.c +72 -65
  48. data/ext/carray_sort_addr.c +14 -21
  49. data/ext/carray_stat.c +1 -3
  50. data/ext/carray_stat_proc.rb +2 -4
  51. data/ext/carray_test.c +28 -30
  52. data/ext/carray_undef.c +1 -3
  53. data/ext/carray_utils.c +12 -4
  54. data/ext/extconf.rb +1 -1
  55. data/ext/mkmath.rb +1 -1
  56. data/ext/ruby_carray.c +11 -6
  57. data/ext/ruby_ccomplex.c +1 -3
  58. data/ext/ruby_float_func.c +1 -3
  59. data/ext/version.h +5 -7
  60. data/lib/carray.rb +2 -0
  61. data/lib/carray/autoload/autoload_gem_numo_narray.rb +6 -6
  62. data/lib/carray/broadcast.rb +45 -0
  63. data/lib/carray/construct.rb +21 -4
  64. data/lib/carray/iterator.rb +1 -0
  65. data/lib/carray/ordering.rb +28 -2
  66. data/spec/Classes/CABitfield_spec.rb +58 -0
  67. data/spec/Classes/CABlockIterator_spec.rb +114 -0
  68. data/spec/Classes/CABlock_spec.rb +205 -0
  69. data/spec/Classes/CAField_spec.rb +39 -0
  70. data/spec/Classes/CAGrid_spec.rb +75 -0
  71. data/spec/Classes/CAMap_spec.rb +0 -0
  72. data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
  73. data/spec/Classes/CAObject_attribute_spec.rb +33 -0
  74. data/spec/Classes/CAObject_spec.rb +33 -0
  75. data/spec/Classes/CARefer_spec.rb +93 -0
  76. data/spec/Classes/CARepeat_spec.rb +65 -0
  77. data/spec/Classes/CASelect_spec.rb +22 -0
  78. data/spec/Classes/CAShift_spec.rb +16 -0
  79. data/spec/Classes/CAStruct_spec.rb +71 -0
  80. data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
  81. data/spec/Classes/CAUnboudRepeat_spec.rb +78 -0
  82. data/spec/Classes/CAWindow_spec.rb +54 -0
  83. data/spec/Classes/CAWrap_spec.rb +8 -0
  84. data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
  85. data/spec/Classes/CScalar_spec.rb +55 -0
  86. data/spec/Features/feature_130_spec.rb +19 -0
  87. data/spec/Features/feature_attributes_spec.rb +280 -0
  88. data/spec/Features/feature_boolean_spec.rb +97 -0
  89. data/spec/Features/feature_broadcast.rb +100 -0
  90. data/spec/Features/feature_cast_function.rb +19 -0
  91. data/spec/Features/feature_cast_spec.rb +33 -0
  92. data/spec/Features/feature_class_spec.rb +84 -0
  93. data/spec/Features/feature_complex_spec.rb +42 -0
  94. data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
  95. data/spec/Features/feature_convert_spec.rb +46 -0
  96. data/spec/Features/feature_copy_spec.rb +123 -0
  97. data/spec/Features/feature_creation_spec.rb +84 -0
  98. data/spec/Features/feature_element_spec.rb +144 -0
  99. data/spec/Features/feature_extream_spec.rb +54 -0
  100. data/spec/Features/feature_generate_spec.rb +74 -0
  101. data/spec/Features/feature_index_spec.rb +69 -0
  102. data/spec/Features/feature_mask_spec.rb +574 -0
  103. data/spec/Features/feature_math_spec.rb +97 -0
  104. data/spec/Features/feature_order_spec.rb +146 -0
  105. data/spec/Features/feature_ref_store_spec.rb +209 -0
  106. data/spec/Features/feature_serialization_spec.rb +125 -0
  107. data/spec/Features/feature_stat_spec.rb +397 -0
  108. data/spec/Features/feature_virtual_spec.rb +48 -0
  109. data/spec/Features/method_eq_spec.rb +81 -0
  110. data/spec/Features/method_is_nan_spec.rb +12 -0
  111. data/spec/Features/method_map_spec.rb +54 -0
  112. data/spec/Features/method_max_with.rb +20 -0
  113. data/spec/Features/method_min_with.rb +19 -0
  114. data/spec/Features/method_ne_spec.rb +18 -0
  115. data/spec/Features/method_project_spec.rb +188 -0
  116. data/spec/Features/method_ref_spec.rb +27 -0
  117. data/spec/Features/method_round_spec.rb +11 -0
  118. data/spec/Features/method_s_linspace_spec.rb +48 -0
  119. data/spec/Features/method_s_span_spec.rb +14 -0
  120. data/spec/Features/method_seq_spec.rb +47 -0
  121. data/spec/Features/method_sort_with.rb +43 -0
  122. data/spec/Features/method_sorted_with.rb +29 -0
  123. data/spec/Features/method_span_spec.rb +42 -0
  124. data/spec/Features/method_wrap_readonly_spec.rb +43 -0
  125. data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
  126. data/spec/spec_all.rb +0 -1
  127. data/utils/convert_test.rb +73 -0
  128. data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
  129. metadata +77 -60
  130. data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
  131. data/spec/CArray/bug/store_spec.rb +0 -27
  132. data/spec/CArray/index/repeat_spec.rb +0 -10
  133. data/spec/CArray/method/eq_spec.rb +0 -80
  134. data/spec/CArray/method/is_nan_spec.rb +0 -12
  135. data/spec/CArray/method/ne_spec.rb +0 -18
  136. data/spec/CArray/method/round_spec.rb +0 -11
  137. data/spec/CArray/object/_attribute_spec.rb +0 -32
  138. data/spec/CArray/object/s_new_spec.rb +0 -31
  139. data/spec/CArray/serialize/Serialization_spec.rb +0 -89
  140. data/test/test_130.rb +0 -23
  141. data/test/test_ALL.rb +0 -49
  142. data/test/test_CABitfield.rb +0 -59
  143. data/test/test_CABlock.rb +0 -208
  144. data/test/test_CAField.rb +0 -40
  145. data/test/test_CAGrid.rb +0 -76
  146. data/test/test_CAMmap.rb +0 -11
  147. data/test/test_CARefer.rb +0 -94
  148. data/test/test_CARepeat.rb +0 -66
  149. data/test/test_CASelect.rb +0 -23
  150. data/test/test_CAShift.rb +0 -17
  151. data/test/test_CAWindow.rb +0 -55
  152. data/test/test_CAWrap.rb +0 -9
  153. data/test/test_CComplex.rb +0 -83
  154. data/test/test_CScalar.rb +0 -91
  155. data/test/test_attribute.rb +0 -281
  156. data/test/test_block_iterator.rb +0 -17
  157. data/test/test_boolean.rb +0 -99
  158. data/test/test_cast.rb +0 -33
  159. data/test/test_class.rb +0 -85
  160. data/test/test_complex.rb +0 -43
  161. data/test/test_convert.rb +0 -79
  162. data/test/test_copy.rb +0 -141
  163. data/test/test_creation.rb +0 -85
  164. data/test/test_element.rb +0 -146
  165. data/test/test_extream.rb +0 -55
  166. data/test/test_generate.rb +0 -75
  167. data/test/test_index.rb +0 -71
  168. data/test/test_mask.rb +0 -578
  169. data/test/test_math.rb +0 -98
  170. data/test/test_order.rb +0 -147
  171. data/test/test_ref_store.rb +0 -211
  172. data/test/test_stat.rb +0 -406
  173. data/test/test_struct.rb +0 -72
  174. data/test/test_virtual.rb +0 -49
@@ -58,10 +58,23 @@ class CArray
58
58
  def span! (range)
59
59
  first = range.begin.to_r
60
60
  last = range.end.to_r
61
- if range.exclude_end?
62
- seq!(first, (last-first)/elements)
61
+ if integer?
62
+ if range.exclude_end?
63
+ step = ((last-1)-first+1)/elements
64
+ else
65
+ step = (last-first+1)/elements
66
+ end
67
+ else
68
+ if range.exclude_end?
69
+ step = (last-first)/elements
70
+ else
71
+ step = (last-first)/(elements-1)
72
+ end
73
+ end
74
+ if integer? && step.denominator != 1
75
+ self[] = (first + seq * step).floor
63
76
  else
64
- seq!(first, (last-first)/(elements-1))
77
+ seq!(first, step)
65
78
  end
66
79
  return self
67
80
  end
@@ -397,7 +410,11 @@ class CArray
397
410
 
398
411
  def linspace (x1, x2, n = 100)
399
412
  data_type = self::DataType
400
- data_type ||= guess_data_type_from_values(x1, x2)
413
+ unless data_type
414
+ guess = guess_data_type_from_values(x1, x2)
415
+ guess = CA_FLOAT64 if guess == CA_INT64
416
+ data_type = guess
417
+ end
401
418
  CArray.new(data_type, [n]).span(x1..x2)
402
419
  end
403
420
 
@@ -280,6 +280,7 @@ class CAIterator
280
280
  end
281
281
 
282
282
  def sort_with (&block)
283
+ warn "CAIterator#sort_with will be obsolete"
283
284
  out = reference.template
284
285
  idx = CA.sort_addr(*yield(self))
285
286
  ca[idx].each_with_addr do |blk, i|
@@ -13,7 +13,6 @@
13
13
  class CArray
14
14
 
15
15
  # reversed
16
-
17
16
  def reversed
18
17
  return self[*([-1..0]*ndim)]
19
18
  end
@@ -42,7 +41,6 @@ class CArray
42
41
  def roll (*argv)
43
42
  return self.rolled(*argv).to_ca
44
43
  end
45
-
46
44
 
47
45
  # Returns the reference which elements are sorted by the comparison method
48
46
  # given as block
@@ -61,6 +59,16 @@ class CArray
61
59
  cmpary = convert(type, :bytes=>bytes, &block)
62
60
  return self[cmpary.sort_addr].to_ca
63
61
  end
62
+
63
+ def sorted_with (*others)
64
+ addr = sort_addr
65
+ ([self] + others).map { |x| x[addr] }
66
+ end
67
+
68
+ def sort_with (*others)
69
+ addr = sort_addr
70
+ ([self] + others).map { |x| x[addr].to_ca }
71
+ end
64
72
 
65
73
  def max_by (&block)
66
74
  if empty?
@@ -71,6 +79,15 @@ class CArray
71
79
  end
72
80
  end
73
81
 
82
+ def max_with (*others)
83
+ if empty?
84
+ return ([self] + others).map { |x| UNDEF }
85
+ else
86
+ addr = max_addr
87
+ return ([self] + others).map { |x| x[addr] }
88
+ end
89
+ end
90
+
74
91
  def min_by (&block)
75
92
  if empty?
76
93
  return UNDEF
@@ -80,6 +97,15 @@ class CArray
80
97
  end
81
98
  end
82
99
 
100
+ def min_with (*others)
101
+ if empty?
102
+ return ([self] + others).map { |x| UNDEF }
103
+ else
104
+ addr = min_addr
105
+ return ([self] + others).map { |x| x[addr] }
106
+ end
107
+ end
108
+
83
109
  def range
84
110
  return (self.min)..(self.max)
85
111
  end
@@ -0,0 +1,58 @@
1
+
2
+ require 'carray'
3
+ require "rspec-power_assert"
4
+
5
+ describe "TestCArrayCABitfield " do
6
+
7
+ example "virtual_array" do
8
+ a = CArray.int(3,3) { 1 }
9
+ b = a.bitfield(0)
10
+ r = b.parent
11
+ is_asserted_by { b.class == CABitfield }
12
+ is_asserted_by { true == b.virtual? }
13
+ is_asserted_by { a == r }
14
+ end
15
+
16
+ example "basic_features" do
17
+ # ---
18
+ a = CArray.int(3,3)
19
+ b = a.bitfield(0)
20
+ b[] = 1
21
+ is_asserted_by { a.template { 1 } == a }
22
+ is_asserted_by { b.template { 1 } == b }
23
+ b[] = 0
24
+ is_asserted_by { a.template { 0 } == a }
25
+ is_asserted_by { b.template { 0 } == b }
26
+ # ---
27
+ a = CArray.int(3,3)
28
+ b = a.bitfield(0..1)
29
+ b[] = 3
30
+ is_asserted_by { a.template { 3 } == a }
31
+ is_asserted_by { b.template { 3 } == b }
32
+
33
+ # ---
34
+ a = CArray.int(3,3)
35
+ b = a.bitfield(5..6)
36
+ b[] = 3
37
+ is_asserted_by { a.template { 3 << 5 } == a }
38
+ is_asserted_by { b.template { 3 } == b }
39
+
40
+ # ---
41
+ a = CArray.int(3,3)
42
+ b = a.bitfield(27..28)
43
+ b[] = 3
44
+ is_asserted_by { a.template { 3 << 27 } == a }
45
+ is_asserted_by { b.template { 3 } == b }
46
+ end
47
+
48
+ example "out_of_index" do
49
+ # ---
50
+ a = CArray.int8(3)
51
+ expect { a.bitfield(-1..0) }.to raise_error(IndexError)
52
+ expect { a.bitfield(0..16) }.to raise_error(IndexError)
53
+ expect { a.bitfield([nil,2]) }.to raise_error(IndexError)
54
+ expect { a.bitfield([nil,1]) }.not_to raise_error()
55
+ end
56
+
57
+
58
+ end
@@ -0,0 +1,114 @@
1
+ require "carray"
2
+ require "rspec-power_assert"
3
+
4
+ describe CABlockIterator do
5
+
6
+ describe "each method" do
7
+
8
+ before do
9
+ @original = CArray.object(4,4).seq!
10
+ @it = @original.blocks(0..1, 0..1)
11
+ end
12
+
13
+ example "should call 4-times its block" do
14
+ count = 0
15
+ @it.each do |blk|
16
+ count += 1
17
+ end
18
+ is_asserted_by { count == 4 }
19
+ end
20
+
21
+ example "should have the block parameter of 2x2 CABlock object" do
22
+ @it.each do |blk|
23
+ is_asserted_by { blk.class == CABlock }
24
+ is_asserted_by { blk.data_type == CA_OBJECT }
25
+ is_asserted_by { blk.dim == [2,2] }
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ describe "reference method []" do
32
+
33
+ before do
34
+ @original = CArray.object(4,4).seq!
35
+ @it = @original.blocks(0..1, 0..1)
36
+ end
37
+
38
+ example "should return a 2x2 CABlock object" do
39
+ blk = @it[0]
40
+ is_asserted_by { blk.class == CABlock }
41
+ is_asserted_by { blk.data_type == CA_OBJECT }
42
+ is_asserted_by { blk == CA_OBJECT([[0,1],[4,5]]) }
43
+ blk = @it[1,0]
44
+ is_asserted_by { blk.class == CABlock }
45
+ is_asserted_by { blk.data_type == CA_OBJECT }
46
+ is_asserted_by { blk == CA_OBJECT([[8,9],[12,13]]) }
47
+ end
48
+
49
+ example "should return a 2x2 CABlock object" do
50
+ is_asserted_by { @it[0] == @it.kernel_at_addr(0, @it.reference) }
51
+ is_asserted_by { @it[1,0] == @it.kernel_at_index([1,0], @it.reference) }
52
+ end
53
+
54
+ end
55
+
56
+ describe "store method []=" do
57
+
58
+ before do
59
+ @original = CArray.object(4,4).seq!
60
+ @it = @original.blocks(0..1, 0..1)
61
+ end
62
+
63
+ example "should return a 2x2 CABlock object" do
64
+ @it[0] = 1
65
+ @it[1,0] = 2
66
+ is_asserted_by { @it.reference == CA_OBJECT( [ [ 1, 1, 2, 3 ],
67
+ [ 1, 1, 6, 7 ],
68
+ [ 2, 2, 10, 11 ],
69
+ [ 2, 2, 14, 15 ] ] ) }
70
+ end
71
+
72
+ end
73
+
74
+ describe "pick method" do
75
+
76
+ before do
77
+ @original = CArray.object(4,4).seq!
78
+ @it = @original.blocks(0..1, 0..1)
79
+ end
80
+
81
+ example "should return a 2x2 CABlock object" do
82
+ blk = @it.pick(0)
83
+ is_asserted_by { blk.class == CArray }
84
+ is_asserted_by { blk.data_type == CA_OBJECT }
85
+ is_asserted_by { blk == CA_OBJECT([[0,2],[8,10]]) }
86
+ blk = @it.pick(1,0)
87
+ is_asserted_by { blk.class == CArray }
88
+ is_asserted_by { blk.data_type == CA_OBJECT }
89
+ is_asserted_by { blk == CA_OBJECT([[4,6],[12,14]]) }
90
+ end
91
+
92
+ end
93
+
94
+ describe "put method" do
95
+
96
+ before do
97
+ @original = CArray.object(4,4).seq!
98
+ @it = @original.blocks(0..1, 0..1)
99
+ end
100
+
101
+ example "should store value via 2x2 CBlock object" do
102
+ @it.put(0,1)
103
+ @it.put(0,1,2)
104
+ is_asserted_by { @it.pick(0) == CA_OBJECT([[1,1],[1,1]]) }
105
+ is_asserted_by { @it.pick(0,1) == CA_OBJECT([[2,2],[2,2]]) }
106
+ is_asserted_by { @it.reference == CA_OBJECT([[ 1, 2, 1, 2 ],
107
+ [ 4, 5, 6, 7 ],
108
+ [ 1, 2, 1, 2 ],
109
+ [ 12, 13, 14, 15 ]]) }
110
+ end
111
+
112
+ end
113
+
114
+ end
@@ -0,0 +1,205 @@
1
+
2
+ require 'carray'
3
+ require "rspec-power_assert"
4
+
5
+ describe "TestCABlock " do
6
+
7
+ example "virtual_array" do
8
+ a = CArray.int(3,3)
9
+ b = a[0..1,0..1]
10
+ r = b.parent
11
+ t = b.root_array
12
+ is_asserted_by { b.class == CABlock }
13
+ is_asserted_by { r.class == CArray }
14
+ is_asserted_by { a == r }
15
+ is_asserted_by { a == t }
16
+ end
17
+
18
+ example "block" do
19
+ a = CArray.int32(3, 3) { 1 }
20
+ b = CArray.int32(3) { 1 }
21
+
22
+ is_asserted_by { a[nil, 1] == b }
23
+ is_asserted_by { a[1, nil] == b }
24
+
25
+ a[nil, 1].seq!
26
+ b.seq!
27
+ is_asserted_by { a[nil, 1] == b }
28
+
29
+ a[1, nil].seq!
30
+ b.seq!
31
+ is_asserted_by { a[1, nil] == b }
32
+ end
33
+
34
+ example "CABlock" do
35
+ a = CArray.int32(4, 4)
36
+
37
+ a.seq!
38
+ b = a[1..2, 1..2]
39
+
40
+ is_asserted_by { b.class == CABlock }
41
+ is_asserted_by { b.rank == a.rank }
42
+ is_asserted_by { b.dim == [2, 2] }
43
+ is_asserted_by { b.elements == 4 }
44
+
45
+ c = CArray.int32(2, 2){ [[5,6],[9,10]] }
46
+ is_asserted_by { b == c }
47
+
48
+ d = a.clone
49
+ d[1..2, 1..2] = 1
50
+ b[] = 1
51
+ is_asserted_by { a == d }
52
+
53
+ a.seq!
54
+ is_asserted_by { b == c }
55
+ end
56
+
57
+
58
+ example "s_new" do
59
+ a = CArray.int32(4, 4) { 1 }
60
+ b = a[0..2, 0..2]
61
+ is_asserted_by { b.data_type == CA_INT32 }
62
+ is_asserted_by { b.rank == 2 }
63
+ is_asserted_by { b.bytes == CArray.sizeof(CA_INT32) }
64
+ is_asserted_by { b.size0 == [4, 4] }
65
+ is_asserted_by { b.dim == [3, 3] }
66
+ is_asserted_by { b.start == [0, 0] }
67
+ is_asserted_by { b.step == [1, 1] }
68
+ is_asserted_by { b.count == [3, 3] }
69
+ is_asserted_by { b.elements == 9 }
70
+ is_asserted_by { b == CArray.int32(3, 3) { 1 } }
71
+ end
72
+
73
+ example "block_of_block" do
74
+ a = CArray.new(CA_INT32, [4, 4]).seq!
75
+ b = a[0..2, 0..2]
76
+ c = b[0..1, 0..1]
77
+
78
+ is_asserted_by { b == CArray.int32(3, 3) {
79
+ [
80
+ [0, 1, 2],
81
+ [4, 5, 6],
82
+ [8, 9, 10],
83
+ ]
84
+ } }
85
+
86
+ is_asserted_by { c == CArray.int32(2, 2) {
87
+ [
88
+ [0, 1],
89
+ [4, 5],
90
+ ]
91
+ } }
92
+ end
93
+
94
+ example "block_of_block_set_value" do
95
+ a = CArray.new(CA_INT32, [4, 4]).seq!
96
+ b = a[0..2, 0..2]
97
+ c = b[0..1, 0..1]
98
+
99
+ a[0..1, 0..1] = 1
100
+
101
+ is_asserted_by { b == CArray.int32(3, 3) {
102
+ [
103
+ [1, 1, 2],
104
+ [1, 1, 6],
105
+ [8, 9, 10],
106
+ ]
107
+ } }
108
+
109
+ is_asserted_by { c == CArray.int32(2, 2) {
110
+ [
111
+ [1, 1],
112
+ [1, 1],
113
+ ]
114
+ } }
115
+
116
+ c[] = 2
117
+
118
+ is_asserted_by { b == CArray.int32(3, 3) {
119
+ [
120
+ [2, 2, 2],
121
+ [2, 2, 6],
122
+ [8, 9, 10],
123
+ ]
124
+ } }
125
+
126
+ is_asserted_by { a[0..1, 0..1] == CArray.int32(2, 2) {
127
+ [
128
+ [2, 2],
129
+ [2, 2],
130
+ ]
131
+ } }
132
+ end
133
+
134
+ example "block_of_block_downrank" do
135
+ a = CArray.new(CA_INT32, [4, 4, 4]) { 0 }
136
+ b = a[0..2, 0..2, 1]
137
+ c = b[0..1, 1]
138
+
139
+ b.seq!
140
+
141
+ is_asserted_by { b == a[0..2, 0..2, 1] }
142
+ is_asserted_by { c == CArray.int32(2) { [1, 4] } }
143
+
144
+ c[] = 1
145
+
146
+ is_asserted_by { a[0..1, 1, 1] == CArray.int(2) { 1 } }
147
+ end
148
+
149
+ example "block_of_block_ref_address" do
150
+ a = CArray.new(CA_INT32, [4, 4]).seq!
151
+ b = a[0..2, 0..2]
152
+ c = b[1..0, 0..1]
153
+
154
+ is_asserted_by { c[2] == 0 }
155
+ is_asserted_by { c[[2]] == CArray.int32(1) { [0] } }
156
+ is_asserted_by { c[nil] == CArray.int32(4) { [4, 5, 0, 1] } }
157
+ is_asserted_by { c[1..2] == CArray.int32(2) { [5, 0] } }
158
+ is_asserted_by { c[[nil, 2]] == CArray.int32(2) { [4, 0] } }
159
+ is_asserted_by { c[[(1..-1), 2]] == CArray.int32(2) { [5, 1] } }
160
+
161
+ c[nil] = 1
162
+ is_asserted_by { a[0..1, 0..1] == CArray.int32(2, 2) { 1 } }
163
+ end
164
+
165
+ example "refer_of_block" do
166
+ a = CArray.new(CA_INT32, [4, 4]).seq!
167
+ b = a[nil, 0..2]
168
+ c = b.reshape(2, 6)
169
+ # is_asserted_by { b.to_a.flatten, c.to_a.flatten)
170
+
171
+ c[0, 0] = 3
172
+ is_asserted_by { b[0, 0] == 3 }
173
+ is_asserted_by { a[0, 0] == 3 }
174
+ end
175
+
176
+ example "refer_of_block_cast" do
177
+ a = CArray.new(CA_INT32, [4, 4]).seq!
178
+ b = a[nil, 0..2]
179
+ c = b.reshape(2, 6)
180
+ is_asserted_by { c.float32[0, 1] == 1.0 }
181
+ is_asserted_by { c.float64[0, 1] == 1.0 }
182
+ end
183
+
184
+ example "block_of_block_self_asign" do
185
+ a = CArray.new(CA_INT32, [4, 4]).seq!
186
+ b = a[0..2, 0..2]
187
+ b[0..1, 0..1] = a[0..1, 0..1]
188
+ end
189
+
190
+ example "block_move" do
191
+ a = CArray.int(10, 10).seq!
192
+ b = a[0..2, 0..2]
193
+
194
+ is_asserted_by { b == CArray.int(3, 3) { [[0, 1, 2], [10, 11, 12], [20, 21, 22]] } }
195
+
196
+ b.move(1,1)
197
+ is_asserted_by { b == CArray.int(3, 3) { [[11, 12, 13], [21, 22, 23], [31, 32, 33]] } }
198
+
199
+ b.move(7,7)
200
+ is_asserted_by { b == CArray.int(3, 3) { [[77, 78, 79], [87, 88, 89], [97, 98, 99]] } }
201
+
202
+ expect { b.move(8,8) }.to raise_error(ArgumentError)
203
+ end
204
+
205
+ end