multiarray 0.11.3 → 0.11.4

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.
@@ -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
- def method_missing( name, *args )
23
- if name.to_s =~ /^[a-z]+$/
24
- target = name.to_s.upcase
25
- if Hornetseye.const_defined? target
26
- target = Hornetseye.const_get target
27
- if target.is_a? Class and target < Element
28
- new target, *args
29
- else
30
- super name, *args
31
- end
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
- def method_missing( name, *args )
49
- if name.to_s =~ /^to_[a-z]+$/
50
- target = name.to_s[ 3 .. -1 ].upcase
51
- if Hornetseye.const_defined? target
52
- target = Hornetseye.const_get target
53
- if target.is_a? Class and target < Element
54
- to_type target, *args
55
- else
56
- super target, *args
57
- end
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 }
@@ -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
@@ -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
- - 3
9
- version: 0.11.3
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-10-28 00:00:00 +01:00
17
+ date: 2010-11-18 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency