multiarray 0.6.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/multiarray/multiarray.rb +7 -0
- data/lib/multiarray/node.rb +4 -0
- data/lib/multiarray/sequence.rb +7 -0
- data/lib/multiarray/shortcuts.rb +5 -5
- data/test/tc_multiarray.rb +17 -0
- data/test/tc_sequence.rb +11 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
1
|
+
multiarray
|
2
2
|
==========
|
3
3
|
This Ruby-extension defines the class {Hornetseye::MultiArray} and other native datatypes. {Hornetseye::MultiArray} provides multi-dimensional Ruby arrays with elements of same type. The extension is designed to be mostly compatible with Masahiro Tanaka's NArray. However it allows the definition of custom element types and operations on them. This work was also inspired by Ronald Garcia's boost::multi_array and by Todd Veldhuizen's Blitz++.
|
data/Rakefile
CHANGED
@@ -44,6 +44,13 @@ module Hornetseye
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
def import( typecode, string, *shape )
|
48
|
+
t = Hornetseye::MultiArray typecode, *shape
|
49
|
+
memory = Malloc.new t.storage_size
|
50
|
+
memory.write string
|
51
|
+
t.new memory
|
52
|
+
end
|
53
|
+
|
47
54
|
# Convert Ruby array to uniform multi-dimensional array
|
48
55
|
#
|
49
56
|
# Type matching is used to find a common element type. Furthermore the required
|
data/lib/multiarray/node.rb
CHANGED
data/lib/multiarray/sequence.rb
CHANGED
@@ -32,6 +32,13 @@ module Hornetseye
|
|
32
32
|
MultiArray.new typecode, size
|
33
33
|
end
|
34
34
|
|
35
|
+
def import( typecode, string, size )
|
36
|
+
t = Hornetseye::Sequence typecode, size
|
37
|
+
memory = Malloc.new t.storage_size
|
38
|
+
memory.write string
|
39
|
+
t.new memory
|
40
|
+
end
|
41
|
+
|
35
42
|
# Convert array to uniform array
|
36
43
|
#
|
37
44
|
# A native type which fits all elements is determined and used to create
|
data/lib/multiarray/shortcuts.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
# Namespace of Hornetseye computer vision library
|
18
18
|
module Hornetseye
|
19
19
|
|
20
|
-
module
|
20
|
+
module MultiArrayConstructor
|
21
21
|
|
22
22
|
def method_missing( name, *args )
|
23
23
|
if name.to_s =~ /^[a-z]+$/
|
@@ -39,11 +39,11 @@ module Hornetseye
|
|
39
39
|
|
40
40
|
end
|
41
41
|
|
42
|
-
Sequence.extend
|
42
|
+
Sequence.extend MultiArrayConstructor
|
43
43
|
|
44
|
-
MultiArray.extend
|
44
|
+
MultiArray.extend MultiArrayConstructor
|
45
45
|
|
46
|
-
module
|
46
|
+
module MultiArrayConversion
|
47
47
|
|
48
48
|
def method_missing( name, *args )
|
49
49
|
if name.to_s =~ /^to_[a-z]+$/
|
@@ -65,7 +65,7 @@ module Hornetseye
|
|
65
65
|
|
66
66
|
end
|
67
67
|
|
68
|
-
Node.class_eval { include
|
68
|
+
Node.class_eval { include MultiArrayConversion }
|
69
69
|
|
70
70
|
end
|
71
71
|
|
data/test/tc_multiarray.rb
CHANGED
@@ -166,6 +166,13 @@ class TC_MultiArray < Test::Unit::TestCase
|
|
166
166
|
assert_equal 6, M( O, 3, 2 ).new.size
|
167
167
|
end
|
168
168
|
|
169
|
+
def test_import
|
170
|
+
assert_equal [ [ 1, 2, 3 ], [ 4, 5, 6 ] ],
|
171
|
+
M.import( I, "\001\000\000\000\002\000\000\000\003\000\000\000" +
|
172
|
+
"\004\000\000\000\005\000\000\000\006\000\000\000",
|
173
|
+
3, 2 ).to_a
|
174
|
+
end
|
175
|
+
|
169
176
|
def test_at_assign
|
170
177
|
[ M( O, 3, 2 ), M( I, 3, 2 ) ].each do |t|
|
171
178
|
m = t.new
|
@@ -331,11 +338,21 @@ class TC_MultiArray < Test::Unit::TestCase
|
|
331
338
|
assert_equal M[ [ 1, 4 ], [ 5, 6 ] ], M[ [ C( 1, 2, 3 ), 4 ], [ 5, 6 ] ].r
|
332
339
|
assert_equal M[ [ 2, 4 ], [ 5, 6 ] ], M[ [ C( 1, 2, 3 ), 4 ], [ 5, 6 ] ].g
|
333
340
|
assert_equal M[ [ 3, 4 ], [ 5, 6 ] ], M[ [ C( 1, 2, 3 ), 4 ], [ 5, 6 ] ].b
|
341
|
+
#assert_equal M[ [ 1, 4 ], [ 5, 6 ] ],
|
342
|
+
# M[ [ C( 1, 2, 3 ), 4 ], [ 5, 6 ] ].collect { |x| x.r }
|
343
|
+
#assert_equal M[ [ 2, 4 ], [ 5, 6 ] ],
|
344
|
+
# M[ [ C( 1, 2, 3 ), 4 ], [ 5, 6 ] ].collect { |x| x.g }
|
345
|
+
#assert_equal M[ [ 3, 4 ], [ 5, 6 ] ],
|
346
|
+
# M[ [ C( 1, 2, 3 ), 4 ], [ 5, 6 ] ].collect { |x| x.b }
|
334
347
|
end
|
335
348
|
|
336
349
|
def test_real_imag
|
337
350
|
assert_equal M[ [ 1, 3 ], [ 4, 5 ] ], M[ [ X( 1, 2 ), 3 ], [ 4, 5 ] ].real
|
338
351
|
assert_equal M[ [ 2, 0 ], [ 0, 0 ] ], M[ [ X( 1, 2 ), 3 ], [ 4, 5 ] ].imag
|
352
|
+
#assert_equal M[ [ 1, 3 ], [ 4, 5 ] ],
|
353
|
+
# M[ [ X( 1, 2 ), 3 ], [ 4, 5 ] ].collect { |x| x.real }
|
354
|
+
#assert_equal M[ [ 2, 0 ], [ 0, 0 ] ],
|
355
|
+
# M[ [ X( 1, 2 ), 3 ], [ 4, 5 ] ].collect { |x| x.imag }
|
339
356
|
end
|
340
357
|
|
341
358
|
def test_inject
|
data/test/tc_sequence.rb
CHANGED
@@ -144,6 +144,12 @@ class TC_Sequence < Test::Unit::TestCase
|
|
144
144
|
assert_equal 3, S[ 1, 2, 3 ].size
|
145
145
|
end
|
146
146
|
|
147
|
+
def test_import
|
148
|
+
assert_equal [ 1, 2, 3 ],
|
149
|
+
S.import( I, "\001\000\000\000\002\000\000\000\003\000\000\000", 3 ).
|
150
|
+
to_a
|
151
|
+
end
|
152
|
+
|
147
153
|
def test_at_assign
|
148
154
|
[ S( O, 3 ), S( I, 3 ) ].each do |t|
|
149
155
|
s = t.new
|
@@ -214,6 +220,9 @@ class TC_Sequence < Test::Unit::TestCase
|
|
214
220
|
assert_equal [ 1, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].r.to_a
|
215
221
|
assert_equal [ 2, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].g.to_a
|
216
222
|
assert_equal [ 3, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].b.to_a
|
223
|
+
#assert_equal [ 1, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].collect { |x| x.r }.to_a
|
224
|
+
#assert_equal [ 2, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].collect { |x| x.g }.to_a
|
225
|
+
#assert_equal [ 3, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].collect { |x| x.b }.to_a
|
217
226
|
s = t[ 0, 0, 0 ]
|
218
227
|
assert_equal 1, s.r = 1
|
219
228
|
assert_equal S[ 1, 2, 3 ], s.g = S[ 1, 2, 3 ]
|
@@ -233,6 +242,8 @@ class TC_Sequence < Test::Unit::TestCase
|
|
233
242
|
[ S( O, 2 ), S( X, 2 ) ].each do |t|
|
234
243
|
assert_equal [ 1, 3 ], t[ X( 1, 2 ), 3 ].real.to_a
|
235
244
|
assert_equal [ 2, 0 ], t[ X( 1, 2 ), 3 ].imag.to_a
|
245
|
+
#assert_equal [ 1, 3 ], t[ X( 1, 2 ), 3 ].collect { |x| x.real }.to_a
|
246
|
+
#assert_equal [ 2, 0 ], t[ X( 1, 2 ), 3 ].collect { |x| x.imag }.to_a
|
236
247
|
s = t[ 0, 0 ]
|
237
248
|
assert_equal 1, s.real = 1
|
238
249
|
assert_equal S[ 2, 3 ], s.imag = S[ 2, 3 ]
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 8
|
8
|
+
- 0
|
9
|
+
version: 0.8.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jan Wedekind
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-07 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|