mdarray 0.5.5.2-java → 0.5.6-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 (209) hide show
  1. checksums.yaml +4 -4
  2. data/config.rb +29 -95
  3. data/doc/BinaryOperator.html +20 -21
  4. data/doc/BitwiseOperators.html +18 -8
  5. data/doc/BitwiseOperators/BinaryAnd.html +189 -0
  6. data/doc/BitwiseOperators/BinaryLeftShift.html +189 -0
  7. data/doc/BitwiseOperators/BinaryOnesComplement.html +189 -0
  8. data/doc/BitwiseOperators/BinaryOr.html +189 -0
  9. data/doc/BitwiseOperators/BinaryRightShift.html +189 -0
  10. data/doc/BitwiseOperators/BinaryXor.html +189 -0
  11. data/doc/BooleanFunctions.html +18 -8
  12. data/doc/BooleanFunctions/And.html +189 -0
  13. data/doc/BooleanFunctions/Not.html +189 -0
  14. data/doc/BooleanFunctions/Or.html +189 -0
  15. data/doc/BooleanMDArray.html +10 -10
  16. data/doc/ByteMDArray.html +73 -14
  17. data/doc/CernDoubleFunctions.html +208 -0
  18. data/doc/CernFloatFunctions.html +208 -0
  19. data/doc/CernFunctions.html +828 -0
  20. data/doc/CernIntFunctions.html +208 -0
  21. data/doc/CernLongFunctions.html +208 -0
  22. data/doc/CharMDArray.html +181 -0
  23. data/doc/Colt.html +18 -20
  24. data/doc/ComparisonOperators.html +18 -8
  25. data/doc/ComparisonOperators/Eq.html +189 -0
  26. data/doc/ComparisonOperators/Ge.html +189 -0
  27. data/doc/ComparisonOperators/Gt.html +189 -0
  28. data/doc/ComparisonOperators/Le.html +189 -0
  29. data/doc/ComparisonOperators/Lt.html +189 -0
  30. data/doc/Const.html +107 -47
  31. data/doc/Csv.html +325 -113
  32. data/doc/Csv/Dimension.html +771 -0
  33. data/doc/Csv/Dimensions.html +654 -0
  34. data/doc/DDescriptive.html +573 -625
  35. data/doc/DoubleMDArray.html +40 -172
  36. data/doc/DoubleStatList.html +19 -20
  37. data/doc/FastBinaryOperator.html +166 -148
  38. data/doc/FastUnaryOperator.html +104 -109
  39. data/doc/FloatMDArray.html +55 -16
  40. data/doc/FunctionCreation.html +53 -273
  41. data/doc/FunctionMap.html +381 -93
  42. data/doc/GenericFunctions.html +18 -8
  43. data/doc/GenericFunctions/Null.html +187 -0
  44. data/doc/IntMDArray.html +77 -16
  45. data/doc/Java/CernJetMathTdouble/DoubleFunctions.html +120 -0
  46. data/doc/Java/CernJetMathTfloat/FloatFunctions.html +120 -0
  47. data/doc/Java/CernJetMathTint/IntFunctions.html +120 -0
  48. data/doc/Java/CernJetMathTlong/LongFunctions.html +120 -0
  49. data/doc/LazyBinaryOperator.html +714 -0
  50. data/doc/LazyMDArray.html +990 -0
  51. data/doc/LazyMDArray/BinaryComp.html +282 -0
  52. data/doc/LazyMDArray/UnaryComp.html +280 -0
  53. data/doc/LazyUnaryOperator.html +537 -0
  54. data/doc/LongMDArray.html +59 -15
  55. data/doc/MDArray.html +3223 -2181
  56. data/doc/MDArray/Counter.html +321 -1233
  57. data/doc/MDArray/IteratorFast.html +177 -116
  58. data/doc/MDArray/IteratorFastBoolean.html +37 -41
  59. data/doc/MDArray/IteratorFastByte.html +46 -39
  60. data/doc/MDArray/IteratorFastChar.html +37 -41
  61. data/doc/MDArray/IteratorFastDouble.html +37 -41
  62. data/doc/MDArray/IteratorFastFloat.html +37 -41
  63. data/doc/MDArray/IteratorFastInt.html +37 -41
  64. data/doc/MDArray/IteratorFastLong.html +37 -41
  65. data/doc/MDArray/IteratorFastShort.html +37 -41
  66. data/doc/MDArray/Section.html +561 -0
  67. data/doc/Nashorn.html +1407 -0
  68. data/doc/NetCDF.html +749 -0
  69. data/doc/NetCDF/Attribute.html +875 -0
  70. data/doc/NetCDF/AttributeWriter.html +286 -0
  71. data/doc/NetCDF/CDMNode.html +460 -0
  72. data/doc/NetCDF/Dimension.html +559 -0
  73. data/doc/NetCDF/DimensionWriter.html +642 -0
  74. data/doc/NetCDF/File.html +1593 -0
  75. data/doc/NetCDF/FileParent.html +674 -0
  76. data/doc/NetCDF/FileWriter.html +2875 -0
  77. data/doc/NetCDF/Group.html +685 -0
  78. data/doc/NetCDF/GroupWriter.html +851 -0
  79. data/doc/NetCDF/TimeVariable.html +646 -0
  80. data/doc/NetCDF/Variable.html +2994 -0
  81. data/doc/NetCDF/VariableWriter.html +420 -0
  82. data/doc/NonNumericalMDArray.html +11 -11
  83. data/doc/NumericFunctions.html +38 -30
  84. data/doc/NumericFunctions/Abs.html +189 -0
  85. data/doc/NumericFunctions/Add.html +189 -0
  86. data/doc/NumericFunctions/Ceil.html +189 -0
  87. data/doc/NumericFunctions/Cube.html +189 -0
  88. data/doc/NumericFunctions/Div.html +189 -0
  89. data/doc/NumericFunctions/Floor.html +189 -0
  90. data/doc/NumericFunctions/Fourth.html +189 -0
  91. data/doc/NumericFunctions/IsZero.html +189 -0
  92. data/doc/NumericFunctions/Max.html +189 -0
  93. data/doc/NumericFunctions/Min.html +189 -0
  94. data/doc/NumericFunctions/Mul.html +189 -0
  95. data/doc/NumericFunctions/Power.html +189 -0
  96. data/doc/NumericFunctions/Square.html +189 -0
  97. data/doc/NumericFunctions/Sub.html +189 -0
  98. data/doc/NumericFunctions/Truncate.html +189 -0
  99. data/doc/NumericalMDArray.html +14 -15
  100. data/doc/Operator.html +318 -109
  101. data/doc/Proc.html +120 -129
  102. data/doc/RubyBinaryOperator.html +66 -70
  103. data/doc/RubyFunctions.html +572 -27
  104. data/doc/RubyMath.html +18 -8
  105. data/doc/RubyMath/Acos.html +189 -0
  106. data/doc/RubyMath/Acosh.html +189 -0
  107. data/doc/RubyMath/Asin.html +189 -0
  108. data/doc/RubyMath/Asinh.html +189 -0
  109. data/doc/RubyMath/Atan.html +189 -0
  110. data/doc/RubyMath/Atan2.html +189 -0
  111. data/doc/RubyMath/Atanh.html +189 -0
  112. data/doc/RubyMath/Cbrt.html +189 -0
  113. data/doc/RubyMath/Cos.html +189 -0
  114. data/doc/RubyMath/Cosh.html +189 -0
  115. data/doc/RubyMath/Erf.html +189 -0
  116. data/doc/RubyMath/Erfc.html +189 -0
  117. data/doc/RubyMath/Exp.html +189 -0
  118. data/doc/RubyMath/Gamma.html +189 -0
  119. data/doc/RubyMath/Hypot.html +189 -0
  120. data/doc/RubyMath/Ldexp.html +189 -0
  121. data/doc/RubyMath/Log.html +189 -0
  122. data/doc/RubyMath/Log10.html +189 -0
  123. data/doc/RubyMath/Log2.html +189 -0
  124. data/doc/RubyMath/Neg.html +189 -0
  125. data/doc/RubyMath/Sin.html +189 -0
  126. data/doc/RubyMath/Sinh.html +189 -0
  127. data/doc/RubyMath/Sqrt.html +189 -0
  128. data/doc/RubyMath/Tan.html +189 -0
  129. data/doc/RubyMath/Tanh.html +189 -0
  130. data/doc/RubyStats.html +8 -8
  131. data/doc/RubyUnaryOperator.html +61 -65
  132. data/doc/ShortMDArray.html +69 -14
  133. data/doc/Sol.html +700 -0
  134. data/doc/Sol/BarChart.html +181 -0
  135. data/doc/Sol/BaseChart.html +800 -0
  136. data/doc/Sol/Bootstrap.html +1137 -0
  137. data/doc/Sol/Bridge.html +586 -0
  138. data/doc/Sol/Chart.html +1162 -0
  139. data/doc/Sol/CoordinateChart.html +679 -0
  140. data/doc/Sol/Dashboard.html +2094 -0
  141. data/doc/Sol/Dashboard/DCFX.html +786 -0
  142. data/doc/Sol/Dashboard/MyHandle.html +338 -0
  143. data/doc/Sol/Dashboard/MyService.html +202 -0
  144. data/doc/Sol/Dashboard/MyTask.html +291 -0
  145. data/doc/Sol/Interval.html +1213 -0
  146. data/doc/Sol/LineChart.html +346 -0
  147. data/doc/Sol/LinearScale.html +334 -0
  148. data/doc/Sol/Margins.html +219 -0
  149. data/doc/Sol/OrdinalScale.html +263 -0
  150. data/doc/Sol/Scale.html +462 -0
  151. data/doc/Sol/Stack.html +199 -0
  152. data/doc/Sol/TimeScale.html +397 -0
  153. data/doc/StatList.html +110 -125
  154. data/doc/StringMDArray.html +10 -10
  155. data/doc/StructureMDArray.html +10 -10
  156. data/doc/UnaryOperator.html +20 -21
  157. data/doc/UserFunction.html +51 -49
  158. data/doc/_index.html +881 -106
  159. data/doc/class_list.html +8 -3
  160. data/doc/css/style.css +2 -1
  161. data/doc/file.README.html +455 -104
  162. data/doc/file_list.html +7 -2
  163. data/doc/frames.html +5 -7
  164. data/doc/index.html +455 -104
  165. data/doc/js/app.js +7 -2
  166. data/doc/js/full_list.js +11 -3
  167. data/doc/method_list.html +3170 -1233
  168. data/doc/top-level-namespace.html +31 -8
  169. data/lib/colt/matrix/algebra.rb +5 -5
  170. data/lib/mdarray.rb +6 -3
  171. data/lib/mdarray/csv.rb +25 -5
  172. data/lib/mdarray/fast_operators.rb +1 -1
  173. data/lib/mdarray/function_creation.rb +3 -1
  174. data/lib/mdarray/hierarchy.rb +2 -0
  175. data/lib/mdarray/operators.rb +1 -1
  176. data/lib/mdarray/ruby_functions.rb +8 -4
  177. data/lib/mdarray/ruby_math.rb +0 -28
  178. data/test/colt/matrix/test_matrix2d_floatingalgebra.rb +31 -7
  179. data/test/complete.rb +4 -4
  180. data/test/mdarray/PETR4_2014.csv +249 -0
  181. data/test/mdarray/VALE_2014.csv +253 -0
  182. data/test/mdarray/VALE_PETR4.csv +501 -0
  183. data/test/mdarray/arithmetic_casting.rb +1 -0
  184. data/test/mdarray/test_access.rb +1 -0
  185. data/test/mdarray/test_boolean.rb +1 -0
  186. data/test/mdarray/test_comparison.rb +1 -0
  187. data/test/mdarray/test_complete.rb +2 -5
  188. data/test/mdarray/test_counter.rb +1 -0
  189. data/test/mdarray/test_creation.rb +1 -0
  190. data/test/mdarray/test_csv.rb +51 -0
  191. data/test/mdarray/test_error.rb +1 -0
  192. data/test/mdarray/test_non_numeric.rb +1 -1
  193. data/test/mdarray/test_operator.rb +31 -14
  194. data/test/mdarray/test_performance.rb +2 -1
  195. data/test/mdarray/test_printing.rb +1 -0
  196. data/test/mdarray/test_sections.rb +1 -0
  197. data/test/mdarray/test_shape.rb +1 -0
  198. data/test/mdarray/test_trigonometry.rb +1 -0
  199. data/test/mdarray/test_views.rb +1 -0
  200. data/vendor/mdarray.jar +0 -0
  201. data/vendor/{netcdfAll-4.5_0.jar → netcdfAll-4.6.jar} +0 -0
  202. data/vendor/slf4j-jdk14-1.7.12.jar +0 -0
  203. data/version.rb +1 -1
  204. metadata +247 -139
  205. data/lib/env.rb +0 -12
  206. data/lib/mdarray/lazy_mdarray.rb +0 -315
  207. data/lib/mdarray/lazy_operators.rb +0 -174
  208. data/test/env.rb +0 -8
  209. data/test/mdarray/test_lazy.rb +0 -306
data/lib/env.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'java'
2
- require_relative '../config.rb'
3
-
4
- $CLASSPATH << "#{File.dirname(__FILE__)}/../vendor/"
5
-
6
- Dir["#{File.dirname(__FILE__)}/../vendor/*.jar"].each do |jar|
7
- require jar
8
- end
9
-
10
- Dir["#{File.dirname(__FILE__)}/../target/*.jar"].each do |jar|
11
- require jar
12
- end
@@ -1,315 +0,0 @@
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
-
28
- class LazyMDArray < ByteMDArray
29
- include_package "ucar.ma2"
30
- include_package "org.codehaus.janino"
31
-
32
- attr_reader :stack
33
-
34
- #=======================================================================================
35
- # Class BinaryComp applies a function f to two arguments. The arguments can be
36
- # functions on their own right
37
- #=======================================================================================
38
-
39
- class BinaryComp
40
-
41
- def initialize(f, x, y, *args)
42
- @x = x
43
- @y = y
44
- @f = f
45
- @other_args = args
46
- end
47
-
48
- def apply
49
- @f.apply(@x.apply, @y.apply)
50
- end
51
-
52
- end # BinaryComp
53
-
54
- #=======================================================================================
55
- # Class UnaryComp applies a function f to one arguments. The arguments can be a
56
- # function on its own right
57
- #=======================================================================================
58
-
59
- class UnaryComp
60
-
61
- def initialize(f, x, *args)
62
- @x = x
63
- @f = f
64
- @other_args = args
65
- end
66
-
67
- def apply
68
- @f.apply(@x.apply)
69
- end
70
-
71
- end # UnaryComp
72
-
73
- #=======================================================================================
74
- #
75
- #=======================================================================================
76
-
77
-
78
- #---------------------------------------------------------------------------------------
79
- #
80
- #---------------------------------------------------------------------------------------
81
-
82
- def initialize
83
-
84
- @stack = Array.new
85
- @type = "lazy"
86
- @previous_binary_operator = nil
87
- @previous_unary_operator = nil
88
-
89
- end
90
-
91
- #---------------------------------------------------------------------------------------
92
- #
93
- #---------------------------------------------------------------------------------------
94
-
95
- def push(elmt)
96
- @stack << elmt
97
- end
98
-
99
- #---------------------------------------------------------------------------------------
100
- #
101
- #---------------------------------------------------------------------------------------
102
-
103
- def pop
104
- @stack.pop
105
- end
106
-
107
- #---------------------------------------------------------------------------------------
108
- #
109
- #---------------------------------------------------------------------------------------
110
-
111
- def test_janino_function
112
- $exp = ExpressionEvaluator.new
113
- $exp.setExpressionType(Java::CernColtFunctionTdouble::DoubleFunction.java_class)
114
- class_type = Java::JavaLang::Class.forName("java.lang.Class")
115
- array = Java::JavaLangReflect::Array.newInstance(class_type, 2)
116
- array[0] = Java::double.java_class
117
- array[1] = Java::double.java_class
118
- $exp.setParameters(["a", "b"].to_java(:string),
119
- array)
120
- $exp.cook("a + b")
121
- end
122
-
123
- #---------------------------------------------------------------------------------------
124
- #
125
- #---------------------------------------------------------------------------------------
126
-
127
- def apply(*args)
128
-
129
- type, shape, function = validate_fast(args)
130
-
131
- result = MDArray.build(type, shape)
132
- helper = Java::RbMdarrayLoopsLazy::DefaultLazyOperator
133
- helper.send("apply", result.nc_array, function)
134
- result
135
-
136
- end
137
-
138
- alias :[] :apply
139
-
140
- #---------------------------------------------------------------------------------------
141
- # Shows this LazyMDArray in Reverse Polish Notation. Mainly for debugging purposes.
142
- #---------------------------------------------------------------------------------------
143
-
144
- def rpn(nl = true)
145
-
146
- exp = String.new
147
-
148
- @stack.each do |elmt|
149
-
150
- if (elmt.is_a? LazyMDArray)
151
- exp << elmt.rpn(false)
152
- elsif (elmt.is_a? Numeric)
153
- exp << elmt << " "
154
- elsif (elmt.is_a? Operator)
155
- exp << elmt.name << " "
156
- elsif (elmt.is_a? MDArray)
157
- exp << elmt.type << " "
158
- else
159
- raise "Wrong element type in Array"
160
- end
161
-
162
- end
163
-
164
- exp
165
-
166
- end
167
-
168
- #---------------------------------------------------------------------------------------
169
- #
170
- #---------------------------------------------------------------------------------------
171
-
172
- def print
173
- Kernel.print "[Lazy MDArray]\n"
174
- p rpn
175
- end
176
-
177
- #---------------------------------------------------------------------------------------
178
- #
179
- #---------------------------------------------------------------------------------------
180
-
181
- protected
182
-
183
- #---------------------------------------------------------------------------------------
184
- # Validates the expression checking if it can be performed: all dimensions need to be
185
- # compatible
186
- #---------------------------------------------------------------------------------------
187
-
188
- def validate_fast(*args)
189
-
190
- # test_janino_function
191
- # p "validade_fast compile janino expression:"
192
- # $exp.apply(100, 100)
193
-
194
- helper_stack = Array.new
195
-
196
- @stack.each do |elmt|
197
-
198
- if (elmt.is_a? LazyMDArray)
199
- helper_stack << elmt.validate_fast(*args)
200
- elsif (elmt.is_a? MDArray)
201
- # helper_stack << [elmt.type, elmt.shape, index_func(elmt)]
202
- # iterator = elmt.nc_array.getIndexIterator
203
- java_proc = Java::RbMdarrayUtil::Util.getIterator(elmt.nc_array)
204
- helper_stack << [elmt.type, elmt.shape, java_proc]
205
- elsif (elmt.is_a? Numeric)
206
- # const_func is inefficient... fix!!!
207
- helper_stack << ["numeric", 1, const_func(elmt)]
208
- elsif (elmt.is_a? Operator)
209
- case elmt.arity
210
- when 1
211
- top = helper_stack.pop
212
- fmap = MDArray.select_function(elmt.name, MDArray.functions, top[0],
213
- top[0], "void")
214
- helper_stack <<
215
- [top[0], top[1],
216
- # UnaryComp.new(top[2], fmap.function, elmt.other_args)]
217
- Java::RbMdarrayUtil::Util.compose(fmap.function, top[2])]
218
- when 2
219
- top1, top2 = helper_stack.pop(2)
220
- if (top1[1] != top2[1] && top1[0] != "numeric" && top2[0] != "numeric")
221
- raise "Expression involves incopatible arrays. #{top1[1]} != #{top2[1]}"
222
- end
223
- type = MDArray.upcast(top1[0], top2[0])
224
- fmap = MDArray.select_function(elmt.name, MDArray.functions, type, type, type)
225
- helper_stack <<
226
- [type, top1[1],
227
- Java::RbMdarrayUtil::Util.compose(fmap.function, top1[2], top2[2])]
228
- end
229
- else
230
- raise "Expression is invalid: element #{elmt} is not valid in this position."
231
- end
232
-
233
- end
234
-
235
- helper_stack[0]
236
-
237
- end
238
-
239
- #---------------------------------------------------------------------------------------
240
- #
241
- #---------------------------------------------------------------------------------------
242
-
243
- private
244
-
245
- #---------------------------------------------------------------------------------------
246
- #
247
- #---------------------------------------------------------------------------------------
248
-
249
- def const_func(val)
250
- Proc.new { |index| val }
251
- end
252
-
253
- #---------------------------------------------------------------------------------------
254
- #
255
- #---------------------------------------------------------------------------------------
256
-
257
- def index_func(a)
258
- Proc.new { |index| a.jget(index) }
259
- end
260
-
261
- #---------------------------------------------------------------------------------------
262
- #
263
- #---------------------------------------------------------------------------------------
264
-
265
- def get_next_func(a)
266
- Proc.new { a.getObjectNext() }
267
- end
268
-
269
- #---------------------------------------------------------------------------------------
270
- #
271
- #---------------------------------------------------------------------------------------
272
-
273
- def binary_function_next(proc1, proc2, f, *args)
274
- Proc.new { f.call(proc1.apply, proc2.apply, *args) }
275
- end
276
-
277
- end # LazyMDArray
278
-
279
- ##########################################################################################
280
- #
281
- ##########################################################################################
282
-
283
- class MDArray
284
-
285
- #---------------------------------------------------------------------------------------
286
- #
287
- #---------------------------------------------------------------------------------------
288
-
289
- def self.set_lazy(flag = true)
290
-
291
- if (flag)
292
- if (MDArray.binary_operator != LazyBinaryOperator)
293
- MDArray.previous_binary_operator = MDArray.binary_operator
294
- MDArray.previous_unary_operator = MDArray.unary_operator
295
- end
296
- MDArray.binary_operator = LazyBinaryOperator
297
- MDArray.unary_operator = LazyUnaryOperator
298
- else
299
- MDArray.binary_operator = MDArray.previous_binary_operator if MDArray.previous_binary_operator != nil
300
- MDArray.unary_operator = MDArray.previous_unary_operator if MDArray.previous_unary_operator != nil
301
- end
302
-
303
- end
304
-
305
- #---------------------------------------------------------------------------------------
306
- #
307
- #---------------------------------------------------------------------------------------
308
-
309
- def self.lazy=(flag)
310
- set_lazy(flag)
311
- end
312
-
313
- end
314
-
315
- require_relative 'lazy_operators'
@@ -1,174 +0,0 @@
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 LazyBinaryOperator < BinaryOperator
28
-
29
- attr_reader :exp # expression in string format
30
-
31
- #---------------------------------------------------------------------------------------
32
- #
33
- #---------------------------------------------------------------------------------------
34
-
35
- def get_args(*args)
36
-
37
- @op1 = args.shift
38
- @op2 = args.shift
39
- @other_args = args
40
- @exp = ""
41
-
42
- end
43
-
44
- #---------------------------------------------------------------------------------------
45
- # A default binary operator takes two arrays where one array can be degenerated (a
46
- # number and loops through all elements of the arrays applying a given method to them.
47
- # For instance, operator '+' in a + b is a default binary operator.
48
- #---------------------------------------------------------------------------------------
49
-
50
- def default(*args)
51
-
52
- get_args(*args)
53
- lazy = @op1
54
-
55
- if (@op1.is_a? LazyMDArray)
56
- lazy.push(@op2)
57
- lazy.push(self)
58
- # @exp << "(" << @op1.exp << name << @op2.id << ")"
59
- else
60
- lazy = LazyMDArray.new
61
- lazy.push(@op1)
62
- lazy.push(@op2)
63
- lazy.push(self)
64
- # p @op1.id
65
- # p @op2.id
66
- # p @name
67
- # @exp << "(" << @op1.id << name << @op2.id << ")"
68
- end
69
-
70
- return lazy
71
-
72
- end
73
-
74
- #---------------------------------------------------------------------------------------
75
- # A fill binary operator takes two arrays where one array can be degenerated (a number)
76
- # and loops through all elements of the arrays, setting the value of the first array
77
- # to the values of the second.
78
- #---------------------------------------------------------------------------------------
79
-
80
- def fill(*args)
81
- raise "Cannot fill array lazyly"
82
- end
83
-
84
- #---------------------------------------------------------------------------------------
85
- #
86
- #---------------------------------------------------------------------------------------
87
-
88
- def in_place(*args)
89
- raise "Cannot operate in_place lazyly"
90
- end
91
-
92
- #---------------------------------------------------------------------------------------
93
- #
94
- #---------------------------------------------------------------------------------------
95
-
96
- def reduce(*args)
97
- raise "Cannot reduce array in lazy operation"
98
- end
99
-
100
- #---------------------------------------------------------------------------------------
101
- #
102
- #---------------------------------------------------------------------------------------
103
-
104
- def complex_reduce(*args)
105
- raise "Cannot reduce array in lazy operation"
106
- end
107
-
108
- end # LazyBinaryOperator
109
-
110
- ##########################################################################################
111
- #
112
- ##########################################################################################
113
-
114
- class LazyUnaryOperator < UnaryOperator
115
-
116
- #---------------------------------------------------------------------------------------
117
- #
118
- #---------------------------------------------------------------------------------------
119
-
120
- def get_args(*args)
121
-
122
- @op = args.shift
123
- @other_args = args
124
-
125
- end
126
-
127
- #---------------------------------------------------------------------------------------
128
- # A default unary operator takes one arrays and loops through all elements of the array
129
- # applying a given method to it. For instance, operator 'log' in a.log is a default
130
- # unary operator.
131
- #---------------------------------------------------------------------------------------
132
-
133
- def default(*args)
134
-
135
- get_args(*args)
136
- lazy = @op
137
-
138
- if (@op.is_a? LazyMDArray)
139
- lazy.push(self)
140
- else
141
- lazy = LazyMDArray.new
142
- lazy.push(@op)
143
- lazy.push(self)
144
- end
145
-
146
- return lazy
147
-
148
- end
149
-
150
- #---------------------------------------------------------------------------------------
151
- #
152
- #---------------------------------------------------------------------------------------
153
-
154
- def in_place(*args)
155
- raise "Cannot operate in_place lazyly"
156
- end
157
-
158
- #---------------------------------------------------------------------------------------
159
- #
160
- #---------------------------------------------------------------------------------------
161
-
162
- def reduce(*args)
163
- raise "Cannot reduce array in lazy operation"
164
- end
165
-
166
- #---------------------------------------------------------------------------------------
167
- #
168
- #---------------------------------------------------------------------------------------
169
-
170
- def complex_reduce(*args)
171
- raise "Cannot reduce array in lazy operation"
172
- end
173
-
174
- end # LazyUnaryOperator