mdarray 0.4.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.
- data/LICENSE.txt +54 -0
- data/LICENSE.txt~ +32 -0
- data/README.md +21 -0
- data/Rakefile +40 -0
- data/lib/env.rb +11 -0
- data/lib/mdarray.rb +414 -0
- data/lib/mdarray/access.rb +237 -0
- data/lib/mdarray/counter.rb +779 -0
- data/lib/mdarray/creation.rb +413 -0
- data/lib/mdarray/fast_non_numerical.rb +102 -0
- data/lib/mdarray/function_creation.rb +100 -0
- data/lib/mdarray/function_map.rb +56 -0
- data/lib/mdarray/hierarchy.rb +177 -0
- data/lib/mdarray/operators.rb +220 -0
- data/lib/mdarray/printing.rb +275 -0
- data/lib/mdarray/proc_util.rb +159 -0
- data/lib/mdarray/ruby_functions.rb +78 -0
- data/lib/mdarray/ruby_generic_functions.rb +37 -0
- data/lib/mdarray/ruby_math.rb +57 -0
- data/lib/mdarray/ruby_numeric_functions.rb +187 -0
- data/lib/mdarray/ruby_operators.rb +201 -0
- data/lib/mdarray/ruby_stats.rb +149 -0
- data/lib/mdarray/slices.rb +185 -0
- data/lib/mdarray/statistics.rb +86 -0
- data/test/arithmetic_casting.rb +195 -0
- data/test/env.rb +50 -0
- data/test/test_access.rb +247 -0
- data/test/test_boolean.rb +67 -0
- data/test/test_comparison.rb +126 -0
- data/test/test_complete.rb +69 -0
- data/test/test_counter.rb +184 -0
- data/test/test_creation.rb +364 -0
- data/test/test_error.rb +53 -0
- data/test/test_lazy.rb +52 -0
- data/test/test_operator.rb +337 -0
- data/test/test_printing.rb +66 -0
- data/test/test_shape.rb +96 -0
- data/test/test_slices.rb +146 -0
- data/test/test_speed.rb +311 -0
- data/test/test_statistics.rb +45 -0
- data/test/test_trigonometry.rb +60 -0
- data/vendor/netcdfAll-4.3.16.jar +0 -0
- data/version.rb +2 -0
- metadata +197 -0
@@ -0,0 +1,100 @@
|
|
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, without fee and without a signed
|
6
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
7
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
8
|
+
# distributions.
|
9
|
+
#
|
10
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
11
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
12
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
13
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
#
|
15
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
16
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
17
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
18
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
19
|
+
# OR MODIFICATIONS.
|
20
|
+
##########################################################################################
|
21
|
+
|
22
|
+
##########################################################################################
|
23
|
+
#
|
24
|
+
##########################################################################################
|
25
|
+
|
26
|
+
module FunctionCreation
|
27
|
+
|
28
|
+
#------------------------------------------------------------------------------------
|
29
|
+
#
|
30
|
+
#------------------------------------------------------------------------------------
|
31
|
+
|
32
|
+
def make_binary_op(name, exec_type, func, force_type = nil, pre_condition = nil,
|
33
|
+
post_condition = nil)
|
34
|
+
|
35
|
+
define_method(name) do |op2, requested_type = nil, *args|
|
36
|
+
binary_op = get_binary_op
|
37
|
+
op = binary_op.new(name, exec_type, force_type, pre_condition, post_condition)
|
38
|
+
op.exec(self, op2, requested_type, *args)
|
39
|
+
end
|
40
|
+
|
41
|
+
MDArray.register_function(name, func)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
#------------------------------------------------------------------------------------
|
46
|
+
#
|
47
|
+
#------------------------------------------------------------------------------------
|
48
|
+
|
49
|
+
def make_binary_operators(name, func, default = true, in_place = true)
|
50
|
+
|
51
|
+
if (default)
|
52
|
+
make_binary_op(name, "default", func)
|
53
|
+
end
|
54
|
+
if (in_place)
|
55
|
+
make_binary_op(name + "!", "in_place", func)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
#------------------------------------------------------------------------------------
|
61
|
+
#
|
62
|
+
#------------------------------------------------------------------------------------
|
63
|
+
|
64
|
+
def make_unary_op(name, exec_type, func, force_type = nil, pre_condition = nil,
|
65
|
+
post_condition = nil)
|
66
|
+
|
67
|
+
define_method(name) do |requested_type = nil, *args|
|
68
|
+
unary_op = get_unary_op
|
69
|
+
op = unary_op.new(name, exec_type, force_type, pre_condition, post_condition)
|
70
|
+
op.exec(self, requested_type, *args)
|
71
|
+
end
|
72
|
+
|
73
|
+
MDArray.register_function(name, func)
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
#------------------------------------------------------------------------------------
|
78
|
+
#
|
79
|
+
#------------------------------------------------------------------------------------
|
80
|
+
|
81
|
+
def make_unary_operators(name, func, default = true, in_place = true)
|
82
|
+
|
83
|
+
if (default)
|
84
|
+
make_unary_op(name, "default", func)
|
85
|
+
end
|
86
|
+
if (in_place)
|
87
|
+
make_unary_op(name + "!", "in_place", func)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
#------------------------------------------------------------------------------------
|
93
|
+
#
|
94
|
+
#------------------------------------------------------------------------------------
|
95
|
+
|
96
|
+
def make_comparison_op(name, func)
|
97
|
+
make_binary_op(name, "default", func, "boolean")
|
98
|
+
end
|
99
|
+
|
100
|
+
end # FunctionCreation
|
@@ -0,0 +1,56 @@
|
|
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, without fee and without a signed
|
6
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
7
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
8
|
+
# distributions.
|
9
|
+
#
|
10
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
11
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
12
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
13
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
#
|
15
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
16
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
17
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
18
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
19
|
+
# OR MODIFICATIONS.
|
20
|
+
##########################################################################################
|
21
|
+
|
22
|
+
##########################################################################################
|
23
|
+
#
|
24
|
+
##########################################################################################
|
25
|
+
|
26
|
+
class FunctionMap
|
27
|
+
|
28
|
+
attr_reader :short_name
|
29
|
+
attr_reader :long_name
|
30
|
+
attr_reader :scope
|
31
|
+
attr_reader :function
|
32
|
+
attr_reader :return_type
|
33
|
+
attr_reader :input1_type
|
34
|
+
attr_reader :input2_type
|
35
|
+
|
36
|
+
attr_accessor :description
|
37
|
+
|
38
|
+
#------------------------------------------------------------------------------------
|
39
|
+
#
|
40
|
+
#------------------------------------------------------------------------------------
|
41
|
+
|
42
|
+
def initialize(short_name, long_name, scope, function, return_type, input1_type,
|
43
|
+
input2_type)
|
44
|
+
|
45
|
+
@short_name = short_name
|
46
|
+
@long_name = long_name
|
47
|
+
@scope = scope
|
48
|
+
@function = function
|
49
|
+
@return_type = return_type
|
50
|
+
@input1_type = input1_type
|
51
|
+
@input2_type = input2_type
|
52
|
+
|
53
|
+
end # initialize
|
54
|
+
|
55
|
+
end # FunctionMap
|
56
|
+
|
@@ -0,0 +1,177 @@
|
|
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, without fee and without a signed
|
6
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
7
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
8
|
+
# distributions.
|
9
|
+
#
|
10
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
11
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
12
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
13
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
#
|
15
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
16
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
17
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
18
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
19
|
+
# OR MODIFICATIONS.
|
20
|
+
##########################################################################################
|
21
|
+
|
22
|
+
##########################################################################################
|
23
|
+
#
|
24
|
+
##########################################################################################
|
25
|
+
|
26
|
+
class NumericalMDArray < MDArray
|
27
|
+
|
28
|
+
def coerce(num)
|
29
|
+
coerced_mdarray = coerced_build(@type, @nc_array)
|
30
|
+
[coerced_mdarray, num]
|
31
|
+
end
|
32
|
+
|
33
|
+
end # NumericalMDArray
|
34
|
+
|
35
|
+
##########################################################################################
|
36
|
+
#
|
37
|
+
##########################################################################################
|
38
|
+
|
39
|
+
class DoubleMDArray < NumericalMDArray
|
40
|
+
|
41
|
+
end # DoubleMDArray
|
42
|
+
|
43
|
+
##########################################################################################
|
44
|
+
#
|
45
|
+
##########################################################################################
|
46
|
+
|
47
|
+
class FloatMDArray < DoubleMDArray
|
48
|
+
|
49
|
+
end # FloatMDArray
|
50
|
+
|
51
|
+
##########################################################################################
|
52
|
+
#
|
53
|
+
##########################################################################################
|
54
|
+
|
55
|
+
class LongMDArray < FloatMDArray
|
56
|
+
|
57
|
+
end # LongMDArray
|
58
|
+
|
59
|
+
##########################################################################################
|
60
|
+
#
|
61
|
+
##########################################################################################
|
62
|
+
|
63
|
+
class IntMDArray < LongMDArray
|
64
|
+
|
65
|
+
end # IntMDArray
|
66
|
+
|
67
|
+
##########################################################################################
|
68
|
+
#
|
69
|
+
##########################################################################################
|
70
|
+
|
71
|
+
class ShortMDArray < IntMDArray
|
72
|
+
|
73
|
+
end # ShortMDArray
|
74
|
+
|
75
|
+
##########################################################################################
|
76
|
+
#
|
77
|
+
##########################################################################################
|
78
|
+
|
79
|
+
class ByteMDArray < ShortMDArray
|
80
|
+
|
81
|
+
end # ByteMDArray
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
##########################################################################################
|
86
|
+
#
|
87
|
+
##########################################################################################
|
88
|
+
|
89
|
+
# Non numerical arrays
|
90
|
+
|
91
|
+
##########################################################################################
|
92
|
+
#
|
93
|
+
##########################################################################################
|
94
|
+
|
95
|
+
class NonNumericalMDArray < MDArray
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
##########################################################################################
|
100
|
+
#
|
101
|
+
##########################################################################################
|
102
|
+
|
103
|
+
class BooleanMDArray < NonNumericalMDArray
|
104
|
+
|
105
|
+
#------------------------------------------------------------------------------------
|
106
|
+
#
|
107
|
+
#------------------------------------------------------------------------------------
|
108
|
+
|
109
|
+
def self.make_boolean_op(name, func)
|
110
|
+
define_method(name) do |other_val|
|
111
|
+
boolean_op(other_val, func)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
#---------------------------------------------------------------------------------------
|
116
|
+
#
|
117
|
+
#---------------------------------------------------------------------------------------
|
118
|
+
|
119
|
+
def boolean_op(other_val, method)
|
120
|
+
result = MDArray.build("boolean", shape)
|
121
|
+
exec_boolean_op(result, other_val, method)
|
122
|
+
end
|
123
|
+
|
124
|
+
#======================================================================================
|
125
|
+
# Logical
|
126
|
+
#======================================================================================
|
127
|
+
|
128
|
+
def self.and(val1, val2)
|
129
|
+
val1 and val2
|
130
|
+
end
|
131
|
+
|
132
|
+
#------------------------------------------------------------------------------------
|
133
|
+
#
|
134
|
+
#------------------------------------------------------------------------------------
|
135
|
+
|
136
|
+
def self.or(val1, val2)
|
137
|
+
val1 or val2
|
138
|
+
end
|
139
|
+
|
140
|
+
#------------------------------------------------------------------------------------
|
141
|
+
#
|
142
|
+
#------------------------------------------------------------------------------------
|
143
|
+
|
144
|
+
def self.not(val1)
|
145
|
+
!val1
|
146
|
+
end
|
147
|
+
|
148
|
+
#------------------------------------------------------------------------------------
|
149
|
+
#
|
150
|
+
#------------------------------------------------------------------------------------
|
151
|
+
|
152
|
+
# make_binary_methods("and", BooleanMDArray.method(:and))
|
153
|
+
# make_binary_methods("or", BooleanMDArray.method(:or))
|
154
|
+
|
155
|
+
make_boolean_op("and", BooleanMDArray.method(:and))
|
156
|
+
make_boolean_op("or", BooleanMDArray.method(:or))
|
157
|
+
|
158
|
+
alias :| :or
|
159
|
+
alias :& :and
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
##########################################################################################
|
164
|
+
#
|
165
|
+
##########################################################################################
|
166
|
+
|
167
|
+
class StringMDArray < NonNumericalMDArray
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
##########################################################################################
|
172
|
+
#
|
173
|
+
##########################################################################################
|
174
|
+
|
175
|
+
class StructureMDArray < NonNumericalMDArray
|
176
|
+
|
177
|
+
end
|
@@ -0,0 +1,220 @@
|
|
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, without fee and without a signed
|
6
|
+
# licensing agreement, is hereby granted, provided that the above copyright notice, this
|
7
|
+
# paragraph and the following two paragraphs appear in all copies, modifications, and
|
8
|
+
# distributions.
|
9
|
+
#
|
10
|
+
# IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
11
|
+
# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
12
|
+
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
|
13
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
#
|
15
|
+
# RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
16
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
17
|
+
# SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
|
18
|
+
# RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
19
|
+
# OR MODIFICATIONS.
|
20
|
+
##########################################################################################
|
21
|
+
|
22
|
+
# example of how to access a protected field on the java superclass
|
23
|
+
# class Java::OrgJquantlibMathMatrixutilities::Array
|
24
|
+
# field_accessor :addr
|
25
|
+
# end
|
26
|
+
|
27
|
+
##########################################################################################
|
28
|
+
#
|
29
|
+
##########################################################################################
|
30
|
+
|
31
|
+
class Const
|
32
|
+
|
33
|
+
attr_reader :value
|
34
|
+
|
35
|
+
#---------------------------------------------------------------------------------------
|
36
|
+
#
|
37
|
+
#---------------------------------------------------------------------------------------
|
38
|
+
|
39
|
+
def initialize(value)
|
40
|
+
@value = value
|
41
|
+
end
|
42
|
+
|
43
|
+
#---------------------------------------------------------------------------------------
|
44
|
+
#
|
45
|
+
#---------------------------------------------------------------------------------------
|
46
|
+
|
47
|
+
def get_iterator_fast
|
48
|
+
return self
|
49
|
+
end
|
50
|
+
|
51
|
+
#---------------------------------------------------------------------------------------
|
52
|
+
#
|
53
|
+
#---------------------------------------------------------------------------------------
|
54
|
+
|
55
|
+
def get_next
|
56
|
+
@value
|
57
|
+
end
|
58
|
+
|
59
|
+
#---------------------------------------------------------------------------------------
|
60
|
+
#
|
61
|
+
#---------------------------------------------------------------------------------------
|
62
|
+
|
63
|
+
def get_current
|
64
|
+
@value
|
65
|
+
end
|
66
|
+
|
67
|
+
end # Const
|
68
|
+
|
69
|
+
##########################################################################################
|
70
|
+
#
|
71
|
+
##########################################################################################
|
72
|
+
|
73
|
+
class Operator
|
74
|
+
|
75
|
+
attr_reader :name
|
76
|
+
attr_reader :type # resulting type of the operation
|
77
|
+
attr_reader :arity # number of arguments to the operator
|
78
|
+
attr_reader :exec_type # type of operator execution, e.g., default, in_place, numeric
|
79
|
+
attr_reader :force_type # force this type as the result type
|
80
|
+
attr_reader :pre_condition # proc to be executed before the operator's execution
|
81
|
+
attr_reader :post_condition # proc to be executed after the operator's execution
|
82
|
+
|
83
|
+
#---------------------------------------------------------------------------------------
|
84
|
+
#
|
85
|
+
#---------------------------------------------------------------------------------------
|
86
|
+
|
87
|
+
def initialize(name, arity, exec_type, force_type = nil, pre_condition = nil,
|
88
|
+
post_condition = nil)
|
89
|
+
|
90
|
+
@name = name
|
91
|
+
@arity = arity
|
92
|
+
@exec_type = exec_type
|
93
|
+
@force_type = force_type
|
94
|
+
@pre_condition = pre_condition # proc to be executed before the main loop
|
95
|
+
@pre_condition_result = nil
|
96
|
+
@post_condition = post_condition # proc to be executed after the main loop
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
#---------------------------------------------------------------------------------------
|
101
|
+
#
|
102
|
+
#---------------------------------------------------------------------------------------
|
103
|
+
|
104
|
+
def exec(*args)
|
105
|
+
|
106
|
+
@pre_condition_result = @pre_condition.call(*args) if @pre_condition
|
107
|
+
result = method(@exec_type).call(*args)
|
108
|
+
(@post_condition)? @post_condition.call(result, *args) : result
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end # Operator
|
113
|
+
|
114
|
+
##########################################################################################
|
115
|
+
#
|
116
|
+
##########################################################################################
|
117
|
+
|
118
|
+
class BinaryOperator < Operator
|
119
|
+
|
120
|
+
#---------------------------------------------------------------------------------------
|
121
|
+
#
|
122
|
+
#---------------------------------------------------------------------------------------
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
#---------------------------------------------------------------------------------------
|
127
|
+
#
|
128
|
+
#---------------------------------------------------------------------------------------
|
129
|
+
|
130
|
+
def parse_args(*args)
|
131
|
+
|
132
|
+
@op1 = args.shift
|
133
|
+
@op2 = args.shift
|
134
|
+
requested_type = args.shift
|
135
|
+
@type = (@force_type)? @force_type : (requested_type)? requested_type :
|
136
|
+
@op1.get_type(@op2)
|
137
|
+
@coerced = @op1.coerced
|
138
|
+
func = MDArray.select_function(@name, MDArray.functions, @type)
|
139
|
+
if (func.is_a? Proc)
|
140
|
+
@do_func = func.dup
|
141
|
+
else
|
142
|
+
@do_func = func
|
143
|
+
end
|
144
|
+
@other_args = args
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
#---------------------------------------------------------------------------------------
|
149
|
+
#
|
150
|
+
#---------------------------------------------------------------------------------------
|
151
|
+
|
152
|
+
def get_args(*args)
|
153
|
+
|
154
|
+
parse_args(*args)
|
155
|
+
if (@op2.is_a? Numeric)
|
156
|
+
op2_iterator = Const.new(@op2)
|
157
|
+
elsif (@op2.is_a? NumericalMDArray)
|
158
|
+
if (@op1.compatible(@op2))
|
159
|
+
op2_iterator = @op2.get_iterator_fast
|
160
|
+
else
|
161
|
+
raise "Invalid operation - arrays are incompatible"
|
162
|
+
end
|
163
|
+
else
|
164
|
+
false
|
165
|
+
# *TODO: make it more general using coerce if other_val type is not recognized
|
166
|
+
# if (arg is not recognized)
|
167
|
+
# self_equiv, arg_equiv = arg.coerce(self)
|
168
|
+
# self_equiv * arg_equiv
|
169
|
+
# end
|
170
|
+
end
|
171
|
+
|
172
|
+
yield @op1.get_iterator_fast, op2_iterator, @op1.shape, *@other_args
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
end # BinaryOperator
|
177
|
+
|
178
|
+
##########################################################################################
|
179
|
+
#
|
180
|
+
##########################################################################################
|
181
|
+
|
182
|
+
class UnaryOperator < Operator
|
183
|
+
|
184
|
+
#---------------------------------------------------------------------------------------
|
185
|
+
#
|
186
|
+
#---------------------------------------------------------------------------------------
|
187
|
+
|
188
|
+
private
|
189
|
+
|
190
|
+
#---------------------------------------------------------------------------------------
|
191
|
+
#
|
192
|
+
#---------------------------------------------------------------------------------------
|
193
|
+
|
194
|
+
def parse_args(*args)
|
195
|
+
|
196
|
+
@op = args.shift
|
197
|
+
requested_type = args.shift
|
198
|
+
@type = (@force_type)? @force_type : (requested_type)? requested_type : @op.type
|
199
|
+
func = MDArray.select_function(@name, MDArray.functions, @type)
|
200
|
+
if (func.is_a? Proc)
|
201
|
+
@do_func = func.dup
|
202
|
+
else
|
203
|
+
@do_func = func
|
204
|
+
end
|
205
|
+
@other_args = args
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
#---------------------------------------------------------------------------------------
|
210
|
+
#
|
211
|
+
#---------------------------------------------------------------------------------------
|
212
|
+
|
213
|
+
def get_args(*args)
|
214
|
+
|
215
|
+
parse_args(*args)
|
216
|
+
yield @op.get_iterator_fast, @op.shape, *@other_args
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
end # UnaryOperator
|