multiarray 0.5.1 → 0.5.2

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.
@@ -1,195 +0,0 @@
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
- # Namespace of Hornetseye computer vision library
18
- module Hornetseye
19
-
20
- # Class for representing binary operations on scalars and arrays
21
- class BinaryMethod_ < Node
22
-
23
- class << self
24
-
25
- # Name of module
26
- #
27
- # @return [Module] The module with the method.
28
- attr_accessor :mod
29
-
30
- # Name of operation
31
- #
32
- # @return [Symbol,String] The name of this operation.
33
- attr_accessor :operation
34
-
35
- # Name of method for type conversion
36
- #
37
- # @return [Symbol,String] The name of the method for type conversion.
38
- attr_accessor :coercion
39
-
40
- # Get string with information about this class
41
- #
42
- # @return [String] Return string with information about this class.
43
- def inspect
44
- "#{mod.to_s}.#{operation.to_s}"
45
- end
46
-
47
- # Get unique descriptor of this class
48
- #
49
- # @param [Hash] hash Labels for any variables.
50
- #
51
- # @return [String] Descriptor of this class.
52
- #
53
- # @private
54
- def descriptor( hash )
55
- inspect
56
- end
57
-
58
- end
59
-
60
- # Initialise binary operation
61
- #
62
- # @param [Node] value1 First operand to apply operation to.
63
- # @param [Node] value2 Second operand to apply operation to.
64
- def initialize( value1, value2 )
65
- @value1, @value2 = value1, value2
66
- end
67
-
68
- # Get unique descriptor of this object
69
- #
70
- # @param [Hash] hash Labels for any variables.
71
- #
72
- # @return [String] Descriptor of this object,
73
- #
74
- # @private
75
- def descriptor( hash )
76
- "#{self.class.descriptor( hash )}(#{@value1.descriptor( hash )})," +
77
- "(#{@value2.descriptor( hash )})"
78
- end
79
-
80
- # Array type of this term
81
- #
82
- # @return [Class] Resulting array type.
83
- #
84
- # @private
85
- def array_type
86
- @value1.array_type.send self.class.coercion, @value2.array_type
87
- end
88
-
89
- # Substitute variables
90
- #
91
- # Substitute the variables with the values given in the hash.
92
- #
93
- # @param [Hash] hash Substitutions to apply.
94
- #
95
- # @return [Node] Term with substitutions applied.
96
- #
97
- # @private
98
- def subst( hash )
99
- self.class.new @value1.subst( hash ), @value2.subst( hash )
100
- end
101
-
102
- # Get variables contained in this term
103
- #
104
- # @return [Set] Returns set of variables.
105
- #
106
- # @private
107
- def variables
108
- @value1.variables + @value2.variables
109
- end
110
-
111
- # Strip of all values
112
- #
113
- # Split up into variables, values, and a term where all values have been
114
- # replaced with variables.
115
- #
116
- # @return [Array<Array,Node>] Returns an array of variables, an array of
117
- # values, and the term based on variables.
118
- #
119
- # @private
120
- def strip
121
- vars1, values1, term1 = @value1.strip
122
- vars2, values2, term2 = @value2.strip
123
- return vars1 + vars2, values1 + values2, self.class.new( term1, term2 )
124
- end
125
-
126
- # Reevaluate computation
127
- #
128
- # @return [Node,Object] Result of computation
129
- #
130
- # @see #force
131
- #
132
- # @private
133
- def demand
134
- self.class.mod.send self.class.operation, @value1, @value2
135
- end
136
-
137
- def skip( index, start )
138
- element1 = @value1.skip( index, start )
139
- element2 = @value2.skip( index, start )
140
- self.class.new( element1, element2 ).demand
141
- end
142
-
143
- # Get element of unary operation
144
- #
145
- # @param [Integer,Node] i Index of desired element.
146
- #
147
- # @return [Node,Object] Element of unary operation.
148
- def element( i )
149
- element1 = @value1.dimension == 0 ? @value1 : @value1.element( i )
150
- element2 = @value2.dimension == 0 ? @value2 : @value2.element( i )
151
- self.class.new( element1, element2 ).demand
152
- end
153
-
154
- def slice( start, length )
155
- element1 = @value1.dimension == 0 ? @value1 :
156
- @value1.slice( start, length )
157
- element2 = @value2.dimension == 0 ? @value2 :
158
- @value2.slice( start, length )
159
- self.class.new( element1, element2 ).demand
160
- end
161
-
162
- # Check whether this term is compilable
163
- #
164
- # @return [FalseClass,TrueClass] Returns whether this term is compilable.
165
- #
166
- # @private
167
- def compilable?
168
- @value1.compilable? and @value2.compilable?
169
- end
170
-
171
- end
172
-
173
- # Create a class deriving from +BinaryMethod_+
174
- #
175
- # @param [Symbol,String] operation Name of operation.
176
- # @param [Symbol,String] conversion Name of method for type conversion.
177
- #
178
- # @return [Class] A class deriving from +BinaryMethod_+.
179
- #
180
- # @see BinaryMethod_
181
- # @see BinaryMethod_.operation
182
- # @see BinaryMethod_.coercion
183
- #
184
- # @private
185
- def BinaryMethod( mod, operation, coercion = :coercion )
186
- retval = Class.new BinaryMethod_
187
- retval.mod = mod
188
- retval.operation = operation
189
- retval.coercion = coercion
190
- retval
191
- end
192
-
193
- module_function :BinaryMethod
194
-
195
- end
@@ -1,189 +0,0 @@
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
- # Namespace of Hornetseye computer vision library
18
- module Hornetseye
19
-
20
- # Class for representing binary operations on scalars and arrays
21
- class BinaryOp_ < Node
22
-
23
- class << self
24
-
25
- # Name of operation
26
- #
27
- # @return [Symbol,String] The name of this operation.
28
- attr_accessor :operation
29
-
30
- # Name of method for type conversion
31
- #
32
- # @return [Symbol,String] The name of the method for type conversion.
33
- attr_accessor :coercion
34
-
35
- # Get string with information about this class
36
- #
37
- # @return [String] Return string with information about this class.
38
- def inspect
39
- operation.to_s
40
- end
41
-
42
- # Get unique descriptor of this class
43
- #
44
- # @param [Hash] hash Labels for any variables.
45
- #
46
- # @return [String] Descriptor of this class.
47
- #
48
- # @private
49
- def descriptor( hash )
50
- inspect
51
- end
52
-
53
- end
54
-
55
- # Initialise binary operation
56
- #
57
- # @param [Node] value1 First operand to apply operation to.
58
- # @param [Node] value2 Second operand to apply operation to.
59
- def initialize( value1, value2 )
60
- @value1, @value2 = value1, value2
61
- end
62
-
63
- # Get unique descriptor of this object
64
- #
65
- # @param [Hash] hash Labels for any variables.
66
- #
67
- # @return [String] Descriptor of this object,
68
- #
69
- # @private
70
- def descriptor( hash )
71
- "(#{@value1.descriptor( hash )}).#{self.class.descriptor( hash )}" +
72
- "(#{@value2.descriptor( hash )})"
73
- end
74
-
75
- # Array type of this term
76
- #
77
- # @return [Class] Resulting array type.
78
- #
79
- # @private
80
- def array_type
81
- @value1.array_type.send self.class.coercion, @value2.array_type
82
- end
83
-
84
- # Substitute variables
85
- #
86
- # Substitute the variables with the values given in the hash.
87
- #
88
- # @param [Hash] hash Substitutions to apply.
89
- #
90
- # @return [Node] Term with substitutions applied.
91
- #
92
- # @private
93
- def subst( hash )
94
- self.class.new @value1.subst( hash ), @value2.subst( hash )
95
- end
96
-
97
- # Get variables contained in this term
98
- #
99
- # @return [Set] Returns set of variables.
100
- #
101
- # @private
102
- def variables
103
- @value1.variables + @value2.variables
104
- end
105
-
106
- # Strip of all values
107
- #
108
- # Split up into variables, values, and a term where all values have been
109
- # replaced with variables.
110
- #
111
- # @return [Array<Array,Node>] Returns an array of variables, an array of
112
- # values, and the term based on variables.
113
- #
114
- # @private
115
- def strip
116
- vars1, values1, term1 = @value1.strip
117
- vars2, values2, term2 = @value2.strip
118
- return vars1 + vars2, values1 + values2, self.class.new( term1, term2 )
119
- end
120
-
121
- # Reevaluate computation
122
- #
123
- # @return [Node,Object] Result of computation
124
- #
125
- # @see #force
126
- #
127
- # @private
128
- def demand
129
- @value1.send self.class.operation, @value2
130
- end
131
-
132
- def skip( index, start )
133
- element1 = @value1.skip( index, start )
134
- element2 = @value2.skip( index, start )
135
- self.class.new( element1, element2 ).demand
136
- end
137
-
138
- # Get element of unary operation
139
- #
140
- # @param [Integer,Node] i Index of desired element.
141
- #
142
- # @return [Node,Object] Element of unary operation.
143
- def element( i )
144
- element1 = @value1.dimension == 0 ? @value1 : @value1.element( i )
145
- element2 = @value2.dimension == 0 ? @value2 : @value2.element( i )
146
- self.class.new( element1, element2 ).demand
147
- end
148
-
149
- def slice( start, length )
150
- element1 = @value1.dimension == 0 ? @value1 :
151
- @value1.slice( start, length )
152
- element2 = @value2.dimension == 0 ? @value2 :
153
- @value2.slice( start, length )
154
- self.class.new( element1, element2 ).demand
155
- end
156
-
157
- # Check whether this term is compilable
158
- #
159
- # @return [FalseClass,TrueClass] Returns whether this term is compilable.
160
- #
161
- # @private
162
- def compilable?
163
- @value1.compilable? and @value2.compilable?
164
- end
165
-
166
- end
167
-
168
- # Create a class deriving from +BinaryOp_+
169
- #
170
- # @param [Symbol,String] operation Name of operation.
171
- # @param [Symbol,String] conversion Name of method for type conversion.
172
- #
173
- # @return [Class] A class deriving from +BinaryOp_+.
174
- #
175
- # @see BinaryOp_
176
- # @see BinaryOp_.operation
177
- # @see BinaryOp_.coercion
178
- #
179
- # @private
180
- def BinaryOp( operation, coercion = :coercion )
181
- retval = Class.new BinaryOp_
182
- retval.operation = operation
183
- retval.coercion = coercion
184
- retval
185
- end
186
-
187
- module_function :BinaryOp
188
-
189
- end
@@ -1,179 +0,0 @@
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
- # Namespace of Hornetseye computer vision library
18
- module Hornetseye
19
-
20
- # Class for representing unary operations on scalars and arrays
21
- class UnaryOp_ < Node
22
-
23
- class << self
24
-
25
- # Name of operation
26
- #
27
- # @return [Symbol,String] The name of this operation.
28
- attr_accessor :operation
29
-
30
- # Name of method for type conversion
31
- #
32
- # @return [Symbol,String] The name of the method for type conversion.
33
- attr_accessor :conversion
34
-
35
- # Get string with information about this class
36
- #
37
- # @return [String] Return string with information about this class.
38
- def inspect
39
- operation.to_s
40
- end
41
-
42
- # Get unique descriptor of this class
43
- #
44
- # @param [Hash] hash Labels for any variables.
45
- #
46
- # @return [String] Descriptor of this class.
47
- #
48
- # @private
49
- def descriptor( hash )
50
- inspect
51
- end
52
-
53
- end
54
-
55
- # Initialise unary operation
56
- #
57
- # @param [Node] value Value to apply operation to.
58
- def initialize( value )
59
- @value = value
60
- end
61
-
62
- # Get unique descriptor of this object
63
- #
64
- # @param [Hash] hash Labels for any variables.
65
- #
66
- # @return [String] Descriptor of this object,
67
- #
68
- # @private
69
- def descriptor( hash )
70
- "(#{@value.descriptor( hash )}).#{self.class.descriptor( hash )}"
71
- end
72
-
73
- # Array type of this term
74
- #
75
- # @return [Class] Resulting array type.
76
- #
77
- # @private
78
- def array_type
79
- @value.array_type.send self.class.conversion
80
- end
81
-
82
- # Substitute variables
83
- #
84
- # Substitute the variables with the values given in the hash.
85
- #
86
- # @param [Hash] hash Substitutions to apply.
87
- #
88
- # @return [Node] Term with substitutions applied.
89
- #
90
- # @private
91
- def subst( hash )
92
- self.class.new @value.subst( hash )
93
- end
94
-
95
- # Get variables contained in this term
96
- #
97
- # @return [Set] Returns set of variables.
98
- #
99
- # @private
100
- def variables
101
- @value.variables
102
- end
103
-
104
- # Strip of all values
105
- #
106
- # Split up into variables, values, and a term where all values have been
107
- # replaced with variables.
108
- #
109
- # @return [Array<Array,Node>] Returns an array of variables, an array of
110
- # values, and the term based on variables.
111
- #
112
- # @private
113
- def strip
114
- vars, values, term = @value.strip
115
- return vars, values, self.class.new( term )
116
- end
117
-
118
- # Reevaluate computation
119
- #
120
- # @return [Node,Object] Result of computation
121
- #
122
- # @see #force
123
- #
124
- # @private
125
- def demand
126
- @value.send self.class.operation
127
- end
128
-
129
- def skip( index, start )
130
- self.class.new( @value.skip( index, start ) ).demand
131
- end
132
-
133
- # Get element of unary operation
134
- #
135
- # @param [Integer,Node] i Index of desired element.
136
- #
137
- # @return [Node,Object] Element of unary operation.
138
- def element( i )
139
- self.class.new( @value.element( i ) ).demand
140
- end
141
-
142
- def slice( start, length )
143
- self.class.new( @value.slice( start, length ) ).demand
144
- end
145
-
146
- # Check whether this term is compilable
147
- #
148
- # @return [FalseClass,TrueClass] Returns whether this term is compilable.
149
- #
150
- # @private
151
- def compilable?
152
- @value.compilable?
153
- end
154
-
155
- end
156
-
157
- # Create a class deriving from +UnaryOp_+
158
- #
159
- # @param [Symbol,String] operation Name of operation.
160
- # @param [Symbol,String] conversion Name of method for type conversion.
161
- #
162
- # @return [Class] A class deriving from +UnaryOp_+.
163
- #
164
- # @see UnaryOp_
165
- # @see UnaryOp_.operation
166
- # @see UnaryOp_.conversion
167
- #
168
- # @private
169
- def UnaryOp( operation, conversion = :contiguous )
170
- retval = Class.new UnaryOp_
171
- retval.operation = operation
172
- retval.conversion = conversion
173
- retval
174
- end
175
-
176
- module_function :UnaryOp
177
-
178
- end
179
-