red_amber 0.3.0 → 0.4.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +39 -20
- data/.yardopts +2 -0
- data/CHANGELOG.md +113 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +25 -26
- data/benchmark/basic.yml +2 -2
- data/benchmark/combine.yml +2 -2
- data/benchmark/dataframe.yml +2 -2
- data/benchmark/group.yml +2 -2
- data/benchmark/reshape.yml +2 -2
- data/benchmark/vector.yml +3 -0
- data/doc/DataFrame.md +32 -12
- data/doc/DataFrame_Comparison.md +65 -0
- data/doc/SubFrames.md +11 -0
- data/doc/Vector.md +207 -1
- data/doc/yard-templates/default/fulldoc/html/css/common.css +6 -0
- data/lib/red_amber/data_frame.rb +429 -75
- data/lib/red_amber/data_frame_combinable.rb +516 -66
- data/lib/red_amber/data_frame_displayable.rb +244 -14
- data/lib/red_amber/data_frame_indexable.rb +121 -18
- data/lib/red_amber/data_frame_loadsave.rb +78 -10
- data/lib/red_amber/data_frame_reshaping.rb +184 -14
- data/lib/red_amber/data_frame_selectable.rb +622 -66
- data/lib/red_amber/data_frame_variable_operation.rb +446 -34
- data/lib/red_amber/group.rb +187 -22
- data/lib/red_amber/helper.rb +70 -10
- data/lib/red_amber/refinements.rb +12 -5
- data/lib/red_amber/subframes.rb +1066 -0
- data/lib/red_amber/vector.rb +385 -11
- data/lib/red_amber/vector_aggregation.rb +312 -0
- data/lib/red_amber/vector_binary_element_wise.rb +387 -0
- data/lib/red_amber/vector_selectable.rb +217 -12
- data/lib/red_amber/vector_unary_element_wise.rb +436 -0
- data/lib/red_amber/vector_updatable.rb +278 -34
- data/lib/red_amber/version.rb +2 -1
- data/lib/red_amber.rb +13 -1
- data/red_amber.gemspec +2 -2
- metadata +13 -8
- data/doc/image/dataframe/reshaping_DataFrames.png +0 -0
- data/lib/red_amber/vector_functions.rb +0 -242
@@ -0,0 +1,312 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Available functions in Arrow are shown by `Arrow::Function.all.map(&:name)`
|
4
|
+
# reference: https://arrow.apache.org/docs/cpp/compute.html
|
5
|
+
|
6
|
+
module RedAmber
|
7
|
+
# Representing a series of data.
|
8
|
+
class Vector
|
9
|
+
class << self
|
10
|
+
private
|
11
|
+
|
12
|
+
# @!macro [attach] define_unary_aggregation
|
13
|
+
# [Unary aggregation function] Returns a scalar.
|
14
|
+
#
|
15
|
+
def define_unary_aggregation(function)
|
16
|
+
define_method(function) do |**options|
|
17
|
+
datum = exec_func_unary(function, options)
|
18
|
+
get_scalar(datum)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Not implemented in red-arrow yet:
|
24
|
+
# Arrow::Indexoptions, Arrow::ModeOptions, Arrow::TDigestOptions
|
25
|
+
|
26
|
+
# @!macro scalar_aggregate_options
|
27
|
+
# @param skip_nulls [true, false]
|
28
|
+
# If true, nil values are ignored.
|
29
|
+
# Otherwise, if any value is nil, emit nil.
|
30
|
+
# @param min_count [Integer]
|
31
|
+
# if less than this many non-nil values are observed, emit nil.
|
32
|
+
# If skip_nulls is false, this option is not respected.
|
33
|
+
|
34
|
+
# @!macro count_options
|
35
|
+
# @param mode [:only_valid, :only_null, :all]
|
36
|
+
# control count aggregate kernel behavior.
|
37
|
+
# - only_valid: count only non-nil values.
|
38
|
+
# - only_null: count only nil.
|
39
|
+
# - all: count both.
|
40
|
+
|
41
|
+
# @!macro variance_options
|
42
|
+
# @param ddof [0, 1]
|
43
|
+
# Control Delta Degrees of Freedom (ddof) of Variance and Stddev kernel.
|
44
|
+
# The divisor used in calculations is N - ddof, where N is the number
|
45
|
+
# of elements. By default, ddof is zero, and population variance or stddev
|
46
|
+
# is returned.
|
47
|
+
# @macro scalar_aggregate_options
|
48
|
+
|
49
|
+
# Test whether all elements in self are evaluated to true.
|
50
|
+
#
|
51
|
+
# @!method all(skip_nulls: true, min_count: 1)
|
52
|
+
# @macro scalar_aggregate_options
|
53
|
+
# @return [true, false]
|
54
|
+
# `all` result of self.
|
55
|
+
# @example Default.
|
56
|
+
# Vector.new(true, true, nil).all # => true
|
57
|
+
#
|
58
|
+
# @example Skip nils.
|
59
|
+
# Vector.new(true, true, nil).all(skip_nulls: false) # => false
|
60
|
+
#
|
61
|
+
define_unary_aggregation :all
|
62
|
+
alias_method :all?, :all
|
63
|
+
|
64
|
+
# Test whether any elements in self are evaluated to true.
|
65
|
+
#
|
66
|
+
# @!method any(skip_nulls: true, min_count: 1)
|
67
|
+
# @macro scalar_aggregate_options
|
68
|
+
# @return [true, false]
|
69
|
+
# `any` result of self.
|
70
|
+
# @example Default.
|
71
|
+
# Vector.new(true, false, nil).any # => true
|
72
|
+
#
|
73
|
+
define_unary_aggregation :any
|
74
|
+
alias_method :any?, :any
|
75
|
+
|
76
|
+
# Approximate median of a numeric Vector with T-Digest algorithm.
|
77
|
+
#
|
78
|
+
# @!method approximate_median(skip_nulls: true, min_count: 1)
|
79
|
+
# @macro scalar_aggregate_options
|
80
|
+
# @return [Float]
|
81
|
+
# median of self.
|
82
|
+
# A nil is returned if there is no valid data point.
|
83
|
+
#
|
84
|
+
define_unary_aggregation :approximate_median
|
85
|
+
alias_method :median, :approximate_median
|
86
|
+
|
87
|
+
# Count the number of nil / non-nil values.
|
88
|
+
#
|
89
|
+
# @!method count(mode: :non_null)
|
90
|
+
# @macro count_options
|
91
|
+
# @return [Integer] count of self.
|
92
|
+
# @example Count only non-nil (default)
|
93
|
+
# Vector.new(1.0, -2.0, Float::NAN, nil).count # => 3
|
94
|
+
#
|
95
|
+
# @example Count nil only.
|
96
|
+
# Vector.new(1.0, -2.0, Float::NAN, nil).count(mode: :only_null) # => 1
|
97
|
+
#
|
98
|
+
# @example Count both non-nil and nil.
|
99
|
+
# Vector.new(1.0, -2.0, Float::NAN, nil).count(mode: :all) # => 4
|
100
|
+
#
|
101
|
+
define_unary_aggregation :count
|
102
|
+
|
103
|
+
# Count the number of unique values.
|
104
|
+
#
|
105
|
+
# @!method count_distinct(mode: :only_valid)
|
106
|
+
# @macro count_options
|
107
|
+
# @return [Integer]
|
108
|
+
# unique count of self.
|
109
|
+
# @example
|
110
|
+
# vector = Vector.new(1, 1.0, nil, nil, Float::NAN, Float::NAN)
|
111
|
+
# vector
|
112
|
+
#
|
113
|
+
# # =>
|
114
|
+
# #<RedAmber::Vector(:double, size=6):0x000000000000d390>
|
115
|
+
# [1.0, 1.0, nil, nil, NaN, NaN]
|
116
|
+
#
|
117
|
+
# # Float::NANs are counted as 1.
|
118
|
+
# vector.count_uniq # => 2
|
119
|
+
#
|
120
|
+
# # nils are counted as 1.
|
121
|
+
# vector.count_uniq(mode: :only_null) # => 1
|
122
|
+
#
|
123
|
+
# vector.count_uniq(mode: :all) # => 3
|
124
|
+
#
|
125
|
+
define_unary_aggregation :count_distinct
|
126
|
+
alias_method :count_uniq, :count_distinct
|
127
|
+
|
128
|
+
# Compute maximum value of self.
|
129
|
+
#
|
130
|
+
# @!method max(skip_nulls: true, min_count: 1)
|
131
|
+
# @macro scalar_aggregate_options
|
132
|
+
# @return [Numeric]
|
133
|
+
# maximum value of self.
|
134
|
+
#
|
135
|
+
define_unary_aggregation :max
|
136
|
+
|
137
|
+
# Compute mean value of self.
|
138
|
+
#
|
139
|
+
# @!method mean(skip_nulls: true, min_count: 1)
|
140
|
+
# @macro scalar_aggregate_options
|
141
|
+
# @return [Numeric]
|
142
|
+
# mean of self.
|
143
|
+
#
|
144
|
+
define_unary_aggregation :mean
|
145
|
+
|
146
|
+
# Compute minimum value of self.
|
147
|
+
#
|
148
|
+
# @!method min(skip_nulls: true, min_count: 1)
|
149
|
+
# @macro scalar_aggregate_options
|
150
|
+
# @return [Numeric]
|
151
|
+
# minimum of self.
|
152
|
+
#
|
153
|
+
define_unary_aggregation :min
|
154
|
+
|
155
|
+
# Compute the min and max value of self.
|
156
|
+
#
|
157
|
+
# @!method min_max(skip_nulls: true, min_count: 1)
|
158
|
+
# @macro scalar_aggregate_options
|
159
|
+
# @return [Array<min, max>]
|
160
|
+
# min and max of self in an Array.
|
161
|
+
#
|
162
|
+
define_unary_aggregation :min_max
|
163
|
+
|
164
|
+
# Compute product value of self.
|
165
|
+
#
|
166
|
+
# @note Self must be a numeric Vector.
|
167
|
+
# @!method product(skip_nulls: true, min_count: 1)
|
168
|
+
# @macro scalar_aggregate_options
|
169
|
+
# @return [Numeric]
|
170
|
+
# product of self.
|
171
|
+
#
|
172
|
+
define_unary_aggregation :product
|
173
|
+
|
174
|
+
# Calculate standard deviation of self.
|
175
|
+
#
|
176
|
+
# @note Self must be a numeric Vector.
|
177
|
+
# @!method stddev(ddof: 0, skip_nulls: true, min_count: 1)
|
178
|
+
# @macro variance_options
|
179
|
+
# @return [Float]
|
180
|
+
# standard deviation of self. Biased (ddof=0) by default.
|
181
|
+
#
|
182
|
+
define_unary_aggregation :stddev
|
183
|
+
|
184
|
+
# Calculate unbiased standard deviation of self.
|
185
|
+
#
|
186
|
+
# @note Self must be a numeric Vector.
|
187
|
+
# @!method sd(ddof: 1, skip_nulls: true, min_count: 1)
|
188
|
+
# @macro variance_options
|
189
|
+
# @return [Float]
|
190
|
+
# standard deviation of self. Unviased (ddof=1)by default.
|
191
|
+
#
|
192
|
+
def sd
|
193
|
+
stddev(ddof: 1)
|
194
|
+
end
|
195
|
+
alias_method :std, :sd
|
196
|
+
|
197
|
+
# Compute sum of self.
|
198
|
+
#
|
199
|
+
# @note Self must be a numeric Vector.
|
200
|
+
# @!method sum(skip_nulls: true, min_count: 1)
|
201
|
+
# @macro scalar_aggregate_options
|
202
|
+
# @return [Numeric]
|
203
|
+
# sum of self.
|
204
|
+
#
|
205
|
+
define_unary_aggregation :sum
|
206
|
+
|
207
|
+
# Calculate variance of self.
|
208
|
+
#
|
209
|
+
# @note Self must be a numeric Vector.
|
210
|
+
# @!method variance(ddof: 0, skip_nulls: true, min_count: 1)
|
211
|
+
# @macro variance_options
|
212
|
+
#
|
213
|
+
# @return [Float]
|
214
|
+
# unviased (ddof=1) standard deviation of self by default.
|
215
|
+
#
|
216
|
+
# @return [Float]
|
217
|
+
# variance of self. Biased (ddof=0) by default.
|
218
|
+
#
|
219
|
+
define_unary_aggregation :variance
|
220
|
+
|
221
|
+
# Calculate unbiased variance of self.
|
222
|
+
#
|
223
|
+
# @note self must be a numeric Vector.
|
224
|
+
# @!method unbiased_variance(ddof: 1, skip_nulls: true, min_count: 1)
|
225
|
+
# @macro variance_options
|
226
|
+
# @return [Float]
|
227
|
+
# variance of self. Unviased (ddof=1) by default.
|
228
|
+
#
|
229
|
+
def unbiased_variance
|
230
|
+
variance(ddof: 1)
|
231
|
+
end
|
232
|
+
alias_method :var, :unbiased_variance
|
233
|
+
|
234
|
+
# @!macro quantile_interpolation
|
235
|
+
# @param interpolation [Symbol]
|
236
|
+
# specifies interpolation method to use,
|
237
|
+
# when the quantile lies between the data i and j.
|
238
|
+
# - Default value is :linear, which returns i + (j - i) * fraction.
|
239
|
+
# - lower: returns i.
|
240
|
+
# - higher: returns j.
|
241
|
+
# - nearest: returns i or j, whichever is closer.
|
242
|
+
# - midpoint: returns (i + j) / 2.
|
243
|
+
|
244
|
+
# Returns a quantile value.
|
245
|
+
# - 0.5 quantile (median) is returned by default.
|
246
|
+
# - Or return quantile for specified probability (prob).
|
247
|
+
# - If quantile lies between two data points, interpolated value is
|
248
|
+
# returned based on selected interpolation method.
|
249
|
+
# - Nils and NaNs are ignored.
|
250
|
+
# - Nil is returned if there are no valid data point.
|
251
|
+
#
|
252
|
+
# @param prob [Float]
|
253
|
+
# probability.
|
254
|
+
# @macro quantile_interpolation
|
255
|
+
# @macro scalar_aggregate_options
|
256
|
+
# @return [Float]
|
257
|
+
# quantile of self.
|
258
|
+
# @example
|
259
|
+
# penguins[:bill_depth_mm].quantile
|
260
|
+
#
|
261
|
+
# # =>
|
262
|
+
# 17.3 # defaultis prob = 0.5
|
263
|
+
#
|
264
|
+
def quantile(prob = 0.5, interpolation: :linear, skip_nulls: true, min_count: 0)
|
265
|
+
unless (0..1).cover? prob
|
266
|
+
raise VectorArgumentError,
|
267
|
+
"Invalid: probability #{prob} must be between 0 and 1"
|
268
|
+
end
|
269
|
+
|
270
|
+
datum = find(:quantile).execute([data],
|
271
|
+
q: prob,
|
272
|
+
interpolation: interpolation,
|
273
|
+
skip_nulls: skip_nulls,
|
274
|
+
min_count: min_count)
|
275
|
+
datum.value.to_a.first
|
276
|
+
end
|
277
|
+
|
278
|
+
# Return quantiles in a DataFrame
|
279
|
+
#
|
280
|
+
# @param probs [Array]
|
281
|
+
# Array of probabilities. Default probabilities are 0.0, 0.25, 0.5 0.75, 1.0 .
|
282
|
+
# @macro quantile_interpolation
|
283
|
+
# @macro scalar_aggregate_options
|
284
|
+
# @return [DataFrame]
|
285
|
+
# quantiles of self.
|
286
|
+
# @example
|
287
|
+
# penguins[:bill_depth_mm].quantiles([0.05, 0.95])
|
288
|
+
#
|
289
|
+
# # =>
|
290
|
+
# #<RedAmber::DataFrame : 2 x 2 Vectors, 0x000000000000fb2c>
|
291
|
+
# probs quantiles
|
292
|
+
# <double> <double>
|
293
|
+
# 0 0.05 13.9
|
294
|
+
# 1 0.95 20.0
|
295
|
+
#
|
296
|
+
def quantiles(probs = [0.0, 0.25, 0.5, 0.75, 1.0],
|
297
|
+
interpolation: :linear, skip_nulls: true, min_count: 0)
|
298
|
+
if probs.empty? || !probs.all? { |q| (0..1).cover?(q) }
|
299
|
+
raise VectorArgumentError, "Invarid probavilities #{probs}"
|
300
|
+
end
|
301
|
+
|
302
|
+
DataFrame.new(
|
303
|
+
probs: probs,
|
304
|
+
quantiles: probs.map do |q|
|
305
|
+
quantile(q,
|
306
|
+
interpolation: interpolation, skip_nulls: skip_nulls,
|
307
|
+
min_count: min_count)
|
308
|
+
end
|
309
|
+
)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
@@ -0,0 +1,387 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Available functions in Arrow are shown by `Arrow::Function.all.map(&:name)`
|
4
|
+
# reference: https://arrow.apache.org/docs/cpp/compute.html
|
5
|
+
|
6
|
+
module RedAmber
|
7
|
+
# Representing a series of data.
|
8
|
+
class Vector
|
9
|
+
class << self
|
10
|
+
# Compute the inverse tangent of y/x.
|
11
|
+
#
|
12
|
+
# [Binary element-wise function] Returns a Vector.
|
13
|
+
# The return value is in the range [-pi, pi].
|
14
|
+
# @param y [Vector, array-like]
|
15
|
+
# numeric array-like.
|
16
|
+
# @param x [Vector, array-like]
|
17
|
+
# numeric array-like.
|
18
|
+
# @return [Vector]
|
19
|
+
# inverse tangent of y/x.
|
20
|
+
#
|
21
|
+
def atan2(y, x) # rubocop:disable Naming/MethodParameterName
|
22
|
+
y = y.data if y.is_a? Vector
|
23
|
+
x = x.data if x.is_a? Vector
|
24
|
+
|
25
|
+
datum = Arrow::Function.find(:atan2).execute([y, x])
|
26
|
+
Vector.create(datum.value)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# @!macro [attach] define_binary_element_wise
|
32
|
+
# [Binary element-wise function] Returns a Vector.
|
33
|
+
#
|
34
|
+
def define_binary_element_wise(function)
|
35
|
+
define_method(function) do |other, **options|
|
36
|
+
datum = exec_func_binary(function, other, options)
|
37
|
+
Vector.create(datum.value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# @!macro [attach] define_binary_element_wise_logical
|
42
|
+
# [Binary element-wise function] Returns a Vector.
|
43
|
+
#
|
44
|
+
def define_binary_element_wise_logical(method, function)
|
45
|
+
define_method(method) do |other, **options|
|
46
|
+
datum = exec_func_binary(function, other, options)
|
47
|
+
Vector.create(datum.value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# @!macro kleene_logic_and
|
53
|
+
# This function behaves as follows with nils:
|
54
|
+
# - true and nil = nil
|
55
|
+
# - nil and true = nil
|
56
|
+
# - false and nil = false
|
57
|
+
# - nil and false = false
|
58
|
+
# - nil and nil = nil
|
59
|
+
# In other words, in this context a nil value really means "unknown",
|
60
|
+
# and an unknown value 'and' false is always false.
|
61
|
+
|
62
|
+
# @!macro kleene_logic_and_not
|
63
|
+
# This function behaves as follows with nils:
|
64
|
+
# - true and not nil = nil
|
65
|
+
# - nil and not false = nil
|
66
|
+
# - false and not nil = false
|
67
|
+
# - nil and not true = false
|
68
|
+
# - nil and not nil = nil
|
69
|
+
# In other words, in this context a nil value really means "unknown",
|
70
|
+
# and an unknown value 'and not' true is always false,
|
71
|
+
# as is false 'and not' an unknown value.
|
72
|
+
|
73
|
+
# @!macro kleene_logic_or
|
74
|
+
# This function behaves as follows with nils:
|
75
|
+
# - true or nil = true
|
76
|
+
# - nil or true = true
|
77
|
+
# - false or nil = nil
|
78
|
+
# - nil or false = nil
|
79
|
+
# - nil or nil = nil
|
80
|
+
# In other words, in this context a nil value really means "unknown",
|
81
|
+
# and an unknown value 'or' true is always true.
|
82
|
+
|
83
|
+
# rubocop:disable Lint/SymbolConversion)
|
84
|
+
|
85
|
+
# Logical 'and' boolean values with Kleene logic.
|
86
|
+
#
|
87
|
+
# @macro kleene_logic_and
|
88
|
+
# For a different nil behavior, see function {#and_org}.
|
89
|
+
# @!method and_kleene(other)
|
90
|
+
# @param other [Vector, array-like]
|
91
|
+
# boolean array-like.
|
92
|
+
# @return [Vector]
|
93
|
+
# and_kleene of self and other.
|
94
|
+
define_binary_element_wise :and_kleene
|
95
|
+
alias_method :'&', :and_kleene
|
96
|
+
|
97
|
+
# Logical 'and not' boolean values.
|
98
|
+
#
|
99
|
+
# When a nil is encountered in either input, a nil is output.
|
100
|
+
# For a different nil behavior, see function {#and_not_kleene}.
|
101
|
+
# @!method and_not(other)
|
102
|
+
# @param other [Vector, array-like]
|
103
|
+
# boolean array-like.
|
104
|
+
# @return [Vector]
|
105
|
+
# and not of self and other.
|
106
|
+
#
|
107
|
+
define_binary_element_wise :and_not
|
108
|
+
|
109
|
+
# Logical 'and not' boolean values with Kleene logic.
|
110
|
+
#
|
111
|
+
# @macro kleene_logic_and_not
|
112
|
+
# For a different nil behavior, see function {#and_not}.
|
113
|
+
# @!method and_not_kleene(other)
|
114
|
+
# @param other [Vector, array-like]
|
115
|
+
# boolean array-like.
|
116
|
+
# @return [Vector]
|
117
|
+
# and not kleene of self and other.
|
118
|
+
#
|
119
|
+
define_binary_element_wise :and_not_kleene
|
120
|
+
|
121
|
+
# Logical 'and' boolean values.
|
122
|
+
#
|
123
|
+
# When a nil is encountered in either input, a nil is output.
|
124
|
+
# For a different nil behavior, see function {#and_kleene}.
|
125
|
+
# @!method and_org(other)
|
126
|
+
# @param other [Vector, array-like]
|
127
|
+
# boolean array-like.
|
128
|
+
# @return [Vector]
|
129
|
+
# evacuated `and` of self and other.
|
130
|
+
#
|
131
|
+
define_binary_element_wise_logical(:and_org, :and)
|
132
|
+
|
133
|
+
# Bit-wise AND of self and other by element-wise.
|
134
|
+
#
|
135
|
+
# Nil values return nil.
|
136
|
+
# @!method bit_wise_and(other)
|
137
|
+
# @param other [Vector, array-like]
|
138
|
+
# integer array-like.
|
139
|
+
# @return [Vector]
|
140
|
+
# bit wise and of self and other.
|
141
|
+
#
|
142
|
+
define_binary_element_wise :bit_wise_and
|
143
|
+
|
144
|
+
# Bit-wise OR of self and other by element-wise.
|
145
|
+
#
|
146
|
+
# Nil values return nil.
|
147
|
+
# @!method bit_wise_or(other)
|
148
|
+
# @param other [Vector, array-like]
|
149
|
+
# integer array-like.
|
150
|
+
# @return [Vector]
|
151
|
+
# bit wise or of self and other.
|
152
|
+
#
|
153
|
+
define_binary_element_wise :bit_wise_or
|
154
|
+
|
155
|
+
# Bit-wise XOR of self and other by element-wise.
|
156
|
+
#
|
157
|
+
# Nil values return nil.
|
158
|
+
# @!method bit_wise_xor(other)
|
159
|
+
# @param other [Vector, array-like]
|
160
|
+
# integer array-like.
|
161
|
+
# @return [Vector]
|
162
|
+
# bit wise xor of self and other.
|
163
|
+
#
|
164
|
+
define_binary_element_wise :bit_wise_xor
|
165
|
+
|
166
|
+
# Compute base `b` logarithm of self.
|
167
|
+
#
|
168
|
+
# Non positive values return -inf or NaN. Nil values return nil.
|
169
|
+
# @!method logb(b)
|
170
|
+
# @param b [Integer]
|
171
|
+
# base.
|
172
|
+
# @return [Vector]
|
173
|
+
# logb of self and other.
|
174
|
+
#
|
175
|
+
define_binary_element_wise :logb
|
176
|
+
|
177
|
+
# Logical 'or' boolean values with Kleene logic.
|
178
|
+
#
|
179
|
+
# @macro kleene_logic_or
|
180
|
+
# For a different nil behavior, see function {#or_org}.
|
181
|
+
# @!method or_kleene(other)
|
182
|
+
# @param other [Vector, array-like]
|
183
|
+
# boolean array-like.
|
184
|
+
# @return [Vector]
|
185
|
+
# or_kleene of self and other.
|
186
|
+
#
|
187
|
+
define_binary_element_wise :or_kleene
|
188
|
+
alias_method :'|', :or_kleene
|
189
|
+
|
190
|
+
# Logical 'or' boolean values.
|
191
|
+
#
|
192
|
+
# When a nil is encountered in either input, a nil is output.
|
193
|
+
# For a different nil behavior, see function {#or_kleene}.
|
194
|
+
# @!method or_org(other)
|
195
|
+
# @param other [Vector, array-like]
|
196
|
+
# boolean array-like.
|
197
|
+
# @return [Vector]
|
198
|
+
# evacuated `or` of self and other.
|
199
|
+
#
|
200
|
+
define_binary_element_wise_logical(:or_org, :or)
|
201
|
+
|
202
|
+
# Add the arguments element-wise.
|
203
|
+
#
|
204
|
+
# Results will wrap around on integer overflow.
|
205
|
+
# @!method add(other)
|
206
|
+
# @param other [Vector, Numeric]
|
207
|
+
# other numeric Vector or numeric scalar.
|
208
|
+
# @return [Vector]
|
209
|
+
# adddition of self and other.
|
210
|
+
#
|
211
|
+
define_binary_element_wise :add
|
212
|
+
alias_method :'+', :add
|
213
|
+
|
214
|
+
# Divide the arguments element-wise.
|
215
|
+
#
|
216
|
+
# Integer division by zero returns an error. However, integer overflow
|
217
|
+
# wraps around, and floating-point division by zero returns an infinite.
|
218
|
+
# @!method divide(divisor)
|
219
|
+
# @param divisor [Vector, Numeric]
|
220
|
+
# numeric vector or numeric scalar as divisor.
|
221
|
+
# @return [Vector]
|
222
|
+
# division of self and other.
|
223
|
+
#
|
224
|
+
define_binary_element_wise :divide
|
225
|
+
alias_method :'/', :divide
|
226
|
+
|
227
|
+
# Multiply the arguments element-wise.
|
228
|
+
#
|
229
|
+
# Results will wrap around on integer overflow.
|
230
|
+
# @!method multiply(other)
|
231
|
+
# @param other [Vector, Numeric]
|
232
|
+
# other numeric vector or numeric scalar.
|
233
|
+
# @return [Vector]
|
234
|
+
# multiplication of self and other.
|
235
|
+
#
|
236
|
+
define_binary_element_wise :multiply
|
237
|
+
alias_method :'*', :multiply
|
238
|
+
|
239
|
+
# Raise arguments to power element-wise.
|
240
|
+
#
|
241
|
+
# Integer to negative integer power returns an error.
|
242
|
+
# However, integer overflow wraps around.
|
243
|
+
# If either self or exponent is nil the result will be nil.
|
244
|
+
# @!method power(exponent)
|
245
|
+
# @param exponent [Vector, Numeric]
|
246
|
+
# numeric vector or numeric scalar as exponent.
|
247
|
+
# @return [Vector]
|
248
|
+
# power operation of self and other.
|
249
|
+
#
|
250
|
+
define_binary_element_wise :power
|
251
|
+
alias_method :'**', :power
|
252
|
+
|
253
|
+
# Subtract the arguments element-wise.
|
254
|
+
#
|
255
|
+
# Results will wrap around on integer overflow.
|
256
|
+
# @!method subtract(other)
|
257
|
+
# @param other [Vector, Numeric]
|
258
|
+
# other numeric vector or numeric scalar.
|
259
|
+
# @return [Vector]
|
260
|
+
# subtraction of self and other.
|
261
|
+
#
|
262
|
+
define_binary_element_wise :subtract
|
263
|
+
alias_method :'-', :subtract
|
264
|
+
|
265
|
+
# Left shift of self by other.
|
266
|
+
#
|
267
|
+
# The shift operates as if on the two's complement representation of the number.
|
268
|
+
# In other words, this is equivalent to multiplying self by 2 to the power 'amount',
|
269
|
+
# even if overflow occurs.
|
270
|
+
# self is returned if 'amount' (the amount to shift by) is negative or
|
271
|
+
# greater than or equal to the precision of self.
|
272
|
+
# @!method shift_left(amount)
|
273
|
+
# @param amount [integer]
|
274
|
+
# the amount to shift by.
|
275
|
+
# @return [Vector]
|
276
|
+
# shift_left of self by amount.
|
277
|
+
#
|
278
|
+
define_binary_element_wise :shift_left
|
279
|
+
alias_method :'<<', :shift_left
|
280
|
+
|
281
|
+
# Right shift of self by other.
|
282
|
+
#
|
283
|
+
# This is equivalent to dividing `x` by 2 to the power `y`.
|
284
|
+
# Self is returned if 'amount' (the amount to shift by) is: negative or
|
285
|
+
# greater than or equal to the precision of self.
|
286
|
+
# @!method shift_right(amount)
|
287
|
+
# @param amount [integer]
|
288
|
+
# the amount to shift by.
|
289
|
+
# @return [Vector]
|
290
|
+
# shift_right of self by amount.
|
291
|
+
#
|
292
|
+
define_binary_element_wise :shift_right
|
293
|
+
alias_method :'>>', :shift_right
|
294
|
+
|
295
|
+
# Logical 'xor' boolean values
|
296
|
+
#
|
297
|
+
# When a nil is encountered in either input, a nil is output.
|
298
|
+
# @!method xor(other)
|
299
|
+
# @param other [Vector]
|
300
|
+
# other boolean vector or boolean scalar.
|
301
|
+
# @return [Vector]
|
302
|
+
# eq of self and other by a boolean Vector.
|
303
|
+
#
|
304
|
+
define_binary_element_wise :xor
|
305
|
+
alias_method :'^', :xor
|
306
|
+
|
307
|
+
# Compare values for equality (self == other)
|
308
|
+
#
|
309
|
+
# A nil on either side emits a nil comparison result.
|
310
|
+
# @!method equal(other)
|
311
|
+
# @param other [Vector]
|
312
|
+
# other vector or scalar.
|
313
|
+
# @return [Vector]
|
314
|
+
# eq of self and other by a boolean Vector.
|
315
|
+
#
|
316
|
+
define_binary_element_wise :equal
|
317
|
+
alias_method :'==', :equal
|
318
|
+
alias_method :eq, :equal
|
319
|
+
|
320
|
+
# Compare values for ordered inequality (self > other).
|
321
|
+
#
|
322
|
+
# A nil on either side emits a nil comparison result.
|
323
|
+
# @!method greater(other)
|
324
|
+
# @param other [Vector]
|
325
|
+
# other vector or scalar.
|
326
|
+
# @return [Vector]
|
327
|
+
# gt of self and other by a boolean Vector.
|
328
|
+
#
|
329
|
+
define_binary_element_wise :greater
|
330
|
+
alias_method :'>', :greater
|
331
|
+
alias_method :gt, :greater
|
332
|
+
|
333
|
+
# Compare values for ordered inequality (self >= other).
|
334
|
+
#
|
335
|
+
# A nil on either side emits a nil comparison result.
|
336
|
+
# @!method greater_equal(other)
|
337
|
+
# @param other [Vector]
|
338
|
+
# other vector or scalar.
|
339
|
+
# @return [Vector]
|
340
|
+
# ge of self and other by a boolean Vector.
|
341
|
+
#
|
342
|
+
define_binary_element_wise :greater_equal
|
343
|
+
alias_method :'>=', :greater_equal
|
344
|
+
alias_method :ge, :greater_equal
|
345
|
+
|
346
|
+
# Compare values for ordered inequality (self < other).
|
347
|
+
#
|
348
|
+
# A nil on either side emits a nil comparison result.
|
349
|
+
# @!method less(other)
|
350
|
+
# @param other [Vector]
|
351
|
+
# other vector or scalar.
|
352
|
+
# @return [Vector]
|
353
|
+
# lt of self and other by a boolean Vector.
|
354
|
+
#
|
355
|
+
define_binary_element_wise :less
|
356
|
+
alias_method :'<', :less
|
357
|
+
alias_method :lt, :less
|
358
|
+
|
359
|
+
# Compare values for ordered inequality (self <= other).
|
360
|
+
#
|
361
|
+
# A nil on either side emits a nil comparison result.
|
362
|
+
# @!method less_equal(other)
|
363
|
+
# @param other [Vector]
|
364
|
+
# other vector or scalar.
|
365
|
+
# @return [Vector]
|
366
|
+
# le of self and other by a boolean Vector.
|
367
|
+
#
|
368
|
+
define_binary_element_wise :less_equal
|
369
|
+
alias_method :'<=', :less_equal
|
370
|
+
alias_method :le, :less_equal
|
371
|
+
|
372
|
+
# Compare values for inequality (self != other).
|
373
|
+
#
|
374
|
+
# A nil on either side emits a nil comparison result.
|
375
|
+
# @!method not_equal(other)
|
376
|
+
# @param other [Vector]
|
377
|
+
# other vector or scalar.
|
378
|
+
# @return [Vector]
|
379
|
+
# ne of self and other by a boolean Vector.
|
380
|
+
#
|
381
|
+
define_binary_element_wise :not_equal
|
382
|
+
alias_method :'!=', :not_equal
|
383
|
+
alias_method :ne, :not_equal
|
384
|
+
|
385
|
+
# rubocop:enable Lint/SymbolConversion)
|
386
|
+
end
|
387
|
+
end
|