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
data/README.md CHANGED
@@ -1,90 +1,89 @@
1
- MDArray
2
- =======
3
-
4
- MDArray is a multi dimensional array implemented for JRuby inspired by NumPy (www.numpy.org)
5
- and Narray (narray.rubyforge.org) by Masahiro Tanaka. MDArray stands on the shoulders of
6
- Java-NetCDF and Parallel Colt.
7
-
8
- NetCDF-Java Library is a Java interface to NetCDF files, as well as to many other types of
9
- scientific data formats. It is developed and distributed by Unidata (http://www.unidata.ucar.edu).
10
-
11
- Parallel Colt (sites.google.com/site/piotrwendykier/software/parallelcolt) is a multithreaded
12
- version of Colt (http://acs.lbl.gov/software/colt/). Colt provides a set of Open Source
13
- Libraries for High Performance Scientific and Technical Computing in Java. Scientific
14
- and technical computing is characterized by demanding problem sizes and a need for high
15
- performance at reasonably small memory footprint.
16
-
17
- MDArray and SciRuby
18
- ===================
19
-
20
- MDArray subscribes fully to the SciRuby Manifesto (http://sciruby.com/).
21
-
22
- Ruby has for some time had no equivalent to the beautifully constructed NumPy, SciPy,
23
- and matplotlib libraries for Python.
24
-
25
- We believe that the time for a Ruby science and visualization package has come. Sometimes
26
- when a solution of sugar and water becomes super-saturated, from it precipitates a pure,
27
- delicious, and diabetes-inducing crystal of sweetness, induced by no more than the tap
28
- of a finger. So is occurring now, we believe, with numeric and visualization libraries for Ruby.”
29
-
30
- Main properties
31
- ===============
32
-
33
- + Homogeneous multidimensional array, a table of elements (usually numbers), all of the
34
- same type, indexed by a tuple of positive integers;
35
- + Easy calculation for large numerical multi dimensional arrays;
36
- + Basic types are: boolean, byte, short, int, long, float, double, string, structure;
37
- + Based on JRuby, which allows importing Java libraries. Version 0.4.0 only imports
38
- Java-NetCDF;
39
- + Operator: +,-,*,/,%,**, >, >=, etc.
40
- + Functions: abs, ceil, floor, truncate, is_zero, square, cube, fourth;
41
- + Binary Operators: &, |, ^, ~ (binary_ones_complement), <<, >>;
42
- + Ruby Math functions: acos, acosh, asin, asinh, atan, atan2, atanh, cbrt, cos, erf, exp,
43
- gamma, hypot, ldexp, log, log10, log2, sin, sinh, sqrt, tan, tanh, neg;
44
- + Boolean operations on boolean arrays: and, or, not;
45
- + Fast descriptive statistics from Parallel Colt (complete list found bellow);
46
- + Easy manipulation of arrays: reshape, reduce dimension, permute, section, slice, etc.
47
- + Reading of two dimensional arrays from CSV files (mainly for debugging and simple
48
- testing purposes);
49
- + StatList: a list that can grow/shrink and that can compute Parallel Colt descriptive
50
- statistics.
51
-
52
- Descriptive statistics methods
53
- ==============================
54
-
55
- auto_correlation, correlation, covariance, durbin_watson, frequencies, geometric_mean,
56
- harmonic_mean, kurtosis, lag1, max, mean, mean_deviation, median, min, moment, moment3,
57
- moment4, pooled_mean, pooled_variance, product, quantile, quantile_inverse,
58
- rank_interpolated, rms, sample_covariance, sample_kurtosis,
59
- sample_kurtosis_standard_error, sample_skew, sample_skew_standard_error,
60
- sample_standard_deviation, sample_variance, sample_weighted_variance, skew, split,
61
- standard_deviation, standard_error, sum, sum_of_inversions, sum_of_logarithms,
62
- sum_of_powers, sum_of_power_deviations, sum_of_squares, sum_of_squared_deviations,
63
- trimmed_mean, variance, weighted_mean, weighted_rms, weighted_sums, winsorized_mean.
64
-
65
- Installation and download
66
- =========================
67
-
68
- + Install Jruby
69
- + jruby –S gem install mdarray
70
-
71
- Contributors
72
- ============
73
-
74
- + Contributors are welcome.
75
-
76
- Homepages
77
- =========
78
-
79
- + http://rubygems.org/gems/mdarray
80
- + https://github.com/rbotafogo/mdarray/wiki
81
-
82
-
83
- HISTORY
84
- =======
85
-
86
- + 16/05/2013: Version 0.5.0: All loops transfered to Java with over 50% performance
87
- improvement. Descriptive statistics from Parallel Colt.
88
- + 19/04/2013: Version 0.4.3: Fixes a simple (but fatal bug). No new features
89
- + 17/04/2013: Version 0.4.2: Adds simple statistics and boolean operators
90
- + 05/05/2013: Version 0.4.0: Initial release
1
+ MDArray
2
+ =======
3
+
4
+ MDArray is a multi dimensional array implemented for JRuby inspired by NumPy (www.numpy.org)
5
+ and Narray (narray.rubyforge.org) by Masahiro Tanaka. MDArray stands on the shoulders of
6
+ Java-NetCDF and Parallel Colt.
7
+
8
+ NetCDF-Java Library is a Java interface to NetCDF files, as well as to many other types of
9
+ scientific data formats. It is developed and distributed by Unidata (http://www.unidata.ucar.edu).
10
+
11
+ Parallel Colt (sites.google.com/site/piotrwendykier/software/parallelcolt) is a multithreaded
12
+ version of Colt (http://acs.lbl.gov/software/colt/). Colt provides a set of Open Source
13
+ Libraries for High Performance Scientific and Technical Computing in Java. Scientific
14
+ and technical computing is characterized by demanding problem sizes and a need for high
15
+ performance at reasonably small memory footprint.
16
+
17
+ MDArray and SciRuby
18
+ ===================
19
+
20
+ MDArray subscribes fully to the SciRuby Manifesto (http://sciruby.com/).
21
+
22
+ Ruby has for some time had no equivalent to the beautifully constructed NumPy, SciPy,
23
+ and matplotlib libraries for Python.
24
+
25
+ We believe that the time for a Ruby science and visualization package has come. Sometimes
26
+ when a solution of sugar and water becomes super-saturated, from it precipitates a pure,
27
+ delicious, and diabetes-inducing crystal of sweetness, induced by no more than the tap
28
+ of a finger. So is occurring now, we believe, with numeric and visualization libraries for Ruby.”
29
+
30
+ Main properties
31
+ ===============
32
+
33
+ + Homogeneous multidimensional array, a table of elements (usually numbers), all of the
34
+ same type, indexed by a tuple of positive integers;
35
+ + Easy calculation for large numerical multi dimensional arrays;
36
+ + Basic types are: boolean, byte, short, int, long, float, double, string, structure;
37
+ + Based on JRuby, which allows importing Java libraries;
38
+ + Operator: +,-,*,/,%,**, >, >=, etc.
39
+ + Functions: abs, ceil, floor, truncate, is_zero, square, cube, fourth;
40
+ + Binary Operators: &, |, ^, ~ (binary_ones_complement), <<, >>;
41
+ + Ruby Math functions: acos, acosh, asin, asinh, atan, atan2, atanh, cbrt, cos, erf, exp,
42
+ gamma, hypot, ldexp, log, log10, log2, sin, sinh, sqrt, tan, tanh, neg;
43
+ + Boolean operations on boolean arrays: and, or, not;
44
+ + Fast descriptive statistics from Parallel Colt (complete list found bellow);
45
+ + Easy manipulation of arrays: reshape, reduce dimension, permute, section, slice, etc.
46
+ + Reading of two dimensional arrays from CSV files (mainly for debugging and simple
47
+ testing purposes);
48
+ + StatList: a list that can grow/shrink and that can compute Parallel Colt descriptive
49
+ statistics.
50
+
51
+ Descriptive statistics methods
52
+ ==============================
53
+
54
+ auto_correlation, correlation, covariance, durbin_watson, frequencies, geometric_mean,
55
+ harmonic_mean, kurtosis, lag1, max, mean, mean_deviation, median, min, moment, moment3,
56
+ moment4, pooled_mean, pooled_variance, product, quantile, quantile_inverse,
57
+ rank_interpolated, rms, sample_covariance, sample_kurtosis,
58
+ sample_kurtosis_standard_error, sample_skew, sample_skew_standard_error,
59
+ sample_standard_deviation, sample_variance, sample_weighted_variance, skew, split,
60
+ standard_deviation, standard_error, sum, sum_of_inversions, sum_of_logarithms,
61
+ sum_of_powers, sum_of_power_deviations, sum_of_squares, sum_of_squared_deviations,
62
+ trimmed_mean, variance, weighted_mean, weighted_rms, weighted_sums, winsorized_mean.
63
+
64
+ Installation and download
65
+ =========================
66
+
67
+ + Install Jruby
68
+ + jruby –S gem install mdarray
69
+
70
+ Contributors
71
+ ============
72
+
73
+ + Contributors are welcome.
74
+
75
+ Homepages
76
+ =========
77
+
78
+ + http://rubygems.org/gems/mdarray
79
+ + https://github.com/rbotafogo/mdarray/wiki
80
+
81
+
82
+ HISTORY
83
+ =======
84
+
85
+ + 16/05/2013: Version 0.5.0: All loops transfered to Java with over 50% performance
86
+ improvement. Descriptive statistics from Parallel Colt.
87
+ + 19/04/2013: Version 0.4.3: Fixes a simple (but fatal bug). No new features
88
+ + 17/04/2013: Version 0.4.2: Adds simple statistics and boolean operators
89
+ + 05/05/2013: Version 0.4.0: Initial release
data/Rakefile CHANGED
@@ -30,9 +30,14 @@ task :push do
30
30
  sh "git push origin master"
31
31
  end
32
32
 
33
+ desc 'Push gem to rubygem'
34
+ task :push_gem do
35
+ sh "push #{name} -p $http_proxy"
36
+ end
37
+
33
38
  Rake::TestTask.new do |t|
34
39
  t.libs << "test"
35
- t.test_files = FileList['test/test_complete.rb']
40
+ t.test_files = FileList['test/complete.rb']
36
41
  t.ruby_opts = ["--server", "-Xinvokedynamic.constants=true", "-J-Xmn512m",
37
42
  "-J-Xms1024m", "-J-Xmx1024m"]
38
43
  t.verbose = true
@@ -0,0 +1,193 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##########################################################################################
4
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
5
+ # and distribute this software and its documentation for educational, research, and
6
+ # not-for-profit purposes, without fee and without a signed licensing agreement, is hereby
7
+ # granted, provided that the above copyright notice, this paragraph and the following two
8
+ # paragraphs appear in all copies, modifications, and distributions. Contact Rodrigo
9
+ # Botafogo - rodrigo.a.botafogo@gmail.com for commercial licensing opportunities.
10
+ #
11
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
12
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
13
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
14
+ # POSSIBILITY OF SUCH DAMAGE.
15
+ #
16
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
18
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
19
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
20
+ # OR MODIFICATIONS.
21
+ ##########################################################################################
22
+
23
+ # require 'jruby/core_ext'
24
+
25
+ ##########################################################################################
26
+ #
27
+ ##########################################################################################
28
+
29
+ class Java::CernJetMathTdouble::DoubleFunctions
30
+ include_package "cern.jet.math.tdouble"
31
+
32
+ cern_methods = [:abs, :acos, :asin, :atan, :atan2, :ceil, :compare, :cos,
33
+ :div, :divNeg, :equals, :exp, :floor, :greater, :identity,
34
+ :IEEEremainder, :inv, :isEqual, :isGreater, :isLess, :less, :lg,
35
+ :log, :log2, :max, :min, :minus, :mod, :mult, :multNeg,
36
+ :multSquare, :neg, :plus, :plusAbs, :pow, :rint, :sign, :sin,
37
+ :sqrt, :square, :tan]
38
+
39
+ # java_alias :unary_atan2, :atan2, [Java::double]
40
+ java_alias :unary_compare, :compare, [Java::double]
41
+ java_alias :unary_div, :div, [Java::double]
42
+ # java_alias :unary_div_neg, :divNeg, [Java::double]
43
+ java_alias :unary_equals, :equals, [Java::double]
44
+ java_alias :unary_greater, :greater, [Java::double]
45
+ java_alias :unary_ieee_remainder, :IEEEremainder, [Java::double]
46
+ java_alias :unary_is_equal, :isEqual, [Java::double]
47
+ java_alias :unary_is_greater, :isGreater, [Java::double]
48
+ java_alias :unary_is_less, :isLess, [Java::double]
49
+ java_alias :unary_less, :less, [Java::double]
50
+ java_alias :unary_lg, :lg, [Java::double]
51
+ # java_alias :unary_log2, :log2, [Java::double]
52
+ java_alias :unary_mod, :mod, [Java::double]
53
+ java_alias :unary_max, :max, [Java::double]
54
+ java_alias :unary_min, :min, [Java::double]
55
+ java_alias :unary_minus, :minus, [Java::double]
56
+ java_alias :unary_mult, :mult, [Java::double]
57
+ # java_alias :unary_mult_neg, :multNeg, [Java::double]
58
+ # java_alias :unary_mult_square, :multSquare, [Java::double]
59
+ java_alias :unary_plus, :plus, [Java::double]
60
+ # java_alias :unary_plus_abs, :plusAbs, [Java::double]
61
+ java_alias :unary_pow, :pow, [Java::double]
62
+
63
+ cern_methods.each do |method|
64
+ field_reader(method)
65
+ attr_reader(":#{method}")
66
+ end
67
+
68
+ end
69
+
70
+ ##########################################################################################
71
+ #
72
+ ##########################################################################################
73
+
74
+ module CernDoubleFunctions
75
+ include_package "cern.jet.math.tdouble"
76
+ extend FunctionCreation
77
+ extend CernFunctions
78
+
79
+ binary_methods = [:atan2, :compare, :div, :divNeg, :equals, :greater, :IEEEremainder,
80
+ :less, :lg, :mod, :minus, :mult, :multNeg, :multSquare, :plus,
81
+ :plusAbs, :pow]
82
+
83
+ unary_methods = [:abs, :acos, :asin, :atan, :ceil, :cos, :exp, :floor, :identity, :inv,
84
+ :log, :neg, :rint, :sign, :sin, :sqrt, :square, :tan]
85
+
86
+ comparison_methods = [:isEqual, :isGreater, :isLess]
87
+
88
+ binary_conflict_methods = [:max, :min]
89
+
90
+ unary_conflict_methods = [:log2]
91
+
92
+ binary_methods.each do |method|
93
+ make_binary_operators(method.to_s,
94
+ cern_binary_function(method.to_s, "#{method}_double",
95
+ Java::CernJetMathTdouble.DoubleFunctions,
96
+ "double"))
97
+ end
98
+
99
+ unary_methods.each do |method|
100
+ make_unary_operators(method.to_s,
101
+ cern_unary_function(method.to_s, "#{method}_double",
102
+ Java::CernJetMathTdouble.DoubleFunctions,
103
+ "double"))
104
+ end
105
+
106
+ comparison_methods.each do |method|
107
+ make_comparison_operator(method.to_s,
108
+ cern_comparison_function(method.to_s, "#{method}_double",
109
+ Java::CernJetMathTdouble.DoubleFunctions,
110
+ "double"))
111
+ end
112
+
113
+ binary_conflict_methods.each do |method|
114
+ make_binary_operators("cern_#{method}",
115
+ cern_binary_function(method.to_s, "cern_#{method}_double",
116
+ Java::CernJetMathTdouble.DoubleFunctions,
117
+ "double"))
118
+ end
119
+
120
+ unary_conflict_methods.each do |method|
121
+ make_unary_operators("cern_#{method}",
122
+ cern_unary_function(method.to_s, "cern_#{method}_double",
123
+ Java::CernJetMathTdouble.DoubleFunctions,
124
+ "double"))
125
+ end
126
+
127
+ def self.register(als, name, long_name, type)
128
+ map = cern_binary_function(name, long_name, Java::CernJetMathTdouble.DoubleFunctions,
129
+ type)
130
+ MDArray.register_function(als, map, 2, CernFunctions.binary_helper)
131
+ end
132
+
133
+ alias :div_neg :divNeg
134
+ alias :is_equal :isEqual
135
+ alias :is_greater :isGreater
136
+ alias :is_less :isLess
137
+ alias :mult_neg :multNeg
138
+ alias :mult_square :multSquare
139
+ alias :ieee_remainder :IEEEremainder
140
+ alias :plus_abs :plusAbs
141
+
142
+ register(:add, :plus, :plus_double, "double")
143
+ register(:sub, :minus, :minus_double, "double")
144
+ register(:mul, :mult, :mult_double, "double")
145
+ register(:power, :pow, :pow_double, "double")
146
+ register(:eq, :equals, :equals_double, "double")
147
+ register(:gt, :isGreater, :is_greater_double, "double")
148
+ register(:lt, :isLess, :is_less_double, "double")
149
+ register(:div_neg, :divNeg, :div_neg_double, "double")
150
+ register(:ieee_remainder, :IEEEremainder, :ieee_remainder_double, "double")
151
+ register(:mult_neg, :multNeg, :mult_neg_double, "double")
152
+ register(:mult_square, :multSquare, :mult_square_double, "double")
153
+ register(:plus_abs, :plusAbs, :plus_abs_double, "double")
154
+
155
+ register(:is_equal, :isEqual, :is_equal_double, "double")
156
+ register(:is_greater, :isGreater, :is_greater_double, "double")
157
+ register(:is_less, :isLess, :is_less_double, "double")
158
+
159
+ # methods bellow are defined as ruby methods and are slower than the above methods.
160
+ # there are no similar methods defined in Colt/Parallel Colt. If performance is
161
+ # needed, then this methods need to be defined in Java.
162
+ # @acosh = RubyMath::Acosh
163
+ # @asinh = RubyMath::Asinh
164
+ # @atanh = RubyMath::Atanh
165
+ # @cbrt = RubyMath::Cbrt
166
+ # @cosh = RubyMath::Cosh
167
+ # @erf = RubyMath::Erf
168
+ # @erfc = RubyMath::Erfc
169
+ # @gamma = RubyMath::Gamma
170
+ # @hypot = RubyMath::Hypot
171
+ # @ldexp = RubyMath::Ldexp
172
+ # @log10 = RubyMath::Log10
173
+ # @sinh = RubyMath::Sinh
174
+ # @tanh = RubyMath::Tanh
175
+
176
+ # @truncate = NumericFunctions::Truncate
177
+ # @is_zero = NumericFunctions::IsZero
178
+ # @cube = NumericFunctions::Cube
179
+ # @fourth = NumericFunctions::Fourth
180
+ # @ge = ComparisonOperators::Ge
181
+ # @le = ComparisonOperators::Le
182
+
183
+ end
184
+
185
+ ##########################################################################################
186
+ #
187
+ ##########################################################################################
188
+
189
+ class DoubleMDArray
190
+
191
+ include CernDoubleFunctions
192
+
193
+ end # DoubleMDArray
@@ -0,0 +1,193 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##########################################################################################
4
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
5
+ # and distribute this software and its documentation for educational, research, and
6
+ # not-for-profit purposes, without fee and without a signed licensing agreement, is hereby
7
+ # granted, provided that the above copyright notice, this paragraph and the following two
8
+ # paragraphs appear in all copies, modifications, and distributions. Contact Rodrigo
9
+ # Botafogo - rodrigo.a.botafogo@gmail.com for commercial licensing opportunities.
10
+ #
11
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
12
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
13
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
14
+ # POSSIBILITY OF SUCH DAMAGE.
15
+ #
16
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
18
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
19
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
20
+ # OR MODIFICATIONS.
21
+ ##########################################################################################
22
+
23
+ # require 'jruby/core_ext'
24
+
25
+ ##########################################################################################
26
+ #
27
+ ##########################################################################################
28
+
29
+ class Java::CernJetMathTfloat::FloatFunctions
30
+ include_package "cern.jet.math.tfloat"
31
+
32
+ cern_methods = [:abs, :acos, :asin, :atan, :atan2, :ceil, :compare, :cos,
33
+ :div, :divNeg, :equals, :exp, :floor, :greater, :identity,
34
+ :IEEEremainder, :inv, :isEqual, :isGreater, :isLess, :less, :lg,
35
+ :log, :log2, :max, :min, :minus, :mod, :mult, :multNeg,
36
+ :multSquare, :neg, :plus, :plusAbs, :pow, :rint, :sign, :sin,
37
+ :sqrt, :square, :tan]
38
+
39
+ # java_alias :unary_atan2, :atan2, [Java::float]
40
+ java_alias :unary_compare, :compare, [Java::float]
41
+ java_alias :unary_div, :div, [Java::float]
42
+ # java_alias :unary_div_neg, :divNeg, [Java::float]
43
+ java_alias :unary_equals, :equals, [Java::float]
44
+ java_alias :unary_greater, :greater, [Java::float]
45
+ java_alias :unary_ieee_remainder, :IEEEremainder, [Java::float]
46
+ java_alias :unary_is_equal, :isEqual, [Java::float]
47
+ java_alias :unary_is_greater, :isGreater, [Java::float]
48
+ java_alias :unary_is_less, :isLess, [Java::float]
49
+ java_alias :unary_less, :less, [Java::float]
50
+ java_alias :unary_lg, :lg, [Java::float]
51
+ # java_alias :unary_log2, :log2, [Java::float]
52
+ java_alias :unary_mod, :mod, [Java::float]
53
+ java_alias :unary_max, :max, [Java::float]
54
+ java_alias :unary_min, :min, [Java::float]
55
+ java_alias :unary_minus, :minus, [Java::float]
56
+ java_alias :unary_mult, :mult, [Java::float]
57
+ # java_alias :unary_mult_neg, :multNeg, [Java::float]
58
+ # java_alias :unary_mult_square, :multSquare, [Java::float]
59
+ java_alias :unary_plus, :plus, [Java::float]
60
+ # java_alias :unary_plus_abs, :plusAbs, [Java::float]
61
+ java_alias :unary_pow, :pow, [Java::float]
62
+
63
+ cern_methods.each do |method|
64
+ field_reader(method)
65
+ attr_reader(":#{method}")
66
+ end
67
+
68
+ end
69
+
70
+ ##########################################################################################
71
+ #
72
+ ##########################################################################################
73
+
74
+ module CernFloatFunctions
75
+ include_package "cern.jet.math.tfloat"
76
+ extend FunctionCreation
77
+ extend CernFunctions
78
+
79
+ binary_methods = [:atan2, :compare, :div, :divNeg, :equals, :greater, :IEEEremainder,
80
+ :less, :lg, :mod, :minus, :mult, :multNeg, :multSquare, :plus,
81
+ :plusAbs, :pow]
82
+
83
+ unary_methods = [:abs, :acos, :asin, :atan, :ceil, :cos, :exp, :floor, :identity, :inv,
84
+ :log, :neg, :rint, :sign, :sin, :sqrt, :square, :tan]
85
+
86
+ comparison_methods = [:isEqual, :isGreater, :isLess]
87
+
88
+ binary_conflict_methods = [:max, :min]
89
+
90
+ unary_conflict_methods = [:log2]
91
+
92
+ binary_methods.each do |method|
93
+ make_binary_operators(method.to_s,
94
+ cern_binary_function(method.to_s, "#{method}_float",
95
+ Java::CernJetMathTfloat.FloatFunctions,
96
+ "float"))
97
+ end
98
+
99
+ unary_methods.each do |method|
100
+ make_unary_operators(method.to_s,
101
+ cern_unary_function(method.to_s, "#{method}_float",
102
+ Java::CernJetMathTfloat.FloatFunctions,
103
+ "float"))
104
+ end
105
+
106
+ comparison_methods.each do |method|
107
+ make_comparison_operator(method.to_s,
108
+ cern_comparison_function(method.to_s, "#{method}_float",
109
+ Java::CernJetMathTfloat.FloatFunctions,
110
+ "float"))
111
+ end
112
+
113
+ binary_conflict_methods.each do |method|
114
+ make_binary_operators("cern_#{method}",
115
+ cern_binary_function(method.to_s, "cern_#{method}_float",
116
+ Java::CernJetMathTfloat.FloatFunctions,
117
+ "float"))
118
+ end
119
+
120
+ unary_conflict_methods.each do |method|
121
+ make_unary_operators("cern_#{method}",
122
+ cern_unary_function(method.to_s, "cern_#{method}_float",
123
+ Java::CernJetMathTfloat.FloatFunctions,
124
+ "float"))
125
+ end
126
+
127
+ def self.register(als, name, long_name, type)
128
+ map = cern_binary_function(name, long_name, Java::CernJetMathTfloat.FloatFunctions,
129
+ type)
130
+ MDArray.register_function(als, map, 2, CernFunctions.binary_helper)
131
+ end
132
+
133
+ alias :div_neg :divNeg
134
+ alias :is_equal :isEqual
135
+ alias :is_greater :isGreater
136
+ alias :is_less :isLess
137
+ alias :mult_neg :multNeg
138
+ alias :mult_square :multSquare
139
+ alias :ieee_remainder :IEEEremainder
140
+ alias :plus_abs :plusAbs
141
+
142
+ register(:add, :plus, :plus_float, "float")
143
+ register(:sub, :minus, :minus_float, "float")
144
+ register(:mul, :mult, :mult_float, "float")
145
+ register(:power, :pow, :pow_float, "float")
146
+ register(:eq, :equals, :equals_float, "float")
147
+ register(:gt, :isGreater, :is_greater_float, "float")
148
+ register(:lt, :isLess, :is_less_float, "float")
149
+ register(:div_neg, :divNeg, :div_neg_float, "float")
150
+ register(:ieee_remainder, :IEEEremainder, :ieee_remainder_float, "float")
151
+ register(:mult_neg, :multNeg, :mult_neg_float, "float")
152
+ register(:mult_square, :multSquare, :mult_square_float, "float")
153
+ register(:plus_abs, :plusAbs, :plus_abs_float, "float")
154
+
155
+ register(:is_equal, :isEqual, :is_equal_float, "float")
156
+ register(:is_greater, :isGreater, :is_greater_float, "float")
157
+ register(:is_less, :isLess, :is_less_float, "float")
158
+
159
+ # methods bellow are defined as ruby methods and are slower than the above methods.
160
+ # there are no similar methods defined in Colt/Parallel Colt. If performance is
161
+ # needed, then this methods need to be defined in Java.
162
+ # @acosh = RubyMath::Acosh
163
+ # @asinh = RubyMath::Asinh
164
+ # @atanh = RubyMath::Atanh
165
+ # @cbrt = RubyMath::Cbrt
166
+ # @cosh = RubyMath::Cosh
167
+ # @erf = RubyMath::Erf
168
+ # @erfc = RubyMath::Erfc
169
+ # @gamma = RubyMath::Gamma
170
+ # @hypot = RubyMath::Hypot
171
+ # @ldexp = RubyMath::Ldexp
172
+ # @log10 = RubyMath::Log10
173
+ # @sinh = RubyMath::Sinh
174
+ # @tanh = RubyMath::Tanh
175
+
176
+ # @truncate = NumericFunctions::Truncate
177
+ # @is_zero = NumericFunctions::IsZero
178
+ # @cube = NumericFunctions::Cube
179
+ # @fourth = NumericFunctions::Fourth
180
+ # @ge = ComparisonOperators::Ge
181
+ # @le = ComparisonOperators::Le
182
+
183
+ end
184
+
185
+ ##########################################################################################
186
+ #
187
+ ##########################################################################################
188
+
189
+ class FloatMDArray
190
+
191
+ include CernFloatFunctions
192
+
193
+ end # FloatMDArray