mdarray 0.5.0.pre-java → 0.5.3-java

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.
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
@@ -5,10 +5,118 @@
5
5
 
6
6
  module NumericFunctions
7
7
  include_package "ucar.ma2.MAMath"
8
-
9
8
  extend FunctionCreation
10
9
  extend RubyFunctions
11
10
 
11
+ class Add
12
+ def self.apply(val1, val2)
13
+ val1 + val2
14
+ end
15
+ end
16
+
17
+ class Sub
18
+ def self.apply(val1, val2)
19
+ val1 - val2
20
+ end
21
+ end
22
+
23
+ class Mul
24
+ def self.apply(val1, val2)
25
+ val1 * val2
26
+ end
27
+ end
28
+
29
+ class Div
30
+ def self.apply(val1, val2)
31
+ val1 / val2
32
+ end
33
+ end
34
+
35
+ class Power
36
+ def self.apply(val1, val2)
37
+ val1 ** val2
38
+ end
39
+ end
40
+
41
+ class Abs
42
+ def self.apply(val)
43
+ val.abs
44
+ end
45
+ end
46
+
47
+ class Ceil
48
+ def self.apply(val)
49
+ val.ceil
50
+ end
51
+ end
52
+
53
+ class Floor
54
+ def self.apply(val)
55
+ val.floor
56
+ end
57
+ end
58
+
59
+ class Truncate
60
+ def self.apply(val)
61
+ val.truncate
62
+ end
63
+ end
64
+
65
+ class IsZero
66
+ def self.apply(val)
67
+ val.zero
68
+ end
69
+ end
70
+
71
+ class Square
72
+ def self.apply(val)
73
+ val * val
74
+ end
75
+ end
76
+
77
+ class Cube
78
+ def self.apply(val)
79
+ val1 * val * val
80
+ end
81
+ end
82
+
83
+ class Fourth
84
+ def self.apply(val)
85
+ val * val * val * val
86
+ end
87
+ end
88
+
89
+ class Min
90
+ def self.apply(val1, val2)
91
+ val1 < val2 ? val1 : val2
92
+ end
93
+ end
94
+
95
+ class Max
96
+ def self.apply(val1, val2)
97
+ val1 > val2 ? val1 : val2
98
+ end
99
+ end
100
+
101
+ @add = NumericFunctions::Add
102
+ @sub = NumericFunctions::Sub
103
+ @mul = NumericFunctions::Mul
104
+ @div = NumericFunctions::Div
105
+ @power = NumericFunctions::Power
106
+ @abs = NumericFunctions::Abs
107
+ @ceil = NumericFunctions::Ceil
108
+ @floor = NumericFunctions::Floor
109
+ @truncate = NumericFunctions::Truncate
110
+ @is_zero = NumericFunctions::IsZero
111
+ @square = NumericFunctions::Square
112
+ @cube = NumericFunctions::Cube
113
+ @fourth = NumericFunctions::Fourth
114
+ @min = NumericFunctions::Min
115
+ @max = NumericFunctions::Max
116
+
117
+ =begin
118
+ Using Proc is much more inefficient than using classes as defined above
119
+
12
120
  @add = Proc.new { |val1, val2| val1 + val2 }
13
121
  @sub = Proc.new { |val1, val2| val1 - val2 }
14
122
  @mul = Proc.new { |val1, val2| val1 * val2 }
@@ -25,7 +133,8 @@ module NumericFunctions
25
133
 
26
134
  @min = Proc.new { |val1, val2| val1 < val2 ? val1 : val2 }
27
135
  @max = Proc.new { |val1, val2| val1 > val2 ? val1 : val2 }
28
-
136
+ =end
137
+
29
138
  #---------------------------------------------------------------------------------------
30
139
  #
31
140
  #---------------------------------------------------------------------------------------
@@ -92,18 +201,56 @@ module ComparisonOperators
92
201
  extend FunctionCreation
93
202
  extend RubyFunctions
94
203
 
204
+ class Ge
205
+ def self.apply(val1, val2)
206
+ val1 >= val2 ? true : false
207
+ end
208
+ end
209
+
210
+ class Gt
211
+ def self.apply(val1, val2)
212
+ val1 > val2 ? true : false
213
+ end
214
+ end
215
+
216
+ class Le
217
+ def self.apply(val1, val2)
218
+ val1 <= val2 ? true : false
219
+ end
220
+ end
221
+
222
+ class Lt
223
+ def self.apply(val1, val2)
224
+ val1 < val2 ? true : false
225
+ end
226
+ end
227
+
228
+ class Eq
229
+ def self.apply(val1, val2)
230
+ val1 == val2 ? true : false
231
+ end
232
+ end
233
+
234
+ @ge = ComparisonOperators::Ge
235
+ @gt = ComparisonOperators::Gt
236
+ @le = ComparisonOperators::Le
237
+ @lt = ComparisonOperators::Lt
238
+ @eq = ComparisonOperators::Eq
239
+
240
+ =begin
95
241
  @ge = Proc.new { |val1, val2| val1 >= val2 ? true : false}
96
242
  @gt = Proc.new { |val1, val2| val1 > val2 ? true : false}
97
243
  @le = Proc.new { |val1, val2| val1 <= val2 ? true : false}
98
244
  @lt = Proc.new { |val1, val2| val1 < val2 ? true : false}
99
245
  @eq = Proc.new { |val1, val2| val1 == val2 ? true : false}
246
+ =end
100
247
 
101
248
  @binary_methods = [:ge, :gt, :le, :lt, :eq]
102
249
 
103
250
  @binary_methods.each do |method|
104
- make_comparison_op(method.to_s,
105
- ruby_binary_function("#{method.to_s}_ruby",
106
- instance_variable_get("@#{method.to_s}")))
251
+ make_comparison_operator(method.to_s,
252
+ ruby_binary_function("#{method.to_s}_ruby",
253
+ instance_variable_get("@#{method.to_s}")))
107
254
  end
108
255
 
109
256
  alias :>= :ge
@@ -122,14 +269,58 @@ module BitwiseOperators
122
269
  extend FunctionCreation
123
270
  extend RubyFunctions
124
271
 
272
+ class BinaryAnd
273
+ def self.apply(val1, val2)
274
+ val1 & val2
275
+ end
276
+ end
277
+
278
+ class BinaryOr
279
+ def self.apply(val1, val2)
280
+ val1 | val2
281
+ end
282
+ end
283
+
284
+ class BinaryXor
285
+ def self.apply(val1, val2)
286
+ val1 ^ val2
287
+ end
288
+ end
289
+
290
+ class BinaryLeftShift
291
+ def self.apply(val1, val2)
292
+ val1 << val2
293
+ end
294
+ end
295
+
296
+ class BinaryRightShift
297
+ def self.apply(val1, val2)
298
+ val1 >> val2
299
+ end
300
+ end
301
+
302
+ class BinaryOnesComplement
303
+ def self.apply(val)
304
+ ~val1
305
+ end
306
+ end
307
+
308
+ @binary_and = BitwiseOperators::BinaryAnd
309
+ @binary_or = BitwiseOperators::BinaryOr
310
+ @binary_xor = BitwiseOperators::BinaryXor
311
+ @binary_left_shift = BitwiseOperators::BinaryLeftShift
312
+ @binary_right_shift = BitwiseOperators::BinaryRightShift
313
+ @binary_ones_complement = BitwiseOperators::BinaryOnesComplement
314
+
315
+ =begin
125
316
  @binary_and = Proc.new { |val1, val2| val1 & val2 }
126
317
  @binary_or = Proc.new { |val1, val2| val1 | val2 }
127
318
  @binary_xor = Proc.new { |val1, val2| val1 ^ val2 }
128
319
  @binary_left_shift = Proc.new { |val1, val2| val1 << val2 }
129
320
  @binary_right_shift = Proc.new { |val1, val2| val1 >> val2 }
130
-
131
321
  @binary_ones_complement = Proc.new { |val| ~val }
132
-
322
+ =end
323
+
133
324
  #---------------------------------------------------------------------------------------
134
325
  #
135
326
  #---------------------------------------------------------------------------------------
data/target/helper.jar CHANGED
Binary file
Binary file
@@ -22,4 +22,5 @@
22
22
  #=begin
23
23
  require_relative 'test_statistics'
24
24
  require_relative 'test_stat_list'
25
+ require_relative 'test_math'
25
26
  #=end
@@ -0,0 +1,249 @@
1
+ require 'rubygems'
2
+ require "test/unit"
3
+ require 'shoulda'
4
+
5
+ require 'mdarray'
6
+
7
+ class MDArrayTest < Test::Unit::TestCase
8
+
9
+ context "Colt Functions Tests" do
10
+
11
+ setup do
12
+
13
+ @byte = MDArray.typed_arange("byte", 1, 10)
14
+ @short = MDArray.typed_arange("short", 1, 10)
15
+ @int = MDArray.typed_arange("int", 1, 10)
16
+ @long = MDArray.typed_arange("long", 1, 10)
17
+ @float = MDArray.typed_arange("float", 1, 10)
18
+ @double = MDArray.linspace("double", 0, 1, 10)
19
+
20
+ end
21
+
22
+ #-------------------------------------------------------------------------------------
23
+ #
24
+ #-------------------------------------------------------------------------------------
25
+ =begin
26
+ should "math operations with colt methods" do
27
+
28
+ @byte + @short
29
+ @double + @double
30
+ @double * @double
31
+ @double * @int
32
+ @double - @double
33
+ @double - @byte
34
+ @int - @int
35
+ @int - @double
36
+
37
+ end
38
+ =end
39
+ #-------------------------------------------------------------------------------------
40
+ #
41
+ #-------------------------------------------------------------------------------------
42
+
43
+ should "work with Parallel Colt double methods" do
44
+
45
+ p "testing Parallel Colt double methods"
46
+
47
+ (@double.abs).print
48
+ (@double.acos).print
49
+ (@double.asin).print
50
+ (@double.atan).print
51
+ (@double.atan2(@double)).print
52
+ (@double.ceil).print
53
+ (@double.compare(@double)).print
54
+ @double.cos
55
+ @double.div(@double)
56
+ @double.div_neg(@double)
57
+ @double.equals(@double)
58
+ @double.exp
59
+ @double.floor
60
+ @double.greater(@double)
61
+ @double.identity
62
+ @double.ieee_remainder(@double)
63
+ @double.inv
64
+ @double.is_equal(@double)
65
+ @double == @double
66
+ @double.is_less(@double)
67
+ @double < @double
68
+ @double.is_greater(@double)
69
+ @double > @double
70
+ @double.less(@double)
71
+ @double.lg(@double)
72
+ @double.log
73
+ @double.cern_log2
74
+ @double.minus(@double)
75
+ @double - @double
76
+ @double.mod(@double)
77
+ @double * @double
78
+ @double.mult_neg(@double)
79
+ @double.mult_square(@double)
80
+ @double.neg
81
+ @double + @double
82
+ @double.plus_abs(@double)
83
+ @double.pow(@double)
84
+ @double.rint
85
+ @double.sign
86
+ @double.sin
87
+ @double.sqrt
88
+ @double.square
89
+ @double.tan
90
+
91
+ end
92
+
93
+ #-------------------------------------------------------------------------------------
94
+ #
95
+ #-------------------------------------------------------------------------------------
96
+
97
+ should "work with Parallel Colt float methods" do
98
+
99
+ p "testing Parallel Colt float methods"
100
+
101
+ (@float.abs).print
102
+ (@float.acos).print
103
+ (@float.asin).print
104
+ (@float.atan).print
105
+ (@float.atan2(@float)).print
106
+ (@float.ceil).print
107
+ (@float.compare(@float)).print
108
+ @float.cos
109
+ @float.div(@float)
110
+ @float.div_neg(@float)
111
+ @float.equals(@float)
112
+ @float.exp
113
+ @float.floor
114
+ @float.greater(@float)
115
+ @float.identity
116
+ @float.ieee_remainder(@float)
117
+ @float.inv
118
+ @float.is_equal(@float)
119
+ @float == @float
120
+ @float.is_less(@float)
121
+ @float < @float
122
+ @float.is_greater(@float)
123
+ @float > @float
124
+ @float.less(@float)
125
+ @float.lg(@float)
126
+ @float.log
127
+ @float.cern_log2
128
+ @float.minus(@float)
129
+ @float - @float
130
+ @float.mod(@float)
131
+ @float * @float
132
+ @float.mult_neg(@float)
133
+ @float.mult_square(@float)
134
+ @float.neg
135
+ @float + @float
136
+ @float.plus_abs(@float)
137
+ @float.pow(@float)
138
+ @float.rint
139
+ @float.sign
140
+ @float.sin
141
+ @float.sqrt
142
+ @float.square
143
+ @float.tan
144
+
145
+ end
146
+
147
+ #-------------------------------------------------------------------------------------
148
+ #
149
+ #-------------------------------------------------------------------------------------
150
+
151
+ should "work with Parallel Colt long methods" do
152
+
153
+ p "testing Parallel Colt long methods"
154
+
155
+ (@long.abs).print
156
+ (@long.compare(@long)).print
157
+ @long.div(@long)
158
+ @long.div_neg(@long)
159
+ @long.equals(@long)
160
+ @long.is_equal(@long)
161
+ @long == @long
162
+ @long.is_less(@long)
163
+ @long < @long
164
+ @long.is_greater(@long)
165
+ @long > @long
166
+ @long.cern_max(@long)
167
+ @long.cern_min(@long)
168
+ @long.minus(@long)
169
+ @long - @long
170
+ @long.mod(@long)
171
+ @long * @long
172
+ @long.mult_neg(@long)
173
+ @long.mult_square(@long)
174
+ @long.neg
175
+ @long + @long
176
+ @long.plus(@long)
177
+ @long.plus_abs(@long)
178
+ @long.pow(@long)
179
+ @long.sign
180
+ @long.square
181
+
182
+ @long.and(@long)
183
+ @long.dec
184
+ @long.factorial
185
+ @long.inc
186
+ @long.not
187
+ @long.or(@long)
188
+ @long.shift_left(@long)
189
+ @long.shift_right_signed(@long)
190
+ @long.binary_right_shift(@long)
191
+ @long.binary_left_shift(@long)
192
+ @long.shift_right_unsigned(@long)
193
+ @long.xor(@long)
194
+
195
+ end
196
+
197
+ #-------------------------------------------------------------------------------------
198
+ #
199
+ #-------------------------------------------------------------------------------------
200
+
201
+ should "work with Parallel Colt int methods" do
202
+
203
+ p "testing Parallel Colt int methods"
204
+
205
+ (@int.abs).print
206
+ (@int.compare(@int)).print
207
+ @int.div(@int)
208
+ @int.div_neg(@int)
209
+ @int.equals(@int)
210
+ @int.is_equal(@int)
211
+ @int == @int
212
+ @int.is_less(@int)
213
+ @int < @int
214
+ @int.is_greater(@int)
215
+ @int > @int
216
+ @int.cern_max(@int)
217
+ @int.cern_min(@int)
218
+ @int.minus(@int)
219
+ @int - @int
220
+ @int.mod(@int)
221
+ @int * @int
222
+ @int.mult_neg(@int)
223
+ @int.mult_square(@int)
224
+ @int.neg
225
+ @int + @int
226
+ @int.plus(@int)
227
+ @int.plus_abs(@int)
228
+ @int.pow(@int)
229
+ @int.sign
230
+ @int.square
231
+
232
+ @int.and(@int)
233
+ @int.dec
234
+ @int.factorial
235
+ @int.inc
236
+ @int.not
237
+ @int.or(@int)
238
+ @int.shift_left(@int)
239
+ @int.shift_right_signed(@int)
240
+ @int.binary_right_shift(@int)
241
+ @int.binary_left_shift(@int)
242
+ @int.shift_right_unsigned(@int)
243
+ @int.xor(@int)
244
+
245
+ end
246
+
247
+ end
248
+
249
+ end