multiarray 0.22.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/Rakefile +1 -1
  2. data/lib/multiarray.rb +53 -16
  3. data/lib/multiarray/bool.rb +1 -1
  4. data/lib/multiarray/complex.rb +76 -68
  5. data/lib/multiarray/components.rb +11 -10
  6. data/lib/multiarray/composite.rb +1 -1
  7. data/lib/multiarray/diagonal.rb +11 -12
  8. data/lib/multiarray/element.rb +3 -3
  9. data/lib/multiarray/elementwise.rb +14 -14
  10. data/lib/multiarray/field.rb +380 -0
  11. data/lib/multiarray/float.rb +10 -10
  12. data/lib/multiarray/gcccache.rb +1 -1
  13. data/lib/multiarray/gcccontext.rb +35 -54
  14. data/lib/multiarray/gccfunction.rb +12 -19
  15. data/lib/multiarray/gcctype.rb +1 -1
  16. data/lib/multiarray/gccvalue.rb +63 -43
  17. data/lib/multiarray/histogram.rb +17 -19
  18. data/lib/multiarray/index.rb +7 -8
  19. data/lib/multiarray/inject.rb +11 -12
  20. data/lib/multiarray/int.rb +12 -11
  21. data/lib/multiarray/integral.rb +11 -12
  22. data/lib/multiarray/lambda.rb +23 -18
  23. data/lib/multiarray/list.rb +1 -1
  24. data/lib/multiarray/lookup.rb +18 -13
  25. data/lib/multiarray/lut.rb +13 -16
  26. data/lib/multiarray/malloc.rb +1 -1
  27. data/lib/multiarray/mask.rb +11 -8
  28. data/lib/multiarray/methods.rb +10 -10
  29. data/lib/multiarray/multiarray.rb +15 -44
  30. data/lib/multiarray/node.rb +64 -138
  31. data/lib/multiarray/object.rb +2 -6
  32. data/lib/multiarray/operations.rb +116 -134
  33. data/lib/multiarray/pointer.rb +7 -19
  34. data/lib/multiarray/random.rb +11 -8
  35. data/lib/multiarray/rgb.rb +53 -53
  36. data/lib/multiarray/sequence.rb +11 -496
  37. data/lib/multiarray/shortcuts.rb +4 -4
  38. data/lib/multiarray/store.rb +14 -11
  39. data/lib/multiarray/unmask.rb +10 -7
  40. data/lib/multiarray/variable.rb +11 -3
  41. data/test/tc_bool.rb +0 -8
  42. data/test/tc_compile.rb +72 -0
  43. data/test/tc_float.rb +0 -8
  44. data/test/tc_int.rb +0 -8
  45. data/test/tc_lazy.rb +22 -3
  46. data/test/tc_multiarray.rb +100 -126
  47. data/test/tc_object.rb +0 -16
  48. data/test/tc_rgb.rb +0 -16
  49. data/test/tc_sequence.rb +151 -165
  50. data/test/ts_multiarray.rb +2 -0
  51. metadata +7 -4
@@ -1,5 +1,5 @@
1
1
  # multiarray - Lazy multi-dimensional arrays for Ruby
2
- # Copyright (C) 2010 Jan Wedekind
2
+ # Copyright (C) 2010, 2011 Jan Wedekind
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@ module Hornetseye
28
28
  #
29
29
  # @private
30
30
  def constructor_shortcut( target )
31
- define_method( target.to_s.downcase ) do |*args|
31
+ define_method target.to_s.downcase do |*args|
32
32
  new target, *args
33
33
  end
34
34
  end
@@ -77,7 +77,7 @@ module Hornetseye
77
77
  #
78
78
  # @private
79
79
  def to_type_shortcut( target )
80
- define_method( "to_#{target.to_s.downcase}" ) do
80
+ define_method "to_#{target.to_s.downcase}" do
81
81
  to_type target
82
82
  end
83
83
  end
@@ -124,7 +124,7 @@ module Hornetseye
124
124
  #
125
125
  # @private
126
126
  def read_shortcut( target )
127
- define_method( "read_#{target.to_s.downcase}" ) do
127
+ define_method "read_#{target.to_s.downcase}" do
128
128
  read.to_type target
129
129
  end
130
130
  end
@@ -1,5 +1,5 @@
1
1
  # multiarray - Lazy multi-dimensional arrays for Ruby
2
- # Copyright (C) 2010 Jan Wedekind
2
+ # Copyright (C) 2010, 2011 Jan Wedekind
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
@@ -29,6 +29,10 @@ module Hornetseye
29
29
  @dest, @source = dest, source
30
30
  end
31
31
 
32
+ def sexp?
33
+ true
34
+ end
35
+
32
36
  # Get unique descriptor of this object
33
37
  #
34
38
  # @param [Hash] hash Labels for any variables.
@@ -40,13 +44,12 @@ module Hornetseye
40
44
  "Store(#{@dest.descriptor( hash )},#{@source.descriptor( hash )})"
41
45
  end
42
46
 
43
- # Get type of result of delayed operation
44
- #
45
- # @return [Class] Type of result.
46
- #
47
- # @private
48
- def array_type
49
- @dest.array_type
47
+ def typecode
48
+ @dest.typecode
49
+ end
50
+
51
+ def shape
52
+ @dest.shape
50
53
  end
51
54
 
52
55
  # Reevaluate computation
@@ -60,10 +63,10 @@ module Hornetseye
60
63
  if variables.empty?
61
64
  if dimension > 0
62
65
  shape.last.times do |i|
63
- dest = @dest.element INT.new( i )
66
+ dest = @dest.element INT.new(i)
64
67
  source = @source.dimension == 0 ? @source :
65
- @source.element( INT.new( i ) )
66
- Store.new( dest, source ).demand
68
+ @source.element(INT.new(i))
69
+ Store.new(dest, source).demand
67
70
  end
68
71
  elsif @dest.class < Pointer_
69
72
  @dest.store @source.demand
@@ -45,6 +45,10 @@ module Hornetseye
45
45
  @dest, @source, @m, @index, @default = dest, source, m, index, default
46
46
  end
47
47
 
48
+ def sexp?
49
+ true
50
+ end
51
+
48
52
  # Get unique descriptor of this object
49
53
  #
50
54
  # @param [Hash] hash Labels for any variables.
@@ -58,13 +62,12 @@ module Hornetseye
58
62
  "#{@default.descriptor( hash )})"
59
63
  end
60
64
 
61
- # Get type of result of delayed operation
62
- #
63
- # @return [Class] Type of result.
64
- #
65
- # @private
66
- def array_type
67
- @dest.array_type
65
+ def typecode
66
+ @dest.typecode
67
+ end
68
+
69
+ def shape
70
+ @dest.shape
68
71
  end
69
72
 
70
73
  # Perform masking operation
@@ -1,5 +1,5 @@
1
1
  # multiarray - Lazy multi-dimensional arrays for Ruby
2
- # Copyright (C) 2010 Jan Wedekind
2
+ # Copyright (C) 2010, 2011 Jan Wedekind
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
@@ -38,6 +38,10 @@ module Hornetseye
38
38
  @meta = meta
39
39
  end
40
40
 
41
+ def sexp?
42
+ true
43
+ end
44
+
41
45
  # Display string with information about this object
42
46
  #
43
47
  # @return [String] String with information about this object (e.g.
@@ -90,8 +94,12 @@ module Hornetseye
90
94
  # @return [Class] Type of result.
91
95
  #
92
96
  # @private
93
- def array_type
94
- @meta.array_type
97
+ def typecode
98
+ @meta.typecode
99
+ end
100
+
101
+ def shape
102
+ @meta.shape
95
103
  end
96
104
 
97
105
  # Strip of all values
data/test/tc_bool.rb CHANGED
@@ -55,14 +55,6 @@ class TC_Bool < Test::Unit::TestCase
55
55
  assert_equal 0, B.dimension
56
56
  end
57
57
 
58
- def test_bool_shape
59
- assert_equal [], B.shape
60
- end
61
-
62
- def test_bool_size
63
- assert_equal 1, B.size
64
- end
65
-
66
58
  def test_inspect
67
59
  assert_equal 'BOOL(true)', B( true ).inspect
68
60
  end
@@ -0,0 +1,72 @@
1
+ # multiarray - Lazy multi-dimensional arrays for Ruby
2
+ # Copyright (C) 2010 Jan Wedekind
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'test/unit'
18
+ begin
19
+ require 'rubygems'
20
+ rescue LoadError
21
+ end
22
+ Kernel::require 'multiarray'
23
+
24
+ class TC_Compile < Test::Unit::TestCase
25
+
26
+ B = Hornetseye::BYTE
27
+ W = Hornetseye::SINT
28
+ S = Hornetseye::Sequence
29
+ M = Hornetseye::MultiArray
30
+
31
+ def S( *args )
32
+ Hornetseye::Sequence *args
33
+ end
34
+
35
+ def M( *args )
36
+ Hornetseye::MultiArray *args
37
+ end
38
+
39
+ def lazy( *args, &action )
40
+ Hornetseye::lazy *args, &action
41
+ end
42
+
43
+ def finalise( *args, &action )
44
+ Hornetseye::finalise *args, &action
45
+ end
46
+
47
+ def sum( *args, &action )
48
+ Hornetseye::sum *args, &action
49
+ end
50
+
51
+ def setup
52
+ end
53
+
54
+ def teardown
55
+ end
56
+
57
+ def test_unary
58
+ assert_equal S(W)[-1, -2, -3], -S(W)[1, 2, 3]
59
+ assert_equal S(W)[-1, -2, -3], -S(W)[1, 2, 3]
60
+ assert !lazy { -S(W)[1, 2, 3] }.finalised?
61
+ end
62
+
63
+ def test_binary
64
+ assert_equal S(W)[2, 3, 4], S(W)[1, 2, 3] + 1
65
+ assert_equal S(W)[2, 3, 4], S(W)[1, 2, 3] + 1
66
+ assert !lazy { S(W)[1, 2, 3] + 1 }.finalised?
67
+ assert_equal S(W)[257, 258, 259], S(W)[1, 2, 3] + 256
68
+ assert_equal S(W)[2, 4, 6], S(W)[1, 2, 3] + S(W)[1, 2, 3]
69
+ end
70
+
71
+ end
72
+
data/test/tc_float.rb CHANGED
@@ -73,14 +73,6 @@ class TC_Float < Test::Unit::TestCase
73
73
  def test_float_dimension
74
74
  assert_equal 0, F.dimension
75
75
  end
76
- !
77
- def test_float_shape
78
- assert_equal [], F.shape
79
- end
80
-
81
- def test_float_size
82
- assert_equal 1, F.size
83
- end
84
76
 
85
77
  def test_inspect
86
78
  assert_equal 'DFLOAT(42.0)', D( 42.0 ).inspect
data/test/tc_int.rb CHANGED
@@ -88,14 +88,6 @@ class TC_Int < Test::Unit::TestCase
88
88
  def test_int_dimension
89
89
  assert_equal 0, I.dimension
90
90
  end
91
- !
92
- def test_int_shape
93
- assert_equal [], I.shape
94
- end
95
-
96
- def test_int_size
97
- assert_equal 1, I.size
98
- end
99
91
 
100
92
  def test_inspect
101
93
  assert_equal 'INT(42)', I( 42 ).inspect
data/test/tc_lazy.rb CHANGED
@@ -37,6 +37,14 @@ class TC_Lazy < Test::Unit::TestCase
37
37
  Hornetseye::MultiArray *args
38
38
  end
39
39
 
40
+ def C( *args )
41
+ Hornetseye::RGB *args
42
+ end
43
+
44
+ def X( *args )
45
+ Complex *args
46
+ end
47
+
40
48
  def lazy( *args, &action )
41
49
  Hornetseye::lazy *args, &action
42
50
  end
@@ -115,12 +123,23 @@ class TC_Lazy < Test::Unit::TestCase
115
123
 
116
124
  def test_indgen_diagonal
117
125
  assert_equal [ 15, 18, 17 ],
118
- M( I, 4, 3 ).indgen.diagonal { |a,b| a + b }.to_a
126
+ M(I, 2).indgen(4, 3).diagonal { |a,b| a + b }.to_a
119
127
  end
120
128
 
121
129
  def test_lut
122
- assert_equal S( I, 4 )[ 4, 2, 3, 2 ],
123
- finalise { S( I, 4 )[ 0, 2, 1, 2 ].lut( S( I, 3 )[ 3, 2, 1 ] ) + 1 }
130
+ assert_equal S( I )[ 4, 2, 3, 2 ],
131
+ finalise { S( I )[ 0, 2, 1, 2 ].lut( S( I )[ 3, 2, 1 ] ) + 1 }
132
+ end
133
+
134
+ def test_complex
135
+ assert_equal [1, 1], lazy(2) { X 1, 2 }.real.to_a
136
+ assert_equal [2, 2], lazy(2) { X 1, 2 }.imag.to_a
137
+ end
138
+
139
+ def test_rgb
140
+ assert_equal [1, 1], lazy(2) { C 1, 2, 3 }.r.to_a
141
+ assert_equal [2, 2], lazy(2) { C 1, 2, 3 }.g.to_a
142
+ assert_equal [3, 3], lazy(2) { C 1, 2, 3 }.b.to_a
124
143
  end
125
144
 
126
145
  end
@@ -63,69 +63,43 @@ class TC_MultiArray < Test::Unit::TestCase
63
63
  end
64
64
 
65
65
  def test_multiarray_inspect
66
- assert_equal 'MultiArray(OBJECT,3,2)', M( O, 3, 2 ).inspect
67
- assert_equal 'MultiArray(OBJECT,3,2)', S( S( O, 3 ), 2 ).inspect
66
+ assert_equal 'MultiArray(OBJECT,2)', M(O,2).inspect
67
+ assert_equal 'MultiArray(OBJECT,2)', S(S(O)).inspect
68
68
  end
69
69
 
70
70
  def test_multiarray_to_s
71
- assert_equal 'MultiArray(OBJECT,3,2)', M( O, 3, 2 ).to_s
72
- assert_equal 'MultiArray(OBJECT,3,2)', S( S( O, 3 ), 2 ).to_s
73
- end
74
-
75
- def test_multiarray_default
76
- assert_equal [ [ nil ] * 3 ] * 2, M( O, 3, 2 ).default.to_a
77
- assert_equal [ [ 0 ] * 3 ] * 2, M( I, 3, 2 ).default.to_a
78
- assert_equal [ [ C( 0, 0, 0 ) ] * 3 ] * 2, M( C, 3, 2 ).default.to_a
71
+ assert_equal 'MultiArray(OBJECT,2)', M(O,2).to_s
72
+ assert_equal 'MultiArray(OBJECT,2)', S(S(O)).to_s
79
73
  end
80
74
 
81
75
  def test_multiarray_at
82
76
  assert_equal [ [ 1, 2, 3 ], [ 4, 5, 6 ] ],
83
77
  M[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].to_a
84
78
  assert_equal [ [ 1, 2, 3 ], [ 4, 5, 6 ] ],
85
- M( O, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].to_a
79
+ M(O, 2)[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].to_a
86
80
  assert_equal O, M[ [ :a ] ].typecode
87
81
  assert_equal B, M[ [ false ], [ true ] ].typecode
88
82
  assert_equal I, M[ [ -2 ** 31, 2 ** 31 - 1 ] ].typecode
89
83
  end
90
84
 
91
85
  def test_multiarray_indgen
92
- assert_equal M( I, 3, 2 )[ [ 0, 1, 2 ], [ 3, 4, 5 ] ],
93
- M( I, 3, 2 ).indgen
94
- assert_equal M( I, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ],
95
- M( I, 3, 2 ).indgen( 1 )
96
- assert_equal M( I, 3, 2 )[ [ 0, 2, 4 ], [ 6, 8, 10 ] ],
97
- M( I, 3, 2 ).indgen( 0, 2 )
98
- assert_equal M( I, 3, 2 )[ [ 1, 3, 5 ], [ 7, 9, 11 ] ],
99
- M( I, 3, 2 ).indgen( 1, 2 )
100
- assert_equal M( C, 2, 2 )[ [ C( 1, 2, 3 ), C( 2, 2, 2 ) ],
101
- [ C( 3, 2, 1 ), C( 4, 2, 0 ) ] ],
102
- M( C, 2, 2 ).indgen( C( 1, 2, 3 ), C( 1, 0, -1 ) )
103
- end
104
-
105
- def test_multiarray_typecode
106
- assert_equal O, M( O, 3, 2 ).typecode
107
- assert_equal I, M( I, 3, 2 ).typecode
108
- assert_equal C, M( C, 3, 2 ).typecode
109
- end
110
-
111
- def test_multiarray_dimension
112
- assert_equal 2, M( O, 3, 2 ).dimension
113
- end
114
-
115
- def test_multiarray_shape
116
- assert_equal [ 3, 2 ], M( O, 3, 2 ).shape
117
- end
118
-
119
- def test_multiarray_size
120
- assert_equal 6, M( O, 3, 2 ).size
121
- assert_equal 6, M( I, 3, 2 ).size
122
- assert_equal 6, M( C, 3, 2 ).size
86
+ assert_equal M(I, 2)[ [ 0, 1, 2 ], [ 3, 4, 5 ] ],
87
+ M(I, 2).indgen(3, 2)
88
+ assert_equal M(I, 2)[ [ 1, 2, 3 ], [ 4, 5, 6 ] ],
89
+ M(I, 2).indgen(3, 2, 1)
90
+ assert_equal M(I, 2)[ [ 0, 2, 4 ], [ 6, 8, 10 ] ],
91
+ M(I, 2).indgen(3, 2, 0, 2)
92
+ assert_equal M(I, 2)[ [ 1, 3, 5 ], [ 7, 9, 11 ] ],
93
+ M(I, 2).indgen(3, 2, 1, 2)
94
+ assert_equal M(C, 2)[ [ C( 1, 2, 3 ), C( 2, 2, 2 ) ],
95
+ [ C( 3, 2, 1 ), C( 4, 2, 0 ) ] ],
96
+ M(C, 2).indgen(2, 2, C( 1, 2, 3 ), C( 1, 0, -1 ))
123
97
  end
124
98
 
125
99
  def test_inspect
126
- assert_equal "MultiArray(OBJECT,3,2):\n[ [ :a, 2, 3 ],\n [ 4, 5, 6 ] ]",
100
+ assert_equal "MultiArray(OBJECT,2):\n[ [ :a, 2, 3 ],\n [ 4, 5, 6 ] ]",
127
101
  M[ [ :a, 2, 3 ], [ 4, 5, 6 ] ].inspect
128
- assert_equal "MultiArray(UBYTE,4,3,2):\n" +
102
+ assert_equal "MultiArray(UBYTE,3):\n" +
129
103
  "[ [ [ 0, 1, 2, 3 ],\n" +
130
104
  " [ 4, 5, 6, 7 ],\n" +
131
105
  " [ 8, 9, 10, 11 ] ],\n" +
@@ -148,23 +122,23 @@ class TC_MultiArray < Test::Unit::TestCase
148
122
  end
149
123
 
150
124
  def test_typecode
151
- assert_equal O, M( O, 3, 2 ).new.typecode
152
- assert_equal I, M( I, 3, 2 ).new.typecode
153
- assert_equal C, M( C, 3, 2 ).new.typecode
125
+ assert_equal O, M(O, 2).new(3, 2).typecode
126
+ assert_equal I, M(I, 2).new(3, 2).typecode
127
+ assert_equal C, M(C, 2).new(3, 2).typecode
154
128
  end
155
129
 
156
130
  def test_dimension
157
- assert_equal 2, M( O, 3, 2 ).new.dimension
158
- assert_equal 2, M( I, 3, 2 ).new.dimension
159
- assert_equal 2, M( C, 3, 2 ).new.dimension
131
+ assert_equal 2, M(O, 2).new(3, 2).dimension
132
+ assert_equal 2, M(I, 2).new(3, 2).dimension
133
+ assert_equal 2, M(C, 2).new(3, 2).dimension
160
134
  end
161
135
 
162
136
  def test_shape
163
- assert_equal [ 3, 2 ], M( O, 3, 2 ).new.shape
137
+ assert_equal [ 3, 2 ], M(O, 2).new(3, 2).shape
164
138
  end
165
139
 
166
140
  def test_size
167
- assert_equal 6, M( O, 3, 2 ).new.size
141
+ assert_equal 6, M(O, 2).new(3, 2).size
168
142
  end
169
143
 
170
144
  def test_import
@@ -177,8 +151,8 @@ class TC_MultiArray < Test::Unit::TestCase
177
151
  end
178
152
 
179
153
  def test_at_assign
180
- [ M( O, 3, 2 ), M( I, 3, 2 ) ].each do |t|
181
- m = t.new
154
+ [ M(O, 2), M(I, 2) ].each do |t|
155
+ m = t.new 3, 2
182
156
  for j in 0 ... 2
183
157
  for i in 0 ... 3
184
158
  assert_equal j * 3 + i + 1, m[ j ][ i ] = j * 3 + i + 1
@@ -216,8 +190,8 @@ class TC_MultiArray < Test::Unit::TestCase
216
190
  end
217
191
 
218
192
  def test_slice
219
- [ M( O, 5, 4 ), M( I, 5, 4 ) ].each do |t|
220
- m = t.indgen[]
193
+ [ M(O, 2), M(I, 2) ].each do |t|
194
+ m = t.indgen(5, 4)[]
221
195
  assert_equal [ [ 5, 10 ], [ 6, 11 ], [ 7, 12 ], [ 8, 13 ], [ 9, 14 ] ],
222
196
  m[ 1 .. 2 ].to_a
223
197
  assert_equal [ [ 6, 7, 8 ], [ 11, 12, 13 ] ],
@@ -305,27 +279,27 @@ class TC_MultiArray < Test::Unit::TestCase
305
279
  end
306
280
  end
307
281
 
308
- def test_view
309
- [ M( O, 3, 2 ), M( I, 3, 2 ) ].each do |t|
310
- m = t[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
311
- v = m[ 1, 0 ... 2 ]
282
+ def test_view
283
+ [ M(O, 2), M(I, 2) ].each do |t|
284
+ m = t[[1, 2, 3], [4, 5, 6]]
285
+ v = m[1, 0 ... 2]
312
286
  v[] = 0
313
- assert_equal [ [ 1, 0, 3 ], [ 4, 0, 6 ] ], m.to_a
287
+ assert_equal [[1, 0, 3], [4, 0, 6]], m.to_a
314
288
  end
315
289
  end
316
290
 
317
291
  def test_transpose
318
292
  assert_equal [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ],
319
- M[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].transpose( 1, 0 ).to_a
293
+ M[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].transpose(1, 0).to_a
320
294
  assert_equal [ [ [ 0, 3 ], [ 1, 4 ], [ 2, 5 ] ] ],
321
- M( I, 3, 2, 1 ).indgen.transpose( 1, 0, 2 ).to_a
322
- end
295
+ M(I, 3).indgen(3, 2, 1).transpose(1, 0, 2).to_a
296
+ end
323
297
 
324
298
  def test_roll_unroll
325
299
  assert_equal [ [ [ 0 ], [ 1 ], [ 2 ] ], [ [ 3 ], [ 4 ], [ 5 ] ] ],
326
- M( I, 3, 2, 1 ).indgen.unroll.to_a
300
+ M(I, 3).indgen(3, 2, 1).unroll.to_a
327
301
  assert_equal [ [ [ 0, 3 ] ], [ [ 1, 4 ] ], [ [ 2, 5 ] ] ],
328
- M( I, 3, 2, 1 ).indgen.roll.to_a
302
+ M(I, 3).indgen(3, 2, 1).roll.to_a
329
303
  end
330
304
 
331
305
  def test_equal
@@ -361,8 +335,8 @@ class TC_MultiArray < Test::Unit::TestCase
361
335
  end
362
336
 
363
337
  def test_inject
364
- assert_equal 21, M[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].inject { |a,b| a + b }
365
- assert_equal 28, M[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].inject( 7 ) { |a,b| a + b }
338
+ assert_equal 21, M[[1, 2, 3], [4, 5, 6]].inject { |a,b| a + b }
339
+ assert_equal 28, M[[1, 2, 3], [4, 5, 6]].inject(7) { |a,b| a + b }
366
340
  end
367
341
 
368
342
  def test_collect
@@ -415,12 +389,12 @@ class TC_MultiArray < Test::Unit::TestCase
415
389
  [ 'b1', 'b2', 'b3' ],
416
390
  [ 'c1', 'c2', 'c3' ],
417
391
  [ 'd1', 'd2', 'd3' ] ].diagonal( 'x' ) { |a,b| a + b }
418
- assert_equal S( I, 4 )[ 4, 12, 21, 18 ],
419
- M( I, 3, 4 ).indgen.diagonal { |a,b| a + b }
420
- assert_equal S( I, 3 )[ 4, 12, 12 ],
421
- M( I, 3, 3 ).indgen.diagonal { |a,b| a + b }
422
- assert_equal S( I, 2 )[ 4, 6 ],
423
- M( I, 3, 2 ).indgen.diagonal { |a,b| a + b }
392
+ assert_equal S(I)[ 4, 12, 21, 18 ],
393
+ M(I, 2).indgen(3, 4).diagonal { |a,b| a + b }
394
+ assert_equal S(I)[ 4, 12, 12 ],
395
+ M(I, 2).indgen(3, 3).diagonal { |a,b| a + b }
396
+ assert_equal S(I)[ 4, 6 ],
397
+ M(I, 2).indgen(3, 2).diagonal { |a,b| a + b }
424
398
  end
425
399
 
426
400
  def test_convolve
@@ -506,41 +480,41 @@ class TC_MultiArray < Test::Unit::TestCase
506
480
  end
507
481
 
508
482
  def test_warp
509
- [ O, I ].each do |t1|
510
- [ O, I ].each do |t2|
483
+ [O, I].each do |t1|
484
+ [O, I].each do |t2|
511
485
  z = t1.default
512
- assert_equal M( t1, 3, 3 )[ [ 1, 2, z ], [ 3, 4, z ], [ z, z, z ] ],
513
- M( t1, 2, 2 )[ [ 1, 2 ], [ 3, 4 ] ].
514
- warp( M( t2, 3, 3 )[ [ 0, 1, 2 ], [ 0, 1, 2 ], [ 0, 1, 2 ] ],
515
- M( t2, 3, 3 )[ [ 0, 0, 0 ], [ 1, 1, 1 ], [ 2, 2, 2 ] ] )
486
+ assert_equal M(t1, 2)[ [ 1, 2, z ], [ 3, 4, z ], [ z, z, z ] ],
487
+ M(t1, 2)[ [ 1, 2 ], [ 3, 4 ] ].
488
+ warp( M(t2, 2)[ [ 0, 1, 2 ], [ 0, 1, 2 ], [ 0, 1, 2 ] ],
489
+ M(t2, 2)[ [ 0, 0, 0 ], [ 1, 1, 1 ], [ 2, 2, 2 ] ] )
516
490
  end
517
491
  end
518
492
  end
519
493
 
520
494
  def test_flip
521
495
  [ O, I ].each do |t|
522
- assert_equal M( t, 3, 2 )[ [ 3, 2, 1 ], [ 6, 5, 4 ] ],
523
- M( t, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].flip( 0 )
524
- assert_equal M( t, 3, 2 )[ [ 4, 5, 6 ], [ 1, 2, 3 ] ],
525
- M( t, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].flip( 1 )
526
- assert_equal M( t, 3, 2 )[ [ 6, 5, 4 ], [ 3, 2, 1 ] ],
527
- M( t, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].flip( 0, 1 )
496
+ assert_equal M(t, 2)[ [ 3, 2, 1 ], [ 6, 5, 4 ] ],
497
+ M(t, 2)[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].flip( 0 )
498
+ assert_equal M(t, 2)[ [ 4, 5, 6 ], [ 1, 2, 3 ] ],
499
+ M(t, 2)[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].flip( 1 )
500
+ assert_equal M(t, 2)[ [ 6, 5, 4 ], [ 3, 2, 1 ] ],
501
+ M(t, 2)[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].flip( 0, 1 )
528
502
  end
529
503
  end
530
504
 
531
505
  def test_shift
532
506
  [ O, I ].each do |t|
533
- assert_equal M( t, 2, 2 )[ [ 4, 3 ], [ 2, 1 ] ],
534
- M( t, 2, 2 )[ [ 1, 2 ], [ 3, 4 ] ].shift( 1, 1 )
507
+ assert_equal M(t, 2)[ [ 4, 3 ], [ 2, 1 ] ],
508
+ M(t, 2)[ [ 1, 2 ], [ 3, 4 ] ].shift( 1, 1 )
535
509
  end
536
510
  end
537
511
 
538
512
  def test_downsample
539
513
  [ O, I ].each do |t|
540
- assert_equal M( t, 1, 2 )[ [ 2 ], [ 6 ] ],
541
- M( t, 3, 2 )[ [ 1, 2, 3 ], [ 5, 6, 7 ] ].downsample( 2, 1 )
542
- assert_equal M( t, 2, 2 )[ [ 1, 3 ], [ 5, 7 ] ],
543
- M( t, 3, 2 )[ [ 1, 2, 3 ], [ 5, 6, 7 ] ].
514
+ assert_equal M(t, 2)[ [ 2 ], [ 6 ] ],
515
+ M(t, 2)[ [ 1, 2, 3 ], [ 5, 6, 7 ] ].downsample( 2, 1 )
516
+ assert_equal M(t, 2)[ [ 1, 3 ], [ 5, 7 ] ],
517
+ M(t, 2)[ [ 1, 2, 3 ], [ 5, 6, 7 ] ].
544
518
  downsample( 2, 1, :offset => [ 0, 0 ] )
545
519
  end
546
520
  end
@@ -642,9 +616,9 @@ class TC_MultiArray < Test::Unit::TestCase
642
616
  M[ [ 1, 2, 4 ], [ 2, 4, 6 ] ] + 1
643
617
  assert_equal M[ [ 2, 3, 5 ], [ 3, 5, 7 ] ],
644
618
  1 + M[ [ 1, 2, 4 ], [ 2, 4, 6 ] ]
645
- assert_equal M[ [ -3, 2, 1 ], [ 8, 6, 4 ] ] +
646
- M[ [ 2, 0, 2 ], [ -4, -1, 2 ] ],
647
- M[ [ -1, 2, 3 ], [ 4, 5, 6 ] ]
619
+ assert_equal M[ [ -1, 2, 3 ], [ 4, 5, 6 ] ],
620
+ M[ [ -3, 2, 1 ], [ 8, 6, 4 ] ] +
621
+ M[ [ 2, 0, 2 ], [ -4, -1, 2 ] ]
648
622
  assert_equal M[ [ 2, 3, 4 ], [ 6, 7, 8 ] ],
649
623
  M[ [ 1, 2, 3 ], [ 4, 5, 6 ] ] + S[ 1, 2 ]
650
624
  assert_equal M[ [ 2, 3, 4 ], [ 6, 7, 8 ] ],
@@ -702,33 +676,33 @@ class TC_MultiArray < Test::Unit::TestCase
702
676
  end
703
677
 
704
678
  def test_fill
705
- m = M( I, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
706
- assert_equal M( I, 3, 2 )[ [ 1, 1, 1 ], [ 1, 1, 1 ] ], m.fill!( 1 )
707
- assert_equal M( I, 3, 2 )[ [ 1, 1, 1 ], [ 1, 1, 1 ] ], m
679
+ m = M(I, 2)[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
680
+ assert_equal M(I, 2)[ [ 1, 1, 1 ], [ 1, 1, 1 ] ], m.fill!( 1 )
681
+ assert_equal M(I, 2)[ [ 1, 1, 1 ], [ 1, 1, 1 ] ], m
708
682
  end
709
683
 
710
684
  def test_to_type
711
- assert_equal M( C, 2, 2 )[ [ 1, 2 ], [ 3, 4 ] ],
712
- M( I, 2, 2 )[ [ 1, 2 ], [ 3, 4 ] ].to_intrgb
685
+ assert_equal M(C, 2)[ [ 1, 2 ], [ 3, 4 ] ],
686
+ M(I, 2)[ [ 1, 2 ], [ 3, 4 ] ].to_intrgb
713
687
  end
714
688
 
715
689
  def test_reshape
716
- [ O, I ].each do |t|
717
- assert_equal M( t, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ],
718
- S( t, 6 )[ 1, 2, 3, 4, 5, 6 ].reshape( 3, 2 )
719
- assert_equal S( t, 6 )[ 1, 2, 3, 4, 5, 6 ],
720
- M( t, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].reshape( 6 )
721
- assert_equal M( t, 2, 3 )[ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ],
722
- M( t, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].reshape( 2, 3 )
723
- assert_raise( RuntimeError ) { M( t, 2, 2 )[ [ 1, 2 ], [ 3, 4 ] ].reshape 3 }
690
+ [O, I].each do |t|
691
+ assert_equal M(t, 2)[[1, 2, 3], [4, 5, 6]],
692
+ S(t)[1, 2, 3, 4, 5, 6].reshape(3, 2)
693
+ assert_equal S(t)[1, 2, 3, 4, 5, 6],
694
+ M(t, 2)[[1, 2, 3], [4, 5, 6]].reshape(6)
695
+ assert_equal M(t, 2)[[1, 2], [3, 4], [5, 6]],
696
+ M(t, 2)[[1, 2, 3], [4, 5, 6]].reshape(2, 3)
697
+ assert_raise( RuntimeError ) { M(t, 2)[[1, 2], [3, 4]].reshape 3 }
724
698
  end
725
699
  end
726
700
 
727
701
  def test_integral
728
- assert_equal M( O, 3, 2 )[ [ 1, 3, 6 ], [ 5, 12, 21 ] ],
729
- M( O, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].integral
730
- assert_equal M( I, 3, 2 )[ [ 1, 3, 6 ], [ 5, 12, 21 ] ],
731
- M( I, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].integral
702
+ assert_equal M(O, 2)[[1, 3, 6], [5, 12, 21]],
703
+ M(O, 2)[[1, 2, 3], [4, 5, 6]].integral
704
+ assert_equal M(I, 2)[[1, 3, 6], [5, 12, 21]],
705
+ M(I, 2)[[1, 2, 3], [4, 5, 6]].integral
732
706
  end
733
707
 
734
708
  def test_components
@@ -737,28 +711,28 @@ class TC_MultiArray < Test::Unit::TestCase
737
711
  end
738
712
 
739
713
  def test_mask
740
- [ O, I ].each do |t|
741
- assert_equal M( O, 2, 2 )[ [ 1, 2 ], [ 5, 7 ] ],
742
- M( O, 2, 3 )[ [ 1, 2 ], [ 3, 4 ], [ 5, 7 ] ].
743
- mask( S[ true, false, true ] )
744
- assert_equal S( O, 3 )[ 2, 5, 7 ], M( O, 3, 2 )[ [ 1, 2, 3 ], [ 4, 5, 7 ] ].
745
- mask( M[ [ false, true, false ], [ false, true, true ] ] )
714
+ [O, I].each do |t|
715
+ assert_equal M(t, 2)[[1, 2], [5, 7]],
716
+ M(t, 2)[[1, 2], [3, 4], [5, 7]].
717
+ mask(S[true, false, true])
718
+ assert_equal S(t)[2, 5, 7], M(t, 2)[[1, 2, 3], [4, 5, 7]].
719
+ mask( M[[false, true, false], [false, true, true]])
746
720
  assert_raise( RuntimeError ) do
747
- M( O, 2, 3 )[ [ 1, 2 ], [ 3, 4 ], [ 5, 7 ] ].mask S[ false, true ]
721
+ M(t, 2)[[1, 2], [3, 4], [5, 7]].mask S[false, true]
748
722
  end
749
723
  end
750
724
  end
751
725
 
752
726
  def test_unmask
753
727
  [ O, I ].each do |t|
754
- assert_equal M( t, 2, 3 )[ [ 1, 2 ], [ 4, 4 ], [ 5, 7 ] ],
755
- M( t, 2, 2 )[ [ 1, 2 ], [ 5, 7 ] ].
756
- unmask( S[ true, false, true ], :default => S[ 3, 4, 5 ] )
757
- assert_equal M( t, 3, 2 )[ [ 0, 2, 0 ], [ 0, 5, 7 ] ],
758
- S( t, 3 )[ 2, 5, 7 ].
759
- unmask( M[ [ false, true, false ], [ false, true, true ] ],
728
+ assert_equal M(t, 2)[[1, 2], [4, 4], [5, 7]],
729
+ M(t, 2)[[1, 2], [5, 7]].
730
+ unmask( S[true, false, true], :default => S[3, 4, 5] )
731
+ assert_equal M(t, 2)[[0, 2, 0], [0, 5, 7]],
732
+ S(t)[2, 5, 7].
733
+ unmask( M[[false, true, false], [false, true, true]],
760
734
  :default => 0 )
761
- assert_raise( RuntimeError ) { S( t, 1 )[ 1 ].unmask M[ [ true, true ] ] }
735
+ assert_raise( RuntimeError ) { S(t)[1].unmask M[[true, true]] }
762
736
  end
763
737
  end
764
738