mdarray 0.5.0.pre-java → 0.5.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/README.md +89 -90
  2. data/Rakefile +6 -1
  3. data/lib/colt/cern_double_functions.rb +193 -0
  4. data/lib/colt/cern_float_functions.rb +193 -0
  5. data/lib/colt/cern_int_functions.rb +152 -0
  6. data/lib/colt/cern_long_functions.rb +152 -0
  7. data/lib/colt/colt.rb +103 -1
  8. data/lib/mdarray.rb +71 -23
  9. data/lib/mdarray/access.rb +8 -0
  10. data/lib/mdarray/counter.rb +43 -1
  11. data/lib/mdarray/creation.rb +5 -10
  12. data/lib/mdarray/fast_operators.rb +17 -13
  13. data/lib/mdarray/function_creation.rb +11 -45
  14. data/lib/mdarray/function_map.rb +16 -8
  15. data/lib/mdarray/lazy_mdarray.rb +311 -0
  16. data/lib/mdarray/lazy_operators.rb +166 -0
  17. data/lib/mdarray/operators.rb +38 -9
  18. data/lib/mdarray/proc_util.rb +2 -0
  19. data/lib/mdarray/ruby_boolean_functions.rb +24 -0
  20. data/lib/mdarray/ruby_functions.rb +76 -2
  21. data/lib/mdarray/ruby_generic_functions.rb +12 -4
  22. data/lib/mdarray/ruby_math.rb +180 -2
  23. data/lib/mdarray/ruby_numeric_functions.rb +198 -7
  24. data/target/helper.jar +0 -0
  25. data/test/colt/ColtMethods.xlsx +0 -0
  26. data/test/colt/test_complete.rb +1 -0
  27. data/test/colt/test_math.rb +249 -0
  28. data/test/complete.rb +1 -0
  29. data/test/env.rb +17 -4
  30. data/test/mdarray/arithmetic_casting.rb +3 -0
  31. data/test/mdarray/test_boolean.rb +1 -1
  32. data/test/mdarray/test_complete.rb +1 -0
  33. data/test/mdarray/test_error.rb +13 -13
  34. data/test/mdarray/test_lazy.rb +306 -0
  35. data/test/mdarray/test_operator.rb +1 -1
  36. data/test/mdarray/test_performance.rb +57 -4
  37. data/test/mdarray/test_trigonometry.rb +5 -1
  38. data/vendor/commons-compiler.jar +0 -0
  39. data/vendor/janino.jar +0 -0
  40. data/version.rb +1 -1
  41. metadata +47 -10
  42. data/test/mdarray/test_statistics.rb +0 -80
@@ -0,0 +1,152 @@
1
+ # -*- coding: utf-8 -*-
2
+ ##########################################################################################
3
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
4
+ # and distribute this software and its documentation for educational, research, and
5
+ # not-for-profit purposes, without fee and without a signed licensing agreement, is hereby
6
+ # granted, provided that the above copyright notice, this paragraph and the following two
7
+ # paragraphs appear in all copies, modifications, and distributions. Contact Rodrigo
8
+ # Botafogo - rodrigo.a.botafogo@gmail.com for commercial licensing opportunities.
9
+ #
10
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
11
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
12
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
13
+ # POSSIBILITY OF SUCH DAMAGE.
14
+ #
15
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
17
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
18
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
19
+ # OR MODIFICATIONS.
20
+ ##########################################################################################
21
+
22
+ require 'java'
23
+
24
+ ##########################################################################################
25
+ #
26
+ ##########################################################################################
27
+
28
+ class Java::CernJetMathTint::IntFunctions
29
+ include_package "cern.jet.math.tint"
30
+
31
+ cern_methods = [:abs, :compare, :div, :divNeg, :equals, :isEqual, :isGreater, :isLess,
32
+ :max, :min, :minus, :mod, :mult, :multNeg, :multSquare, :neg, :plus,
33
+ :plusAbs, :pow, :sign, :square,
34
+ :and, :dec, :factorial, :inc, :not, :or, :shiftLeft,
35
+ :shiftRightSigned, :shiftRightUnsigned, :xor]
36
+
37
+ # methods that also exist for types double and float
38
+ java_alias :unary_compare, :compare, [Java::int]
39
+ java_alias :unary_div, :div, [Java::int]
40
+ java_alias :unary_equals, :equals, [Java::int]
41
+ java_alias :unary_isEqual, :isEqual, [Java::int]
42
+ java_alias :unary_isGreater, :isGreater, [Java::int]
43
+ java_alias :unary_isLess, :isLess, [Java::int]
44
+ java_alias :unary_max, :max, [Java::int]
45
+ java_alias :unary_min, :min, [Java::int]
46
+ java_alias :unary_minus, :minus, [Java::int]
47
+ java_alias :unary_mod, :mod, [Java::int]
48
+ java_alias :unary_mult, :mult, [Java::int]
49
+ java_alias :unary_plus, :plus, [Java::int]
50
+ java_alias :unary_pow, :pow, [Java::int]
51
+
52
+ # methods that only exist for types long and int
53
+ java_alias :unary_and, :and, [Java::int]
54
+ java_alias :unary_or, :or, [Java::int]
55
+ java_alias :unary_shiftLeft, :shiftLeft, [Java::int]
56
+ java_alias :unary_shiftRightSigned, :shiftRightSigned, [Java::int]
57
+ java_alias :unary_shiftRightUnsigned, :shiftRightUnsigned, [Java::int]
58
+ java_alias :unary_xor, :xor, [Java::int]
59
+
60
+
61
+ cern_methods.each do |method|
62
+ field_reader(method)
63
+ attr_reader(":#{method}")
64
+ end
65
+
66
+ end
67
+
68
+ ##########################################################################################
69
+ #
70
+ ##########################################################################################
71
+
72
+ module CernIntFunctions
73
+ include_package "cern.jet.math.tint"
74
+ extend FunctionCreation
75
+ extend CernFunctions
76
+
77
+ binary_methods = [:compare, :div, :divNeg, :equals, :minus, :mod, :mult, :multNeg,
78
+ :multSquare, :plus, :plusAbs, :pow,
79
+ :and, :or, :shiftLeft, :shiftRightSigned, :shiftRightUnsigned, :xor]
80
+
81
+ unary_methods = [:abs, :neg, :sign, :square, :dec, :factorial, :inc, :not]
82
+
83
+ comparison_methods = [:isEqual, :isGreater, :isLess]
84
+
85
+ binary_conflict_methods = [:max, :min]
86
+
87
+ binary_methods.each do |method|
88
+ make_binary_operators(method.to_s,
89
+ cern_binary_function(method.to_s, "#{method}_int",
90
+ Java::CernJetMathTint.IntFunctions,
91
+ "int"))
92
+ end
93
+
94
+ unary_methods.each do |method|
95
+ make_unary_operators(method.to_s,
96
+ cern_unary_function(method.to_s, "#{method}_int",
97
+ Java::CernJetMathTint.IntFunctions,
98
+ "int"))
99
+ end
100
+
101
+ comparison_methods.each do |method|
102
+ make_comparison_operator(method.to_s,
103
+ cern_comparison_function(method.to_s, "#{method}_double",
104
+ Java::CernJetMathTint.IntFunctions,
105
+ "int"))
106
+ end
107
+
108
+ binary_conflict_methods.each do |method|
109
+ make_binary_operators("cern_#{method}",
110
+ cern_binary_function(method.to_s, "cern_#{method}_double",
111
+ Java::CernJetMathTint.IntFunctions,
112
+ "int"))
113
+ end
114
+
115
+ def self.register(als, name, int_name, type)
116
+ map = cern_binary_function(name, int_name, Java::CernJetMathTint.IntFunctions,
117
+ type)
118
+ MDArray.register_function(als, map, 2, CernFunctions.binary_helper)
119
+ end
120
+
121
+ alias :div_neg :divNeg
122
+ alias :is_equal :isEqual
123
+ alias :is_greater :isGreater
124
+ alias :is_less :isLess
125
+ alias :mult_neg :multNeg
126
+ alias :mult_square :multSquare
127
+ alias :plus_abs :plusAbs
128
+ alias :shift_left :shiftLeft
129
+ alias :shift_right_signed :shiftRightSigned
130
+ alias :shift_right_unsigned :shiftRightUnsigned
131
+
132
+ register(:add, :plus, :plus_int, "int")
133
+ register(:sub, :minus, :minus_int, "int")
134
+ register(:mul, :mult, :mult_int, "int")
135
+ register(:power, :pow, :pow_int, "int")
136
+ register(:eq, :equals, :equals_int, "int")
137
+ register(:gt, :isGreater, :is_greater_int, "int")
138
+ register(:lt, :isLess, :is_less_int, "int")
139
+ register(:binary_left_shift, :shiftLeft, :shift_left_int, "int")
140
+ register(:binary_right_shift, :shiftRightSigned, :shift_right_int, "int")
141
+
142
+ end
143
+
144
+ ##########################################################################################
145
+ #
146
+ ##########################################################################################
147
+
148
+ class IntMDArray
149
+
150
+ include CernIntFunctions
151
+
152
+ end # IntMDArray
@@ -0,0 +1,152 @@
1
+ # -*- coding: utf-8 -*-
2
+ ##########################################################################################
3
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
4
+ # and distribute this software and its documentation for educational, research, and
5
+ # not-for-profit purposes, without fee and without a signed licensing agreement, is hereby
6
+ # granted, provided that the above copyright notice, this paragraph and the following two
7
+ # paragraphs appear in all copies, modifications, and distributions. Contact Rodrigo
8
+ # Botafogo - rodrigo.a.botafogo@gmail.com for commercial licensing opportunities.
9
+ #
10
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
11
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
12
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
13
+ # POSSIBILITY OF SUCH DAMAGE.
14
+ #
15
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
17
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
18
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
19
+ # OR MODIFICATIONS.
20
+ ##########################################################################################
21
+
22
+ require 'java'
23
+
24
+ ##########################################################################################
25
+ #
26
+ ##########################################################################################
27
+
28
+ class Java::CernJetMathTlong::LongFunctions
29
+ include_package "cern.jet.math.tlong"
30
+
31
+ cern_methods = [:abs, :compare, :div, :divNeg, :equals, :isEqual, :isGreater, :isLess,
32
+ :max, :min, :minus, :mod, :mult, :multNeg, :multSquare, :neg, :plus,
33
+ :plusAbs, :pow, :sign, :square,
34
+ :and, :dec, :factorial, :inc, :not, :or, :shiftLeft,
35
+ :shiftRightSigned, :shiftRightUnsigned, :xor]
36
+
37
+ # methods that also exist for types double and float
38
+ java_alias :unary_compare, :compare, [Java::long]
39
+ java_alias :unary_div, :div, [Java::long]
40
+ java_alias :unary_equals, :equals, [Java::long]
41
+ java_alias :unary_isEqual, :isEqual, [Java::long]
42
+ java_alias :unary_isGreater, :isGreater, [Java::long]
43
+ java_alias :unary_isLess, :isLess, [Java::long]
44
+ java_alias :unary_max, :max, [Java::long]
45
+ java_alias :unary_min, :min, [Java::long]
46
+ java_alias :unary_minus, :minus, [Java::long]
47
+ java_alias :unary_mod, :mod, [Java::long]
48
+ java_alias :unary_mult, :mult, [Java::long]
49
+ java_alias :unary_plus, :plus, [Java::long]
50
+ java_alias :unary_pow, :pow, [Java::long]
51
+
52
+ # methods that only exist for types long and int
53
+ java_alias :unary_and, :and, [Java::long]
54
+ java_alias :unary_or, :or, [Java::long]
55
+ java_alias :unary_shiftLeft, :shiftLeft, [Java::long]
56
+ java_alias :unary_shiftRightSigned, :shiftRightSigned, [Java::long]
57
+ java_alias :unary_shiftRightUnsigned, :shiftRightUnsigned, [Java::long]
58
+ java_alias :unary_xor, :xor, [Java::long]
59
+
60
+
61
+ cern_methods.each do |method|
62
+ field_reader(method)
63
+ attr_reader(":#{method}")
64
+ end
65
+
66
+ end
67
+
68
+ ##########################################################################################
69
+ #
70
+ ##########################################################################################
71
+
72
+ module CernLongFunctions
73
+ include_package "cern.jet.math.tlong"
74
+ extend FunctionCreation
75
+ extend CernFunctions
76
+
77
+ binary_methods = [:compare, :div, :divNeg, :equals, :minus, :mod, :mult, :multNeg,
78
+ :multSquare, :plus, :plusAbs, :pow,
79
+ :and, :or, :shiftLeft, :shiftRightSigned, :shiftRightUnsigned, :xor]
80
+
81
+ unary_methods = [:abs, :neg, :sign, :square, :dec, :factorial, :inc, :not]
82
+
83
+ comparison_methods = [:isEqual, :isGreater, :isLess]
84
+
85
+ binary_conflict_methods = [:max, :min]
86
+
87
+ binary_methods.each do |method|
88
+ make_binary_operators(method.to_s,
89
+ cern_binary_function(method.to_s, "#{method}_long",
90
+ Java::CernJetMathTlong.LongFunctions,
91
+ "long"))
92
+ end
93
+
94
+ unary_methods.each do |method|
95
+ make_unary_operators(method.to_s,
96
+ cern_unary_function(method.to_s, "#{method}_long",
97
+ Java::CernJetMathTlong.LongFunctions,
98
+ "long"))
99
+ end
100
+
101
+ comparison_methods.each do |method|
102
+ make_comparison_operator(method.to_s,
103
+ cern_comparison_function(method.to_s, "#{method}_double",
104
+ Java::CernJetMathTlong.LongFunctions,
105
+ "long"))
106
+ end
107
+
108
+ binary_conflict_methods.each do |method|
109
+ make_binary_operators("cern_#{method}",
110
+ cern_binary_function(method.to_s, "cern_#{method}_double",
111
+ Java::CernJetMathTlong.LongFunctions,
112
+ "long"))
113
+ end
114
+
115
+ def self.register(als, name, long_name, type)
116
+ map = cern_binary_function(name, long_name, Java::CernJetMathTlong.LongFunctions,
117
+ type)
118
+ MDArray.register_function(als, map, 2, CernFunctions.binary_helper)
119
+ end
120
+
121
+ alias :div_neg :divNeg
122
+ alias :is_equal :isEqual
123
+ alias :is_greater :isGreater
124
+ alias :is_less :isLess
125
+ alias :mult_neg :multNeg
126
+ alias :mult_square :multSquare
127
+ alias :plus_abs :plusAbs
128
+ alias :shift_left :shiftLeft
129
+ alias :shift_right_signed :shiftRightSigned
130
+ alias :shift_right_unsigned :shiftRightUnsigned
131
+
132
+ register(:add, :plus, :plus_long, "long")
133
+ register(:sub, :minus, :minus_long, "long")
134
+ register(:mul, :mult, :mult_long, "long")
135
+ register(:power, :pow, :pow_long, "long")
136
+ register(:eq, :equals, :equals_long, "long")
137
+ register(:gt, :isGreater, :is_greater_long, "long")
138
+ register(:lt, :isLess, :is_less_long, "long")
139
+ register(:binary_left_shift, :shiftLeft, :shift_left_long, "long")
140
+ register(:binary_right_shift, :shiftRightSigned, :shift_right_long, "long")
141
+
142
+ end
143
+
144
+ ##########################################################################################
145
+ #
146
+ ##########################################################################################
147
+
148
+ class LongMDArray
149
+
150
+ include CernLongFunctions
151
+
152
+ end # LongMDArray
data/lib/colt/colt.rb CHANGED
@@ -49,8 +49,110 @@ class Colt
49
49
 
50
50
  end # Colt
51
51
 
52
+ ##########################################################################################
53
+ #
54
+ ##########################################################################################
55
+
56
+ module CernFunctions
57
+
58
+ class << self
59
+ attr_reader :binary_helper
60
+ attr_reader :unary_helper
61
+ end
62
+
63
+ @binary_helper = Java::RbMdarrayLoopsBinops
64
+ @unary_helper = Java::RbMdarrayLoopsUnops
65
+
66
+ #------------------------------------------------------------------------------------
67
+ #
68
+ #------------------------------------------------------------------------------------
69
+
70
+ def make_binary_operators(name, func, default = true, in_place = true)
71
+
72
+ if (default)
73
+ make_binary_op(name, :default, func, CernFunctions.binary_helper)
74
+ end
75
+ if (in_place)
76
+ make_binary_op(name + "!", :in_place, func, CernFunctions.binary_helper)
77
+ end
78
+
79
+ end
80
+
81
+ #------------------------------------------------------------------------------------
82
+ #
83
+ #------------------------------------------------------------------------------------
84
+
85
+ def make_binary_operator(name, type, func)
86
+ make_binary_op(name, type, func, CernFunctions.binary_helper)
87
+ end
88
+
89
+ #------------------------------------------------------------------------------------
90
+ #
91
+ #------------------------------------------------------------------------------------
92
+
93
+ def make_unary_operators(name, func, default = true, in_place = true)
94
+
95
+ if (default)
96
+ make_unary_op(name, :default, func, CernFunctions.unary_helper)
97
+ end
98
+ if (in_place)
99
+ make_unary_op(name + "!", :in_place, func, CernFunctions.unary_helper)
100
+ end
101
+
102
+ end
103
+
104
+ #------------------------------------------------------------------------------------
105
+ #
106
+ #------------------------------------------------------------------------------------
107
+
108
+ def make_unary_operator(name, type, func)
109
+ make_unary_op(name, type, func, CernFunctions.unary_helper)
110
+ end
111
+
112
+ #------------------------------------------------------------------------------------
113
+ #
114
+ #------------------------------------------------------------------------------------
115
+
116
+ def make_comparison_operator(name, func)
117
+ make_binary_op(name, "default", func, CernFunctions.binary_helper, "boolean")
118
+ end
119
+
120
+ #------------------------------------------------------------------------------------
121
+ #
122
+ #------------------------------------------------------------------------------------
123
+
124
+ def cern_binary_function(short_name, long_name, module_name, type)
125
+ [long_name, "CernFunctions", module_name.send(short_name), type, type, type]
126
+ end
127
+
128
+ #------------------------------------------------------------------------------------
129
+ #
130
+ #------------------------------------------------------------------------------------
131
+
132
+ def cern_unary_function(short_name, long_name, module_name, type)
133
+ [long_name, "CernFunctions", module_name.send(short_name), type, type, "void"]
134
+ end
135
+
136
+ #------------------------------------------------------------------------------------
137
+ #
138
+ #------------------------------------------------------------------------------------
139
+
140
+ def cern_comparison_function(short_name, long_name, module_name, type)
141
+ [long_name, "CernFunctions", module_name.send(short_name), "boolean", type, type]
142
+ end
143
+
144
+ end # CernFunctions
145
+
146
+ ##########################################################################################
147
+ #
148
+ ##########################################################################################
149
+
52
150
  require_relative 'stat_list'
53
151
  require_relative 'colt_mdarray'
152
+ require_relative 'cern_double_functions'
153
+ require_relative 'cern_float_functions'
154
+ require_relative 'cern_long_functions'
155
+ require_relative 'cern_int_functions'
54
156
 
55
- # MDArray.functions = "CernFunctions"
157
+ MDArray.functions = "CernFunctions"
56
158
 
data/lib/mdarray.rb CHANGED
@@ -77,19 +77,22 @@ class MDArray
77
77
  attr_accessor :unary_operator
78
78
  attr_accessor :coerced
79
79
 
80
- @numerical = ["byte", "short", "int", "long", "float", "double"]
80
+ @numerical = ["numeric", "byte", "short", "int", "long", "float", "double"]
81
81
  @non_numerical = ["boolean", "char", "string", "sequence"]
82
82
 
83
83
  class << self
84
84
 
85
85
  attr_accessor :functions
86
86
  attr_accessor :function_map
87
-
88
87
  attr_reader :numerical
89
88
  attr_reader :non_numerical
90
-
89
+ attr_accessor :binary_operator
90
+ attr_accessor :unary_operator
91
+ attr_accessor :previous_binary_operator
92
+ attr_accessor :previous_unary_operator
93
+
91
94
  end
92
-
95
+
93
96
  MDArray.function_map = Map.new
94
97
 
95
98
  #------------------------------------------------------------------------------------
@@ -214,7 +217,7 @@ class MDArray
214
217
 
215
218
  value.each do |func|
216
219
 
217
- p "scope: #{func.scope}, short name: #{key}, long name: #{func.long_name}, return type: #{func.return_type}, input1 type: #{func.input1_type}, input2 type: #{func.input2_type}"
220
+ p "package: #{func.package}, short name: #{key}, long name: #{func.long_name}, return type: #{func.return_type}, input1 type: #{func.input1_type}, input2 type: #{func.input2_type}"
218
221
 
219
222
  end
220
223
 
@@ -255,16 +258,20 @@ class MDArray
255
258
  # @param post_condition Proc to be executed after the operator's execution
256
259
  #------------------------------------------------------------------------------------
257
260
 
258
- def self.make_binary_op(name, exec_type, func, force_type = nil, pre_condition = nil,
259
- post_condition = nil)
261
+ def self.make_binary_op(name, exec_type, func, helper_class, force_type = nil,
262
+ pre_condition = nil, post_condition = nil)
260
263
 
261
264
  define_method(name) do |op2, requested_type = nil, *args|
262
- binary_op = get_binary_op
265
+ if (@type == "lazy" || ((op2.is_a? MDArray) && op2.type == "lazy"))
266
+ binary_op = LazyBinaryOperator
267
+ else
268
+ binary_op = get_binary_op
269
+ end
263
270
  op = binary_op.new(name, exec_type, force_type, pre_condition, post_condition)
264
271
  op.exec(self, op2, requested_type, *args)
265
272
  end
266
273
 
267
- MDArray.register_function(name, func)
274
+ MDArray.register_function(name, func, 2, helper_class)
268
275
 
269
276
  end
270
277
 
@@ -284,8 +291,8 @@ class MDArray
284
291
  # @param post_condition Proc to be executed after the operator's execution
285
292
  #------------------------------------------------------------------------------------
286
293
 
287
- def self.make_unary_op(name, exec_type, func, force_type = nil, pre_condition = nil,
288
- post_condition = nil)
294
+ def self.make_unary_op(name, exec_type, func, helper_class, force_type = nil,
295
+ pre_condition = nil, post_condition = nil)
289
296
 
290
297
  define_method(name) do |requested_type = nil, *args|
291
298
  unary_op = get_unary_op
@@ -293,7 +300,23 @@ class MDArray
293
300
  op.exec(self, requested_type, *args)
294
301
  end
295
302
 
296
- MDArray.register_function(name, func)
303
+ MDArray.register_function(name, func, 1, helper_class)
304
+
305
+ end
306
+
307
+ #---------------------------------------------------------------------------------------
308
+ #
309
+ #---------------------------------------------------------------------------------------
310
+
311
+ def self.calc_value(given_type, function_type, match, partial_match, no_match)
312
+
313
+ if (given_type == function_type)
314
+ match
315
+ elsif ((function_type == "*") || (given_type == "*"))
316
+ partial_match
317
+ else
318
+ no_match
319
+ end
297
320
 
298
321
  end
299
322
 
@@ -311,28 +334,52 @@ class MDArray
311
334
  # @param input2_type the type of the second argument to the function
312
335
  #---------------------------------------------------------------------------------------
313
336
 
314
- def self.select_function(name, scope = nil, return_type = nil, input1_type = nil,
337
+ def self.select_function(name, package = nil, return_type = nil, input1_type = nil,
315
338
  input2_type = nil)
316
339
 
340
+
341
+ =begin
342
+ p "selecting function: #{name}"
343
+ p "return_type: #{return_type}"
344
+ p "input1_type: #{input1_type}"
345
+ p "input2_type: #{input2_type}"
346
+ =end
347
+
317
348
  list = MDArray.function_map[name]
318
349
  best_value = -1
319
350
  func = nil
320
351
 
321
352
  list.each do |function|
322
-
323
- value = 0
324
- value += (scope == function.scope)? 8 : 0
325
- value += (return_type == function.return_type)? 4 : 0
326
- value += (input1_type == function.input1_type)? 2 : 0
327
- value += (input2_type == function.input2_type)? 1 : 0
328
- if (value > best_value)
329
- func = function.function
353
+ value = (package == function.package)? 2 : 1
354
+ # p "package: #{package}; function package: #{function.package}"
355
+ # p value
356
+ value *= calc_value(return_type, function.return_type, 32, 16, 0)
357
+ # p "return_type: #{return_type}; func_ret_type: #{function.return_type}"
358
+ # p value
359
+ value *= calc_value(input1_type, function.input1_type, 8, 4, 0)
360
+ # p "input1_type: #{input1_type}; func_input1_type: #{function.input1_type}"
361
+ # p value
362
+ value *= calc_value(input2_type, function.input2_type, 2, 1, 0)
363
+ # p "input2_type: #{input2_type}; func_input2_type: #{function.input2_type}"
364
+ # p value
365
+ if (value == 0)
366
+ next
367
+ elsif (value > best_value)
368
+ func = function
330
369
  best_value = value
331
- # p "best value: #{best_value}, func: #{func}"
332
370
  end
333
371
  end
334
372
 
335
- func
373
+ =begin
374
+ p "MDArray.select_function"
375
+ p "selected function #{func.function}"
376
+ =end
377
+
378
+ if (best_value > 0)
379
+ func
380
+ else
381
+ raise "No method to process operator: #{name}"
382
+ end
336
383
 
337
384
  end
338
385
 
@@ -385,5 +432,6 @@ require_relative 'mdarray/views'
385
432
  require_relative 'mdarray/printing'
386
433
  require_relative 'mdarray/counter'
387
434
  require_relative 'mdarray/ruby_stats'
435
+ require_relative 'mdarray/lazy_mdarray'
388
436
  require_relative 'mdarray/csv'
389
437
  require_relative 'colt/colt'