mdarray 0.4.3.pre-java → 0.5.0-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 (111) hide show
  1. data/README.md +82 -14
  2. data/Rakefile +8 -2
  3. data/doc/BinaryOperator.html +227 -0
  4. data/doc/BitwiseOperators.html +135 -0
  5. data/doc/BooleanFunctions.html +135 -0
  6. data/doc/BooleanMDArray.html +193 -0
  7. data/doc/ByteMDArray.html +271 -0
  8. data/doc/Colt.html +269 -0
  9. data/doc/ComparisonOperators.html +135 -0
  10. data/doc/Const.html +490 -0
  11. data/doc/Csv.html +589 -0
  12. data/doc/DDescriptive.html +4373 -0
  13. data/doc/DoubleMDArray.html +555 -0
  14. data/doc/DoubleStatList.html +256 -0
  15. data/doc/FastBinaryOperator.html +743 -0
  16. data/doc/FastBoolean.html +512 -0
  17. data/doc/FastUnaryOperator.html +583 -0
  18. data/doc/FloatMDArray.html +237 -0
  19. data/doc/FunctionCreation.html +520 -0
  20. data/doc/FunctionMap.html +813 -0
  21. data/doc/GenericFunctions.html +135 -0
  22. data/doc/IntMDArray.html +259 -0
  23. data/doc/LongMDArray.html +257 -0
  24. data/doc/MDArray.html +9639 -0
  25. data/doc/MDArray/Counter.html +2767 -0
  26. data/doc/MDArray/IteratorFast.html +872 -0
  27. data/doc/MDArray/IteratorFastBoolean.html +384 -0
  28. data/doc/MDArray/IteratorFastByte.html +373 -0
  29. data/doc/MDArray/IteratorFastChar.html +384 -0
  30. data/doc/MDArray/IteratorFastDouble.html +384 -0
  31. data/doc/MDArray/IteratorFastFloat.html +384 -0
  32. data/doc/MDArray/IteratorFastInt.html +384 -0
  33. data/doc/MDArray/IteratorFastLong.html +384 -0
  34. data/doc/MDArray/IteratorFastShort.html +384 -0
  35. data/doc/MDArrayTest.html +125 -0
  36. data/doc/NonNumericalMDArray.html +177 -0
  37. data/doc/NumericFunctions.html +297 -0
  38. data/doc/NumericalMDArray.html +278 -0
  39. data/doc/Operator.html +826 -0
  40. data/doc/Proc.html +1097 -0
  41. data/doc/RubyBinaryOperator.html +526 -0
  42. data/doc/RubyFunctions.html +232 -0
  43. data/doc/RubyMath.html +135 -0
  44. data/doc/RubyStats.html +135 -0
  45. data/doc/RubyUnaryOperator.html +510 -0
  46. data/doc/ShortMDArray.html +267 -0
  47. data/doc/StatList.html +1176 -0
  48. data/doc/StringMDArray.html +181 -0
  49. data/doc/StructureMDArray.html +181 -0
  50. data/doc/UnaryOperator.html +227 -0
  51. data/doc/UserFunction.html +297 -0
  52. data/doc/_index.html +467 -0
  53. data/doc/class_list.html +53 -0
  54. data/doc/css/common.css +1 -0
  55. data/doc/css/full_list.css +57 -0
  56. data/doc/css/style.css +338 -0
  57. data/doc/file.README.html +173 -0
  58. data/doc/file_list.html +55 -0
  59. data/doc/frames.html +28 -0
  60. data/doc/index.html +173 -0
  61. data/doc/js/app.js +214 -0
  62. data/doc/js/full_list.js +173 -0
  63. data/doc/js/jquery.js +4 -0
  64. data/doc/method_list.html +2524 -0
  65. data/doc/top-level-namespace.html +114 -0
  66. data/lib/colt/colt.rb +56 -0
  67. data/lib/colt/colt_mdarray.rb +95 -0
  68. data/lib/colt/double_descriptive.rb +636 -0
  69. data/lib/colt/probability.rb +12 -0
  70. data/lib/colt/stat_list.rb +192 -0
  71. data/lib/env.rb +5 -1
  72. data/lib/mdarray.rb +5 -0
  73. data/lib/mdarray/access.rb +2 -2
  74. data/lib/mdarray/creation.rb +34 -19
  75. data/lib/mdarray/csv.rb +61 -0
  76. data/lib/mdarray/fast_operators.rb +241 -0
  77. data/lib/mdarray/operators.rb +18 -0
  78. data/lib/mdarray/ruby_operators.rb +2 -18
  79. data/lib/mdarray/ruby_stats.rb +1 -1
  80. data/lib/mdarray/views.rb +8 -8
  81. data/target/helper.jar +0 -0
  82. data/test/colt/VALE3.csv +3437 -0
  83. data/test/colt/VALE3.xlsx +0 -0
  84. data/test/colt/VALE3_short-err.csv +20 -0
  85. data/test/colt/VALE3_short.csv +20 -0
  86. data/test/colt/VALE3_short.xlsx +0 -0
  87. data/test/colt/test_complete.rb +25 -0
  88. data/test/colt/test_stat_list.rb +128 -0
  89. data/test/colt/test_statistics.rb +114 -0
  90. data/test/complete.rb +25 -0
  91. data/test/env.rb +54 -30
  92. data/test/{arithmetic_casting.rb → mdarray/arithmetic_casting.rb} +0 -0
  93. data/test/{test_access.rb → mdarray/test_access.rb} +0 -0
  94. data/test/{test_boolean.rb → mdarray/test_boolean.rb} +0 -2
  95. data/test/{test_comparison.rb → mdarray/test_comparison.rb} +0 -0
  96. data/test/{test_complete.rb → mdarray/test_complete.rb} +3 -14
  97. data/test/{test_counter.rb → mdarray/test_counter.rb} +0 -0
  98. data/test/{test_creation.rb → mdarray/test_creation.rb} +0 -0
  99. data/test/{test_error.rb → mdarray/test_error.rb} +8 -5
  100. data/test/{test_operator.rb → mdarray/test_operator.rb} +6 -2
  101. data/test/{test_speed.rb → mdarray/test_performance.rb} +74 -39
  102. data/test/{test_printing.rb → mdarray/test_printing.rb} +0 -1
  103. data/test/{test_shape.rb → mdarray/test_shape.rb} +0 -0
  104. data/test/mdarray/test_statistics.rb +80 -0
  105. data/test/{test_trigonometry.rb → mdarray/test_trigonometry.rb} +0 -0
  106. data/test/{test_views.rb → mdarray/test_views.rb} +0 -0
  107. data/vendor/parallelcolt-0.10.0.jar +0 -0
  108. data/version.rb +1 -1
  109. metadata +122 -39
  110. data/test/test_lazy.rb +0 -52
  111. data/test/test_statistics.rb +0 -38
@@ -0,0 +1,12 @@
1
+ Returns the area from zero to x under the beta density function.
2
+ x
3
+ - -
4
+ | (a+b) | | a-1 b-1
5
+ P(x) = ---------- | t (1-t) dt
6
+ - - | |
7
+ | (a) | (b) -
8
+ 0
9
+
10
+ This function is identical to the incomplete beta integral function
11
+ Gamma.incompleteBeta(a, b, x). The complemented function is 1 - P(1-x) =
12
+ Gamma.incompleteBeta( b, a, x );
@@ -0,0 +1,192 @@
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_relative 'double_descriptive'
24
+
25
+ ##########################################################################################
26
+ #
27
+ ##########################################################################################
28
+
29
+ class StatList
30
+
31
+ attr_reader :array_list
32
+
33
+ #------------------------------------------------------------------------------------
34
+ # Appends the specified element to the end of this list.
35
+ #------------------------------------------------------------------------------------
36
+
37
+ def add(element)
38
+ @array_list.add(element)
39
+ end
40
+
41
+ #------------------------------------------------------------------------------------
42
+ # Inserts the specified element before the specified position into the receiver.
43
+ #------------------------------------------------------------------------------------
44
+
45
+ def before_insert(index, element)
46
+ @array_list.beforeInsert(index, element)
47
+ end
48
+
49
+ #------------------------------------------------------------------------------------
50
+ #
51
+ #------------------------------------------------------------------------------------
52
+
53
+ def binary_search(key, from = 0, to = @array_list.size() - 1)
54
+ sorted_data.binarySearchFromTo(key, from, to)
55
+ end
56
+
57
+ #------------------------------------------------------------------------------------
58
+ #
59
+ #------------------------------------------------------------------------------------
60
+
61
+ def copy
62
+ DoubleStatList.new(@array_list.copy)
63
+ end
64
+
65
+ #------------------------------------------------------------------------------------
66
+ # Returns the elements currently stored. Trims the list to the maximum size.
67
+ #------------------------------------------------------------------------------------
68
+
69
+ def elements
70
+ @array_list.trimToSize
71
+ @array_list.elements().to_a
72
+ end
73
+
74
+ #------------------------------------------------------------------------------------
75
+ # Returns the element at the specified position in the receiver.
76
+ #------------------------------------------------------------------------------------
77
+
78
+ def get(index)
79
+ @array_list.get(index)
80
+ end
81
+
82
+ alias :[] :get
83
+
84
+ #------------------------------------------------------------------------------------
85
+ #
86
+ #------------------------------------------------------------------------------------
87
+
88
+ def index_of(element, from = 0, to = @array_list.size() - 1)
89
+ @array_list.indexOfFromTo(element, from, to)
90
+ end
91
+
92
+ #------------------------------------------------------------------------------------
93
+ #
94
+ #------------------------------------------------------------------------------------
95
+
96
+ def last_index_of(element, from = 0, to = @array_list.size() - 1)
97
+ @array_list.lastIndexOfFromTo(element, from, to)
98
+ end
99
+
100
+ #------------------------------------------------------------------------------------
101
+ #
102
+ #------------------------------------------------------------------------------------
103
+
104
+ def reverse
105
+ @array_list.reverse()
106
+ end
107
+
108
+ #------------------------------------------------------------------------------------
109
+ #
110
+ #------------------------------------------------------------------------------------
111
+
112
+ def set(index, element)
113
+ @array_list.set(index, element)
114
+ end
115
+
116
+ alias :[]= :set
117
+
118
+ #------------------------------------------------------------------------------------
119
+ #
120
+ #------------------------------------------------------------------------------------
121
+
122
+ def shuffle(from = 0, to = @array_list.size() - 1)
123
+ @array_list.shuffleFromTo(from, to)
124
+ end
125
+
126
+ #------------------------------------------------------------------------------------
127
+ #
128
+ #------------------------------------------------------------------------------------
129
+
130
+ def trim_to_size
131
+ @array_list.trimToSize()
132
+ end
133
+
134
+ #------------------------------------------------------------------------------------
135
+ #
136
+ #------------------------------------------------------------------------------------
137
+
138
+ def print
139
+ puts @array_list.toString()
140
+ end
141
+
142
+ #------------------------------------------------------------------------------------
143
+ #
144
+ #------------------------------------------------------------------------------------
145
+
146
+ def to_s
147
+ print
148
+ end
149
+
150
+ #------------------------------------------------------------------------------------
151
+ #
152
+ #------------------------------------------------------------------------------------
153
+
154
+ private
155
+
156
+ #------------------------------------------------------------------------------------
157
+ #
158
+ #------------------------------------------------------------------------------------
159
+
160
+ def initialize(value = nil)
161
+ reset_statistics
162
+ end
163
+
164
+ end
165
+
166
+
167
+ ##########################################################################################
168
+ #
169
+ ##########################################################################################
170
+
171
+ class DoubleStatList < StatList
172
+ include DDescriptive
173
+
174
+ #------------------------------------------------------------------------------------
175
+ #
176
+ #------------------------------------------------------------------------------------
177
+
178
+ def initialize(value = nil)
179
+
180
+ super(value)
181
+
182
+ if (value == nil)
183
+ @array_list = Java::CernColtListTdouble::DoubleArrayList.new()
184
+ elsif (value.is_a? Integer)
185
+ @array_list = Java::CernColtListTdouble::DoubleArrayList.new(value)
186
+ else # Receiving a DoubleArrayList
187
+ @array_list = value
188
+ end
189
+
190
+ end
191
+
192
+ end # StatList
data/lib/env.rb CHANGED
@@ -3,5 +3,9 @@ require 'java'
3
3
  $CLASSPATH << "#{File.dirname(__FILE__)}/../vendor/"
4
4
 
5
5
  Dir["#{File.dirname(__FILE__)}/../vendor/*.jar"].each do |jar|
6
- require jar
6
+ require jar
7
+ end
8
+
9
+ Dir["#{File.dirname(__FILE__)}/../target/*.jar"].each do |jar|
10
+ require jar
7
11
  end
@@ -108,6 +108,8 @@ class MDArray
108
108
  @local_iterator = nil
109
109
  @section = section
110
110
  @coerced = false # should never be set by the user! For internal use only!
111
+ @binary_operator = nil
112
+ @unary_operator = nil
111
113
 
112
114
  # initialize printing defaults
113
115
  printing_defaults
@@ -377,8 +379,11 @@ require_relative 'mdarray/function_creation'
377
379
  require_relative 'mdarray/ruby_functions'
378
380
  require_relative 'mdarray/operators'
379
381
  require_relative 'mdarray/ruby_operators'
382
+ require_relative 'mdarray/fast_operators'
380
383
  require_relative 'mdarray/access'
381
384
  require_relative 'mdarray/views'
382
385
  require_relative 'mdarray/printing'
383
386
  require_relative 'mdarray/counter'
384
387
  require_relative 'mdarray/ruby_stats'
388
+ require_relative 'mdarray/csv'
389
+ require_relative 'colt/colt'
@@ -103,8 +103,8 @@ class MDArray
103
103
  #---------------------------------------------------------------------------------------
104
104
  # When set is used to assign to an element, it is assumed that the index does not need
105
105
  # correction, for instance, no negative index is allowed. If one wants to use
106
- # negative indexes, then method set should be used. So mat[-1, 0, 0] = 10, raises an
107
- # exection while mat.set([-1, 0, 0], 10) sets the last value for the first dimension.
106
+ # negative indexes, then method [] should be used. So mat.set([-1, 0, 0], 10), raises
107
+ # an exection while mat[-1, 0, 0] = 10 sets the last value for the first dimension.
108
108
  # *<tt>index</tt>: array with the index position
109
109
  # *<tt>value</tt>: value to be set
110
110
  #---------------------------------------------------------------------------------------
@@ -25,6 +25,13 @@
25
25
 
26
26
  class MDArray
27
27
 
28
+ class << self
29
+
30
+ attr_accessor :binary_operator
31
+ attr_accessor :unary_operator
32
+
33
+ end
34
+
28
35
  #------------------------------------------------------------------------------------
29
36
  # Given two types returns the upcasted one
30
37
  #------------------------------------------------------------------------------------
@@ -42,28 +49,12 @@ class MDArray
42
49
  #
43
50
  #------------------------------------------------------------------------------------
44
51
 
45
- def self.binary_operator=(operator)
46
- @@binary_operator = operator
47
- end
48
-
49
- def self.binary_operator
50
- @@binary_operator
51
- end
52
-
53
- def self.unary_operator=(operator)
54
- @@unary_operator = operator
55
- end
56
-
57
- def self.unary_operator
58
- @@unary_operator
59
- end
60
-
61
52
  def get_binary_op
62
- (@binary_operator)? @binary_operator : @@binary_operator
53
+ (@binary_operator)? @binary_operator : MDArray.binary_operator
63
54
  end
64
55
 
65
56
  def get_unary_op
66
- (@unary_operator)? @unary_operator : @@unary_operator
57
+ (@unary_operator)? @unary_operator : MDArray.unary_operator
67
58
  end
68
59
 
69
60
  # Factory Methods
@@ -77,7 +68,17 @@ class MDArray
77
68
  #------------------------------------------------------------------------------------
78
69
 
79
70
  def self.build(type, shape, storage = nil)
80
-
71
+
72
+ if (shape.is_a? String)
73
+ # building from csv
74
+ # using shape as filename
75
+ # using storage as flag for headers
76
+ storage = (storage)? storage : false
77
+ parameters = Csv.read_numeric(shape, storage)
78
+ shape=[parameters[0], parameters[1]]
79
+ storage = parameters[2]
80
+ end
81
+
81
82
  dtype = DataType.valueOf(type.upcase)
82
83
  jshape = shape.to_java :int
83
84
 
@@ -93,6 +94,20 @@ class MDArray
93
94
 
94
95
  end
95
96
 
97
+ #------------------------------------------------------------------------------------
98
+ #
99
+ #------------------------------------------------------------------------------------
100
+
101
+
102
+ #------------------------------------------------------------------------------------
103
+ #
104
+ #------------------------------------------------------------------------------------
105
+
106
+ def self.build_from_nc_array(type, nc_array, section = false)
107
+ klass = Object.const_get("#{type.capitalize}MDArray")
108
+ return klass.new(type, nc_array, section)
109
+ end
110
+
96
111
  #------------------------------------------------------------------------------------
97
112
  # Builds a boolean mdarray
98
113
  # @param shape [Array] the shape of the mdarray as a ruby array
@@ -0,0 +1,61 @@
1
+ require 'csv'
2
+ require 'date'
3
+
4
+ class Csv
5
+
6
+ attr_reader :col_sep
7
+ attr_reader :row_sep
8
+ attr_reader :quote_char
9
+
10
+ @epoch = Date.new(1970, 1, 1)
11
+
12
+ class << self
13
+ attr_reader :epoch
14
+ end
15
+
16
+ #------------------------------------------------------------------------------------
17
+ #
18
+ #------------------------------------------------------------------------------------
19
+
20
+ def self.read_numeric(filename, headers = false)
21
+
22
+ buffer = Array.new
23
+ lines = 0
24
+ columns = nil
25
+
26
+ CSV.foreach(filename,
27
+ {return_headers: false,
28
+ # headers: true,
29
+ converters: [:numeric, :date]} ) do |row|
30
+
31
+ if (headers)
32
+ headers = false
33
+ next
34
+ end
35
+
36
+ columns ||= row.size
37
+ lines += 1
38
+
39
+ row.each do |data|
40
+
41
+ if (row.size != columns)
42
+ raise "Data does not have the same number of columns for all lines"
43
+ end
44
+
45
+ # if it is a Date, then convert it to seconds since epoch
46
+ if (data.is_a? Date)
47
+ buffer << data.to_time.to_i
48
+ end
49
+
50
+ if (data.is_a? Numeric)
51
+ buffer << data
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ [lines, columns, buffer]
58
+
59
+ end
60
+
61
+ end # Csv
@@ -0,0 +1,241 @@
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
+ ##########################################################################################
24
+ #
25
+ ##########################################################################################
26
+
27
+ class FastBinaryOperator < BinaryOperator
28
+
29
+ #---------------------------------------------------------------------------------------
30
+ #
31
+ #---------------------------------------------------------------------------------------
32
+
33
+ def get_args(*args)
34
+
35
+ parse_args(*args)
36
+
37
+ if (@op1.is_a? NumericalMDArray)
38
+ if (@op2.is_a? Numeric)
39
+ arg2 = @op2
40
+ elsif (@op2.is_a? NumericalMDArray)
41
+ if (!@op1.compatible(@op2))
42
+ raise "Invalid operation - arrays are incompatible"
43
+ end
44
+ arg2 = @op2.nc_array
45
+ else # Operation with another user defined type
46
+ false
47
+ # *TODO: make it more general using coerce if other_val type is not recognized
48
+ # if (arg is not recognized)
49
+ # self_equiv, arg_equiv = arg.coerce(self)
50
+ # self_equiv * arg_equiv
51
+ # end
52
+ end
53
+
54
+ else # NonNumericalMDArray
55
+ if (!@op1.compatible(@op2))
56
+ raise "Invalid operation - arrays are incompatible"
57
+ end
58
+
59
+ # Will not work if we have subclasses!!!!
60
+ if (@op1.class != @op2.class)
61
+ raise "Invalid operation - array are not of compatible types"
62
+ end
63
+
64
+ arg2 = @op2.nc_array
65
+ end
66
+
67
+ yield @op1.nc_array, arg2, @op1.shape, *args
68
+
69
+ end
70
+
71
+ #---------------------------------------------------------------------------------------
72
+ #
73
+ #---------------------------------------------------------------------------------------
74
+
75
+ def default(*args)
76
+
77
+ calc = nil
78
+ get_args(*args) do |op1, op2, shape, *other_args|
79
+ calc = MDArray.build(@type, shape)
80
+ if (@coerced)
81
+ helper = Java::RbMdarrayLoopsBinops::CoerceBinaryOperator
82
+ helper.send("apply", calc.nc_array, op1, op2, @do_func)
83
+ elsif (@op1.is_a? NumericalMDArray)
84
+ helper = Java::RbMdarrayLoopsBinops::DefaultBinaryOperator
85
+ helper.send("apply", calc.nc_array, op1, op2, @do_func)
86
+ else
87
+ helper = Java::RbMdarrayLoopsBinops::DefaultBinaryOperator
88
+ helper.send("apply#{@op1.class}", calc.nc_array, op1, op2, @do_func)
89
+ end
90
+ end
91
+ return calc
92
+
93
+ end
94
+
95
+ #---------------------------------------------------------------------------------------
96
+ #
97
+ #---------------------------------------------------------------------------------------
98
+
99
+ def fill(*args)
100
+
101
+ get_args(*args) do |op1, op2, shape, *other_args|
102
+ helper = Java::RbMdarrayLoopsBinops::FillBinaryOperator
103
+ helper.send("apply", op1, op2)
104
+ end
105
+
106
+ end
107
+
108
+ #---------------------------------------------------------------------------------------
109
+ #
110
+ #---------------------------------------------------------------------------------------
111
+
112
+ def in_place(*args)
113
+
114
+ get_args(*args) do |op1, op2, shape, *other_args|
115
+ helper = Java::RbMdarrayLoopsBinops::InplaceBinaryOperator
116
+ helper.send("apply", op1, op2, @do_func)
117
+ end
118
+
119
+ end
120
+
121
+ #---------------------------------------------------------------------------------------
122
+ #
123
+ #---------------------------------------------------------------------------------------
124
+
125
+ def reduce(*args)
126
+
127
+ calc = nil
128
+
129
+ get_args(*args) do |op1, op2, shape, *other_args|
130
+ helper = Java::RbMdarrayLoopsBinops::ReduceBinaryOperator
131
+ calc = @pre_condition_result
132
+ calc = helper.send("apply", calc, op1, op2, @do_func)
133
+ end
134
+
135
+ return calc
136
+
137
+ end
138
+
139
+ #---------------------------------------------------------------------------------------
140
+ #
141
+ #---------------------------------------------------------------------------------------
142
+
143
+ def complex_reduce(*args)
144
+
145
+ calc = nil
146
+
147
+ get_args(*args) do |op1, op2, shape, *other_args|
148
+ helper = Java::RbMdarrayLoopsBinops::ComplexReduceBinaryOperator
149
+ calc = @pre_condition_result
150
+ calc = helper.send("apply", calc, op1, op2, @do_func)
151
+ end
152
+
153
+ return calc
154
+
155
+ end
156
+
157
+ end # FastBinaryOperator
158
+
159
+ ##########################################################################################
160
+ #
161
+ ##########################################################################################
162
+
163
+ class FastUnaryOperator < UnaryOperator
164
+
165
+ #---------------------------------------------------------------------------------------
166
+ #
167
+ #---------------------------------------------------------------------------------------
168
+
169
+ def get_args(*args)
170
+
171
+ parse_args(*args)
172
+ yield @op.nc_array, @op.shape, *@other_args
173
+
174
+ end
175
+
176
+ #---------------------------------------------------------------------------------------
177
+ #
178
+ #---------------------------------------------------------------------------------------
179
+
180
+ def set_block(*args)
181
+
182
+ get_args(*args) do |op1, shape, *other_args|
183
+ block = other_args[0]
184
+ helper = Java::RbMdarrayLoopsUnops::SetAll
185
+ func = (shape.size <= 7)? "apply#{shape.size}" : "apply"
186
+ helper.send(func, op1, &block) if block
187
+ end
188
+
189
+ end
190
+
191
+ #---------------------------------------------------------------------------------------
192
+ #
193
+ #---------------------------------------------------------------------------------------
194
+
195
+ def default(*args)
196
+
197
+ calc = nil
198
+ get_args(*args) do |op1, shape, *other_args|
199
+ calc = MDArray.build(@type, shape)
200
+ helper = Java::RbMdarrayLoopsUnops::DefaultUnaryOperator
201
+ helper.send("apply", calc.nc_array, op1, @do_func)
202
+ end
203
+ return calc
204
+
205
+ end
206
+
207
+ #---------------------------------------------------------------------------------------
208
+ #
209
+ #---------------------------------------------------------------------------------------
210
+
211
+ def in_place(*args)
212
+
213
+ get_args(*args) do |op1, shape, *other_args|
214
+ helper = Java::RbMdarrayLoopsUnops::InplaceUnaryOperator
215
+ helper.send("apply", op1, @do_func)
216
+ end
217
+
218
+ end
219
+
220
+ #---------------------------------------------------------------------------------------
221
+ #
222
+ #---------------------------------------------------------------------------------------
223
+
224
+ def reduce(*args)
225
+
226
+ calc = nil
227
+
228
+ get_args(*args) do |op1, shape, *other_args|
229
+ helper = Java::RbMdarrayLoopsUnops::ReduceUnaryOperator
230
+ calc = @pre_condition_result
231
+ calc = helper.send("apply", calc, op1, @do_func)
232
+ end
233
+
234
+ return calc
235
+
236
+ end
237
+
238
+ end # UnaryOperator
239
+
240
+ MDArray.binary_operator = FastBinaryOperator
241
+ MDArray.unary_operator = FastUnaryOperator