multiarray 0.11.3 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +61 -0
- data/Rakefile +1 -1
- data/lib/multiarray.rb +28 -0
- data/lib/multiarray/complex.rb +310 -13
- data/lib/multiarray/composite.rb +7 -0
- data/lib/multiarray/diagonal.rb +18 -3
- data/lib/multiarray/elementwise.rb +7 -2
- data/lib/multiarray/float.rb +43 -3
- data/lib/multiarray/gcccache.rb +4 -1
- data/lib/multiarray/gcccontext.rb +119 -21
- data/lib/multiarray/gccfunction.rb +92 -3
- data/lib/multiarray/gcctype.rb +26 -0
- data/lib/multiarray/gccvalue.rb +204 -2
- data/lib/multiarray/histogram.rb +65 -1
- data/lib/multiarray/index.rb +11 -0
- data/lib/multiarray/inject.rb +18 -1
- data/lib/multiarray/int.rb +49 -18
- data/lib/multiarray/integral.rb +65 -1
- data/lib/multiarray/lambda.rb +19 -5
- data/lib/multiarray/list.rb +8 -0
- data/lib/multiarray/lookup.rb +8 -1
- data/lib/multiarray/lut.rb +96 -2
- data/lib/multiarray/methods.rb +13 -3
- data/lib/multiarray/multiarray.rb +11 -0
- data/lib/multiarray/node.rb +52 -9
- data/lib/multiarray/operations.rb +118 -15
- data/lib/multiarray/pointer.rb +35 -1
- data/lib/multiarray/rgb.rb +139 -14
- data/lib/multiarray/sequence.rb +140 -2
- data/lib/multiarray/shortcuts.rb +76 -30
- data/lib/multiarray/store.rb +54 -0
- data/lib/multiarray/variable.rb +19 -0
- data/test/tc_lazy.rb +9 -0
- metadata +3 -3
data/lib/multiarray/shortcuts.rb
CHANGED
@@ -17,52 +17,98 @@
|
|
17
17
|
# Namespace of Hornetseye computer vision library
|
18
18
|
module Hornetseye
|
19
19
|
|
20
|
+
# Module with meta-programming methods for creating constructor shortcut methods
|
20
21
|
module MultiArrayConstructor
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
else
|
33
|
-
super name, *args
|
34
|
-
end
|
35
|
-
else
|
36
|
-
super name, *args
|
23
|
+
# Meta-programming method for creating constructor shortcut methods
|
24
|
+
#
|
25
|
+
# @param [Class] target Element-type to create constructor shortcut for.
|
26
|
+
#
|
27
|
+
# @return [Proc] The new method.
|
28
|
+
#
|
29
|
+
# @private
|
30
|
+
def constructor_shortcut( target )
|
31
|
+
define_method( target.to_s.downcase ) do |*args|
|
32
|
+
new target, *args
|
37
33
|
end
|
38
34
|
end
|
39
35
|
|
36
|
+
module_function :constructor_shortcut
|
37
|
+
|
38
|
+
constructor_shortcut OBJECT
|
39
|
+
constructor_shortcut BOOL
|
40
|
+
constructor_shortcut BYTE
|
41
|
+
constructor_shortcut UBYTE
|
42
|
+
constructor_shortcut SINT
|
43
|
+
constructor_shortcut USINT
|
44
|
+
constructor_shortcut INT
|
45
|
+
constructor_shortcut UINT
|
46
|
+
constructor_shortcut LONG
|
47
|
+
constructor_shortcut ULONG
|
48
|
+
constructor_shortcut SFLOAT
|
49
|
+
constructor_shortcut DFLOAT
|
50
|
+
constructor_shortcut SCOMPLEX
|
51
|
+
constructor_shortcut DCOMPLEX
|
52
|
+
constructor_shortcut BYTERGB
|
53
|
+
constructor_shortcut UBYTERGB
|
54
|
+
constructor_shortcut SINTRGB
|
55
|
+
constructor_shortcut USINTRGB
|
56
|
+
constructor_shortcut INTRGB
|
57
|
+
constructor_shortcut UINTRGB
|
58
|
+
constructor_shortcut LONGRGB
|
59
|
+
constructor_shortcut ULONGRGB
|
60
|
+
constructor_shortcut SFLOATRGB
|
61
|
+
constructor_shortcut DFLOATRGB
|
62
|
+
|
40
63
|
end
|
41
64
|
|
42
65
|
Sequence.extend MultiArrayConstructor
|
43
66
|
|
44
67
|
MultiArray.extend MultiArrayConstructor
|
45
68
|
|
69
|
+
# Module with meta-programming methods for creating conversion shortcut methods
|
46
70
|
module MultiArrayConversion
|
47
71
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
else
|
59
|
-
super name, *args
|
60
|
-
end
|
61
|
-
else
|
62
|
-
super name, *args
|
72
|
+
# Meta-programming method for creating type conversion shortcut methods
|
73
|
+
#
|
74
|
+
# @param [Class] target Element-type to create type conversion shortcut for.
|
75
|
+
#
|
76
|
+
# @return [Proc] The new method.
|
77
|
+
#
|
78
|
+
# @private
|
79
|
+
def to_type_shortcut( target )
|
80
|
+
define_method( "to_#{target.to_s.downcase}" ) do
|
81
|
+
to_type target
|
63
82
|
end
|
64
83
|
end
|
65
84
|
|
85
|
+
module_function :to_type_shortcut
|
86
|
+
|
87
|
+
to_type_shortcut OBJECT
|
88
|
+
to_type_shortcut BOOL
|
89
|
+
to_type_shortcut BYTE
|
90
|
+
to_type_shortcut UBYTE
|
91
|
+
to_type_shortcut SINT
|
92
|
+
to_type_shortcut USINT
|
93
|
+
to_type_shortcut INT
|
94
|
+
to_type_shortcut UINT
|
95
|
+
to_type_shortcut LONG
|
96
|
+
to_type_shortcut ULONG
|
97
|
+
to_type_shortcut SFLOAT
|
98
|
+
to_type_shortcut DFLOAT
|
99
|
+
to_type_shortcut SCOMPLEX
|
100
|
+
to_type_shortcut DCOMPLEX
|
101
|
+
to_type_shortcut BYTERGB
|
102
|
+
to_type_shortcut UBYTERGB
|
103
|
+
to_type_shortcut SINTRGB
|
104
|
+
to_type_shortcut USINTRGB
|
105
|
+
to_type_shortcut INTRGB
|
106
|
+
to_type_shortcut UINTRGB
|
107
|
+
to_type_shortcut LONGRGB
|
108
|
+
to_type_shortcut ULONGRGB
|
109
|
+
to_type_shortcut SFLOATRGB
|
110
|
+
to_type_shortcut DFLOATRGB
|
111
|
+
|
66
112
|
end
|
67
113
|
|
68
114
|
Node.class_eval { include MultiArrayConversion }
|
data/lib/multiarray/store.rb
CHANGED
@@ -16,20 +16,46 @@
|
|
16
16
|
|
17
17
|
module Hornetseye
|
18
18
|
|
19
|
+
# Class for computing the elements of an array and storing them
|
19
20
|
class Store < Node
|
20
21
|
|
22
|
+
# Constructor
|
23
|
+
#
|
24
|
+
# @param [Node] dest Target array to write array to.
|
25
|
+
# @param [Node] source Expression to compute elements of array.
|
26
|
+
#
|
27
|
+
# @private
|
21
28
|
def initialize( dest, source )
|
22
29
|
@dest, @source = dest, source
|
23
30
|
end
|
24
31
|
|
32
|
+
# Get unique descriptor of this object
|
33
|
+
#
|
34
|
+
# @param [Hash] hash Labels for any variables.
|
35
|
+
#
|
36
|
+
# @return [String] Descriptor of this object,
|
37
|
+
#
|
38
|
+
# @private
|
25
39
|
def descriptor( hash )
|
26
40
|
"Store(#{@dest.descriptor( hash )},#{@source.descriptor( hash )})"
|
27
41
|
end
|
28
42
|
|
43
|
+
# Get type of result of delayed operation
|
44
|
+
#
|
45
|
+
# @return [Class] Type of result.
|
46
|
+
#
|
47
|
+
# @private
|
29
48
|
def array_type
|
30
49
|
@dest.array_type
|
31
50
|
end
|
32
51
|
|
52
|
+
# Reevaluate computation
|
53
|
+
#
|
54
|
+
# @return [Node,Object] Result of computation
|
55
|
+
#
|
56
|
+
# @see #force
|
57
|
+
#
|
58
|
+
# @private
|
33
59
|
def demand
|
34
60
|
if variables.empty?
|
35
61
|
if dimension > 0
|
@@ -48,20 +74,48 @@ module Hornetseye
|
|
48
74
|
end
|
49
75
|
end
|
50
76
|
|
77
|
+
# Substitute variables
|
78
|
+
#
|
79
|
+
# Substitute the variables with the values given in the hash.
|
80
|
+
#
|
81
|
+
# @param [Hash] hash Substitutions to apply.
|
82
|
+
#
|
83
|
+
# @return [Node] Term with substitutions applied.
|
84
|
+
#
|
85
|
+
# @private
|
51
86
|
def subst( hash )
|
52
87
|
self.class.new @dest.subst( hash ), @source.subst( hash )
|
53
88
|
end
|
54
89
|
|
90
|
+
# Get variables contained in this term
|
91
|
+
#
|
92
|
+
# @return [Set] Returns list of variables.
|
93
|
+
#
|
94
|
+
# @private
|
55
95
|
def variables
|
56
96
|
@dest.variables + @source.variables
|
57
97
|
end
|
58
98
|
|
99
|
+
# Strip of all values
|
100
|
+
#
|
101
|
+
# Split up into variables, values, and a term where all values have been
|
102
|
+
# replaced with variables.
|
103
|
+
#
|
104
|
+
# @return [Array<Array,Node>] Returns an array of variables, an array of
|
105
|
+
# values, and the term based on variables.
|
106
|
+
#
|
107
|
+
# @private
|
59
108
|
def strip
|
60
109
|
vars1, values1, term1 = @dest.strip
|
61
110
|
vars2, values2, term2 = @source.strip
|
62
111
|
return vars1 + vars2, values1 + values2, Store.new( term1, term2 )
|
63
112
|
end
|
64
113
|
|
114
|
+
# Check whether this term is compilable
|
115
|
+
#
|
116
|
+
# @return [Boolean] Returns whether this term is compilable.
|
117
|
+
#
|
118
|
+
# @private
|
65
119
|
def compilable?
|
66
120
|
@dest.compilable? and @source.compilable?
|
67
121
|
end
|
data/lib/multiarray/variable.rb
CHANGED
@@ -17,13 +17,23 @@
|
|
17
17
|
# Namespace of Hornetseye computer vision library
|
18
18
|
module Hornetseye
|
19
19
|
|
20
|
+
# Clas for representing variables
|
21
|
+
#
|
22
|
+
# @private
|
20
23
|
class Variable < Node
|
21
24
|
|
22
25
|
# Type information about this variable
|
23
26
|
#
|
24
27
|
# @return [Class] Returns type information about this variable.
|
28
|
+
#
|
29
|
+
# @private
|
25
30
|
attr_reader :meta
|
26
31
|
|
32
|
+
# Constructor creating a variable
|
33
|
+
#
|
34
|
+
# @param [Class] meta The type of this variable.
|
35
|
+
#
|
36
|
+
# @private
|
27
37
|
def initialize( meta )
|
28
38
|
@meta = meta
|
29
39
|
end
|
@@ -32,6 +42,8 @@ module Hornetseye
|
|
32
42
|
#
|
33
43
|
# @return [String] String with information about this object (e.g.
|
34
44
|
# 'Variable(INT)').
|
45
|
+
#
|
46
|
+
# @private
|
35
47
|
def inspect
|
36
48
|
"Variable(#{@meta.inspect})"
|
37
49
|
end
|
@@ -54,6 +66,8 @@ module Hornetseye
|
|
54
66
|
# Get array size for index variable
|
55
67
|
#
|
56
68
|
# @return [Node] Get the dimension of the array if this is an index variable.
|
69
|
+
#
|
70
|
+
# @private
|
57
71
|
def size
|
58
72
|
@meta.size
|
59
73
|
end
|
@@ -63,6 +77,10 @@ module Hornetseye
|
|
63
77
|
# Set the dimension of the array assuming this is an index variable.
|
64
78
|
#
|
65
79
|
# @param [Node] value The new size.
|
80
|
+
#
|
81
|
+
# @return [Node] Returns +value+.
|
82
|
+
#
|
83
|
+
# @private
|
66
84
|
def size=( value )
|
67
85
|
@meta.size = value
|
68
86
|
end
|
@@ -151,3 +169,4 @@ module Hornetseye
|
|
151
169
|
end
|
152
170
|
|
153
171
|
end
|
172
|
+
|
data/test/tc_lazy.rb
CHANGED
@@ -67,6 +67,13 @@ class TC_Lazy < Test::Unit::TestCase
|
|
67
67
|
assert_equal [ [ 0, 0, 0 ], [ 1, 1, 1 ] ], lazy( 3, 2 ) { |i,j| j }.to_a
|
68
68
|
end
|
69
69
|
|
70
|
+
def test_at
|
71
|
+
assert_equal [ [ -1, 4 ], [ 2, 5 ], [ 3, 6 ] ],
|
72
|
+
lazy { |i| lazy { |j| @m[i,j] } }.to_a
|
73
|
+
assert_equal [ [ -1, 4 ], [ 2, 5 ], [ 3, 6 ] ],
|
74
|
+
lazy { |i,j| @m[j,i] }.to_a
|
75
|
+
end
|
76
|
+
|
70
77
|
def test_minus_at
|
71
78
|
assert_equal -2, lazy { ( -@s )[ 1 ] }
|
72
79
|
end
|
@@ -98,6 +105,8 @@ class TC_Lazy < Test::Unit::TestCase
|
|
98
105
|
assert_equal 10, lazy( 5 ) { |i| i }.inject { |a,b| a + b }
|
99
106
|
assert_equal [ 0, 3, 6, 9 ], sum { |k| lazy( 4, 3 ) { |i,j| i }[ k ] }.to_a
|
100
107
|
assert_equal [ 3, 3, 3, 3 ], sum { |k| lazy( 4, 3 ) { |i,j| j }[ k ] }.to_a
|
108
|
+
assert_equal 0, lazy( 3 ) { 0 }.inject { |a,b| a.minor b }
|
109
|
+
assert_equal 0, lazy( 3, 2 ) { 0 }.inject { |a,b| a.minor b }
|
101
110
|
end
|
102
111
|
|
103
112
|
def test_indgen_diagonal
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 11
|
8
|
-
-
|
9
|
-
version: 0.11.
|
8
|
+
- 4
|
9
|
+
version: 0.11.4
|
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-
|
17
|
+
date: 2010-11-18 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|