Class: RedAmber::Vector
- Inherits:
-
Object
- Object
- RedAmber::Vector
- Includes:
- Enumerable, ArrowFunction, Helper, VectorSelectable, VectorStringFunction, VectorUpdatable
- Defined in:
- lib/red_amber/vector.rb,
lib/red_amber/vector_aggregation.rb,
lib/red_amber/vector_unary_element_wise.rb,
lib/red_amber/vector_binary_element_wise.rb
Overview
Representing a series of data.
Instance Attribute Summary collapse
-
#data ⇒ Arrow::Array
(also: #to_arrow_array)
readonly
Entity of Vector.
-
#key ⇒ Symbol
Associated key name when self is in a DataFrame.
Class Method Summary collapse
-
.[] ⇒ Vector
Create a Vector (calling ‘.new`).
-
.atan2(y, x) ⇒ Vector
Compute the inverse tangent of y/x.
-
.create(arrow_array) ⇒ Vector
Quicker constructor of Vector.
Instance Method Summary collapse
-
#abs ⇒ Vector
Calculate the absolute value of self element-wise.
-
#abs_checked ⇒ Vector
Calculate the absolute value of self element-wise.
-
#acos ⇒ Vector
Compute the inverse cosine of self element-wise.
-
#acos_checked ⇒ Vector
Compute the inverse cosine of self element-wise.
-
#add(other) ⇒ Vector
(also: #+)
Add the arguments element-wise.
-
#add_checked ⇒ Vector
Add the arguments element-wise.
-
#all(skip_nulls: true, min_count: 1) ⇒ true, false
(also: #all?)
Test whether all elements in self are evaluated to true.
-
#and_kleene(other) ⇒ Vector
(also: #&)
Logical ‘and’ boolean values with Kleene logic.
-
#and_not(other) ⇒ Vector
Logical ‘and not’ boolean values.
-
#and_not_kleene(other) ⇒ Vector
Logical ‘and not’ boolean values with Kleene logic.
-
#and_org(other) ⇒ Vector
Logical ‘and’ boolean values.
-
#any(skip_nulls: true, min_count: 1) ⇒ true, false
(also: #any?)
Test whether any elements in self are evaluated to true.
-
#approximate_median(skip_nulls: true, min_count: 1) ⇒ Float
(also: #median)
Approximate median of a numeric Vector with T-Digest algorithm.
-
#array_sort_indices(order: :ascending) ⇒ Vector
(also: #sort_indexes, #sort_indices, #sort_index)
Return the indices that would sort self.
-
#asin ⇒ Vector
Compute the inverse sine of self element-wise.
-
#asin_checked ⇒ Vector
Compute the inverse sine of self element-wise.
-
#atan ⇒ Vector
Compute the inverse tangent of self element-wise.
-
#bit_wise_and(other) ⇒ Vector
Bit-wise AND of self and other by element-wise.
-
#bit_wise_not ⇒ Vector
Bit-wise negate by element-wise.
-
#bit_wise_or(other) ⇒ Vector
Bit-wise OR of self and other by element-wise.
-
#bit_wise_xor(other) ⇒ Vector
Bit-wise XOR of self and other by element-wise.
-
#boolean? ⇒ true, false
Test if self is a boolean Vector.
-
#ceil ⇒ Vector
Round up to the nearest integer.
-
#chunked? ⇒ true, false
private
Tests wheather self is chunked or not.
-
#coerce(other) ⇒ Object
Enable to compute with coercion mechanism.
-
#cos ⇒ Vector
Compute the cosine of self element-wise.
-
#cos_checked ⇒ Vector
Compute the cosine of self element-wise.
-
#count(mode: :non_null) ⇒ Integer
Count the number of nil / non-nil values.
-
#count_distinct(mode: :only_valid) ⇒ Integer
(also: #count_uniq)
Count the number of unique values.
-
#cumsum ⇒ Vector
Compute cumulative sum over the numeric Vector.
-
#cumulative_sum_checked ⇒ Vector
Compute cumulative sum over the numeric Vector.
-
#dictionary? ⇒ true, false
Test if self is a dictionary Vector.
-
#divide(divisor) ⇒ Vector
(also: #/)
Divide the arguments element-wise.
-
#divide_checked ⇒ Vector
Divide the arguments element-wise.
-
#each ⇒ Object
Iterates over Vector elements or returns a Enumerator.
-
#empty? ⇒ true, false
Test wheather self is empty.
-
#equal(other) ⇒ Vector
(also: #==, #eq)
Compare values for equality (self == other).
-
#fdiv(divisor) ⇒ Vector
Returns element-wise quotient by double Vector.
-
#fdiv_checked(divisor) ⇒ Object
Returns element-wise quotient by double Vector.
-
#fill_null_backward ⇒ Vector
(also: #fill_nil_backward)
Carry non-nil values backward to fill nil slots.
-
#fill_null_forward ⇒ Vector
(also: #fill_nil_forward)
Carry non-nil values forward to fill nil slots.
-
#float? ⇒ true, false
Test if self is a float Vector.
-
#floor ⇒ Vector
Round down to the nearest integer.
-
#greater(other) ⇒ Vector
(also: #>, #gt)
Compare values for ordered inequality (self > other).
-
#greater_equal(other) ⇒ Vector
(also: #>=, #ge)
Compare values for ordered inequality (self >= other).
-
#has_nil? ⇒ true, false
Return true if self has any nil.
-
#indices ⇒ Array
(also: #indexes, #indeces)
Indeces from 0 to size-1 by Array.
-
#initialize(*array) ⇒ Vector
constructor
Create a Vector.
-
#inspect(limit: 80) ⇒ String
String representation of self.
-
#integer? ⇒ true, false
Test if self is a integer Vector.
-
#invert ⇒ Vector
(also: #!, #not)
Invert boolean values.
-
#is_finite ⇒ Vector
Return true if value is finite.
-
#is_inf ⇒ Vector
Return true if value is infinity.
-
#is_na ⇒ Vector
return true if value is nil or NaN.
-
#is_nan ⇒ Vector
Return true if NaN.
-
#is_null ⇒ Vector
(also: #is_nil)
Return true if nil.
-
#is_valid ⇒ Vector
Return true if non-nil.
-
#less(other) ⇒ Vector
(also: #<, #lt)
Compare values for ordered inequality (self < other).
-
#less_equal(other) ⇒ Vector
(also: #<=, #le)
Compare values for ordered inequality (self <= other).
-
#list? ⇒ true, false
Test if self is a list Vector.
-
#ln ⇒ Vector
Compute natural logarithm.
-
#ln_checked ⇒ Vector
Compute natural logarithm.
-
#log10 ⇒ Vector
Compute base 10 logarithm.
-
#log10_checked ⇒ Vector
Compute base 10 logarithm.
-
#log1p ⇒ Vector
Compute natural log of (1+x).
-
#log1p_checked ⇒ Vector
Compute natural log of (1+x).
-
#log2 ⇒ Vector
Compute base 2 logarithm.
-
#log2_checked ⇒ Vector
Compute base 2 logarithm.
-
#logb(b) ⇒ Vector
Compute base ‘b` logarithm of self.
-
#logb_checked ⇒ Vector
Compute base ‘b` logarithm of self.
-
#map(&block) ⇒ Object
(also: #collect)
Returns a Vector from collected objects from the block.
-
#max(skip_nulls: true, min_count: 1) ⇒ Numeric
Compute maximum value of self.
-
#mean(skip_nulls: true, min_count: 1) ⇒ Numeric
Compute mean value of self.
-
#min(skip_nulls: true, min_count: 1) ⇒ Numeric
Compute minimum value of self.
-
#min_max(skip_nulls: true, min_count: 1) ⇒ Array<min, max>
Compute the min and max value of self.
-
#mode ⇒ Hash{'mode'=>mode, 'count'=>count}
private
Compute the 1 most common values and their respective occurence counts.
-
#modulo(divisor) ⇒ Vector
(also: #%)
Returns element-wise modulo.
-
#modulo_checked(divisor) ⇒ Vector
Returns element-wise modulo.
-
#multiply(other) ⇒ Vector
(also: #mul, #*)
Multiply the arguments element-wise.
-
#multiply_checked ⇒ Vector
Multiply the arguments element-wise.
-
#n_chunks ⇒ Integer
private
Returns the number of chunks.
-
#n_nans ⇒ Integer
Count NaNs in self if self is a numeric Vector.
-
#n_nulls ⇒ Integer
(also: #n_nils)
Count nils in self.
-
#negate ⇒ Vector
(also: #-@)
Negate the argument element-wise.
-
#negate_checked ⇒ Vector
Negate the argument element-wise.
-
#not_equal(other) ⇒ Vector
(also: #!=, #ne)
Compare values for inequality (self != other).
-
#numeric? ⇒ true, false
Test if self is a numeric Vector.
-
#one ⇒ Object?
Get a non-nil element in self.
-
#or_kleene(other) ⇒ Vector
(also: #|)
Logical ‘or’ boolean values with Kleene logic.
-
#or_org(other) ⇒ Vector
Logical ‘or’ boolean values.
-
#power(exponent) ⇒ Vector
(also: #pow, #**)
Raise arguments to power element-wise.
-
#power_checked ⇒ Vector
Raise arguments to power element-wise.
-
#product(skip_nulls: true, min_count: 1) ⇒ Numeric
Compute product value of self.
-
#propagate(function = nil, &block) ⇒ Object
(also: #expand)
Spread the return value of an aggregate function as if it is a element-wise function.
-
#quantile(prob = 0.5, interpolation: :linear, skip_nulls: true, min_count: 0) ⇒ Float
Returns a quantile value.
-
#quantiles(probs = [0.0, 0.25, 0.5, 0.75, 1.0], interpolation: :linear, skip_nulls: true, min_count: 0) ⇒ DataFrame
Return quantiles in a DataFrame.
-
#remainder(divisor) ⇒ Vector
Returns element-wise remainder.
-
#remainder_checked(divisor) ⇒ Vector
Returns element-wise modulo.
-
#resolve(other) ⇒ Vector
Return other as a Vector which is same data type as self.
-
#round(n_digits: 0, round_mode: :half_to_even) ⇒ Vector
Round to a given precision.
-
#round_to_multiple(multiple: 1.0, round_mode: :half_to_even) ⇒ Vector
Round to a given multiple.
-
#sd(ddof: 1, skip_nulls: true, min_count: 1) ⇒ Float
(also: #std)
Calculate unbiased standard deviation of self.
-
#shift_left(amount) ⇒ Vector
(also: #<<)
Left shift of self by other.
-
#shift_left_checked ⇒ Vector
Left shift of self by other.
-
#shift_right(amount) ⇒ Vector
(also: #>>)
Right shift of self by other.
-
#shift_right_checked ⇒ Vector
Right shift of self by other.
-
#sign ⇒ Vector
Get the signedness of the arguments element-wise.
-
#sin ⇒ Vector
Compute the sine of self element-wise.
-
#sin_checked ⇒ Vector
Compute the sine of self element-wise.
-
#size ⇒ Integer
(also: #length, #n_rows, #nrow)
Vector size.
-
#sqrt ⇒ Vector
Compute square root of self.
-
#sqrt_checked ⇒ Vector
Compute square root of self.
-
#stddev(ddof: 0, skip_nulls: true, min_count: 1) ⇒ Float
Calculate standard deviation of self.
-
#string? ⇒ true, false
Test if self is a string Vector.
-
#subtract(other) ⇒ Vector
(also: #sub, #-)
Subtract the arguments element-wise.
-
#subtract_checked ⇒ Vector
Subtract the arguments element-wise.
-
#sum(skip_nulls: true, min_count: 1) ⇒ Numeric
Compute sum of self.
-
#tally ⇒ Hash
Returns a hash containing the counts of equal elements.
-
#tan ⇒ Vector
Compute the tangent of self element-wise.
-
#tan_checked ⇒ Vector
Compute the tangent of self element-wise.
-
#temporal? ⇒ true, false
Test if self is a temporal Vector.
-
#to_ary ⇒ Array
(also: #to_a, #values, #entries)
Convert to an Array.
-
#to_s ⇒ String
String representation of self like an Array.
-
#trunc ⇒ Vector
Compute the integral part.
-
#type ⇒ Symbol
Type nickname of self.
-
#type_class ⇒ type_Class
Type Class of self.
-
#unbiased_variance(ddof: 1, skip_nulls: true, min_count: 1) ⇒ Float
(also: #var)
Calculate unbiased variance of self.
-
#unique ⇒ Vector
(also: #uniq)
Compute unique elements.
-
#value_counts ⇒ Object
private
Arrow imprementation of #tally.
-
#variance(ddof: 0, skip_nulls: true, min_count: 1) ⇒ Float
Calculate variance of self.
-
#xor(other) ⇒ Vector
(also: #^)
Logical ‘xor’ boolean values.
Methods included from VectorStringFunction
#count_substring, #end_with, #find_substring, #match_like, #match_substring, #start_with
Methods included from VectorSelectable
#[], #drop_nil, #filter, #first, #index, #is_in, #last, #rank, #sample, #sort, #take
Methods included from VectorUpdatable
#cast, #concatenate, #fill_nil, #if_else, #list_flatten, #list_separate, #list_sizes, #merge, #primitive_invert, #replace, #shift, #split, #split_to_columns, #split_to_rows
Methods included from ArrowFunction
Constructor Details
#initialize(*array) ⇒ Vector
default is headless Vector and ‘@key == nil’
Create a Vector.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/red_amber/vector.rb', line 71 def initialize(*array) @data = case array in [Vector => v] v.data in [Range => r] Arrow::Array.new(Array(r)) in [Arrow::Array | Arrow::ChunkedArray] array[0] in [arrow_array_like] if arrow_array_like.respond_to?(:to_arrow_array) arrow_array_like.to_arrow_array else Arrow::Array.new(array.flatten) end end |
Instance Attribute Details
#data ⇒ Arrow::Array (readonly) Also known as: to_arrow_array
Entity of Vector.
21 22 23 |
# File 'lib/red_amber/vector.rb', line 21 def data @data end |
#key ⇒ Symbol
Associated key name when self is in a DataFrame.
Default Vector is ‘head-less’ (key-less).
29 30 31 |
# File 'lib/red_amber/vector.rb', line 29 def key @key end |
Class Method Details
.[] ⇒ Vector
Create a Vector (calling ‘.new`).
44 45 46 |
# File 'lib/red_amber/vector.rb', line 44 def [](...) new(...) end |
.atan2(y, x) ⇒ Vector
Compute the inverse tangent of y/x.
- Binary element-wise function
-
Returns a Vector.
The return value is in the range [-pi, pi].
21 22 23 24 25 26 27 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 21 def atan2(y, x) # rubocop:disable Naming/MethodParameterName y = y.data if y.is_a? Vector x = x.data if x.is_a? Vector datum = Arrow::Function.find(:atan2).execute([y, x]) Vector.create(datum.value) end |
.create(arrow_array) ⇒ Vector
This method doesn’t check argment type.
Quicker constructor of Vector.
56 57 58 59 60 |
# File 'lib/red_amber/vector.rb', line 56 def create(arrow_array) instance = allocate instance.instance_variable_set(:@data, arrow_array) instance end |
Instance Method Details
#abs ⇒ Vector
Calculate the absolute value of self element-wise.
Results will wrap around on integer overflow.
- Unary element-wise function
-
Returns a Vector.
57 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 57 define_unary_element_wise :abs |
#abs_checked ⇒ Vector
Calculate the absolute value of self element-wise.
This function is a overflow-checking variant of #abs.
- Unary element-wise function
-
Returns a Vector.
64 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 64 define_unary_element_wise :abs_checked |
#acos ⇒ Vector
Compute the inverse cosine of self element-wise.
NaN is returned for invalid input values.
- Unary element-wise function
-
Returns a Vector.
72 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 72 define_unary_element_wise :acos |
#acos_checked ⇒ Vector
Compute the inverse cosine of self element-wise.
This function is a overflow-checking variant of #acos.
- Unary element-wise function
-
Returns a Vector.
79 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 79 define_unary_element_wise :acos_checked |
#add(other) ⇒ Vector Also known as: +
Add the arguments element-wise.
Results will wrap around on integer overflow.
- Binary element-wise function
-
Returns a Vector.
218 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 218 define_binary_element_wise :add |
#add_checked ⇒ Vector
Add the arguments element-wise.
This function is a overflow-checking variant of #add.
- Binary element-wise function
-
Returns a Vector.
226 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 226 define_binary_element_wise :add_checked |
#all(skip_nulls: true, min_count: 1) ⇒ true, false Also known as: all?
Test whether all elements in self are evaluated to true.
- Unary aggregation function
-
Returns a scalar.
61 |
# File 'lib/red_amber/vector_aggregation.rb', line 61 define_unary_aggregation :all |
#and_kleene(other) ⇒ Vector Also known as: &
Logical ‘and’ boolean values with Kleene logic.
This function behaves as follows with nils:
-
true and nil = nil
-
nil and true = nil
-
false and nil = false
-
nil and false = false
-
nil and nil = nil
In other words, in this context a nil value really means “unknown”, and an unknown value ‘and’ false is always false. For a different nil behavior, see function #and_org.
- Binary element-wise function
-
Returns a Vector.
94 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 94 define_binary_element_wise :and_kleene |
#and_not(other) ⇒ Vector
Logical ‘and not’ boolean values.
When a nil is encountered in either input, a nil is output. For a different nil behavior, see function #and_not_kleene.
- Binary element-wise function
-
Returns a Vector.
107 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 107 define_binary_element_wise :and_not |
#and_not_kleene(other) ⇒ Vector
Logical ‘and not’ boolean values with Kleene logic.
This function behaves as follows with nils:
-
true and not nil = nil
-
nil and not false = nil
-
false and not nil = false
-
nil and not true = false
-
nil and not nil = nil
In other words, in this context a nil value really means “unknown”, and an unknown value ‘and not’ true is always false, as is false ‘and not’ an unknown value. For a different nil behavior, see function #and_not.
- Binary element-wise function
-
Returns a Vector.
119 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 119 define_binary_element_wise :and_not_kleene |
#and_org(other) ⇒ Vector
Logical ‘and’ boolean values.
When a nil is encountered in either input, a nil is output. For a different nil behavior, see function #and_kleene.
- Binary element-wise function
-
Returns a Vector.
131 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 131 define_binary_element_wise_logical(:and_org, :and) |
#any(skip_nulls: true, min_count: 1) ⇒ true, false Also known as: any?
Test whether any elements in self are evaluated to true.
- Unary aggregation function
-
Returns a scalar.
73 |
# File 'lib/red_amber/vector_aggregation.rb', line 73 define_unary_aggregation :any |
#approximate_median(skip_nulls: true, min_count: 1) ⇒ Float Also known as: median
Approximate median of a numeric Vector with T-Digest algorithm.
- Unary aggregation function
-
Returns a scalar.
84 |
# File 'lib/red_amber/vector_aggregation.rb', line 84 define_unary_aggregation :approximate_median |
#array_sort_indices(order: :ascending) ⇒ Vector Also known as: sort_indexes, sort_indices, sort_index
Return the indices that would sort self.
Computes indices Vector that define a stable sort of self. By default, nils are considered greater than any other value and are therefore sorted at the end of the Vector. For floating-point types, NaNs are considered greater than any other non-nil value, but smaller than nil.
- Unary element-wise function
-
Returns a Vector.
108 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 108 define_unary_element_wise :array_sort_indices |
#asin ⇒ Vector
Compute the inverse sine of self element-wise.
NaN is returned for invalid input values.
- Unary element-wise function
-
Returns a Vector.
87 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 87 define_unary_element_wise :asin |
#asin_checked ⇒ Vector
Compute the inverse sine of self element-wise.
This function is a overflow-checking variant of #asin.
- Unary element-wise function
-
Returns a Vector.
94 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 94 define_unary_element_wise :asin_checked |
#atan ⇒ Vector
Compute the inverse tangent of self element-wise.
the return value is in the range [-pi/2, pi/2]. For a full return range [-pi, pi], see atan2 .
- Unary element-wise function
-
Returns a Vector.
120 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 120 define_unary_element_wise :atan |
#bit_wise_and(other) ⇒ Vector
Bit-wise AND of self and other by element-wise.
Nil values return nil.
- Binary element-wise function
-
Returns a Vector.
142 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 142 define_binary_element_wise :bit_wise_and |
#bit_wise_not ⇒ Vector
Bit-wise negate by element-wise.
nil values reeturn nil.
- Unary element-wise function
-
Returns a Vector.
128 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 128 define_unary_element_wise :bit_wise_not |
#bit_wise_or(other) ⇒ Vector
Bit-wise OR of self and other by element-wise.
Nil values return nil.
- Binary element-wise function
-
Returns a Vector.
153 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 153 define_binary_element_wise :bit_wise_or |
#bit_wise_xor(other) ⇒ Vector
Bit-wise XOR of self and other by element-wise.
Nil values return nil.
- Binary element-wise function
-
Returns a Vector.
164 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 164 define_binary_element_wise :bit_wise_xor |
#boolean? ⇒ true, false
Test if self is a boolean Vector.
257 258 259 |
# File 'lib/red_amber/vector.rb', line 257 def boolean? @data.boolean? end |
#ceil ⇒ Vector
Round up to the nearest integer.
Compute the smallest integer value not less in magnitude than each element.
- Unary element-wise function
-
Returns a Vector.
143 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 143 define_unary_element_wise :ceil |
#chunked? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Tests wheather self is chunked or not.
383 384 385 |
# File 'lib/red_amber/vector.rb', line 383 def chunked? @data.is_a? Arrow::ChunkedArray end |
#coerce(other) ⇒ Object
Enable to compute with coercion mechanism.
487 488 489 |
# File 'lib/red_amber/vector.rb', line 487 def coerce(other) [Vector.new(Array(other) * size), self] end |
#cos ⇒ Vector
Compute the cosine of self element-wise.
NaN is returned for invalid input values.
- Unary element-wise function
-
Returns a Vector.
151 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 151 define_unary_element_wise :cos |
#cos_checked ⇒ Vector
Compute the cosine of self element-wise.
This function is a overflow-checking variant of #cos.
- Unary element-wise function
-
Returns a Vector.
158 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 158 define_unary_element_wise :cos_checked |
#count(mode: :non_null) ⇒ Integer
Count the number of nil / non-nil values.
- Unary aggregation function
-
Returns a scalar.
101 |
# File 'lib/red_amber/vector_aggregation.rb', line 101 define_unary_aggregation :count |
#count_distinct(mode: :only_valid) ⇒ Integer Also known as: count_uniq
Count the number of unique values.
- Unary aggregation function
-
Returns a scalar.
125 |
# File 'lib/red_amber/vector_aggregation.rb', line 125 define_unary_aggregation :count_distinct |
#cumsum ⇒ Vector
Self must be numeric.
Try to cast to Int64 if integer overflow occured.
Compute cumulative sum over the numeric Vector.
177 178 179 180 181 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 177 def cumsum cumulative_sum_checked rescue Arrow::Error::Invalid Vector.create(Arrow::Int64Array.new(data)).cumulative_sum_checked end |
#cumulative_sum_checked ⇒ Vector
Self must be numeric.
Return error for integer overflow.
Compute cumulative sum over the numeric Vector.
This function is a overflow-checking variant of #cumsum.
- Unary element-wise function
-
Returns a Vector.
168 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 168 define_unary_element_wise :cumulative_sum_checked |
#dictionary? ⇒ true, false
Test if self is a dictionary Vector.
302 303 304 |
# File 'lib/red_amber/vector.rb', line 302 def dictionary? @data.dictionary? end |
#divide(divisor) ⇒ Vector Also known as: /
Divide the arguments element-wise.
Integer division by zero returns an error. However, integer overflow wraps around, and floating-point division by zero returns an infinite.
- Binary element-wise function
-
Returns a Vector.
238 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 238 define_binary_element_wise :divide |
#divide_checked ⇒ Vector
Divide the arguments element-wise.
This function is a overflow-checking variant of #divide.
- Binary element-wise function
-
Returns a Vector.
246 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 246 define_binary_element_wise :divide_checked |
#each ⇒ Enumerator #each {|element| ... } ⇒ self
Iterates over Vector elements or returns a Enumerator.
342 343 344 345 346 347 348 349 |
# File 'lib/red_amber/vector.rb', line 342 def each return enum_for(:each) unless block_given? size.times do |i| yield data[i] end self end |
#empty? ⇒ true, false
Test wheather self is empty.
230 231 232 |
# File 'lib/red_amber/vector.rb', line 230 def empty? size.zero? end |
#equal(other) ⇒ Vector Also known as: ==, eq
Compare values for equality (self == other)
A nil on either side emits a nil comparison result.
- Binary element-wise function
-
Returns a Vector.
464 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 464 define_binary_element_wise :equal |
#fdiv(divisor) ⇒ Vector
Returns element-wise quotient by double Vector.
330 331 332 333 334 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 330 def fdiv(divisor) divisor = divisor.data if divisor.is_a?(Vector) datum = find(:divide).execute([Arrow::DoubleArray.new(data), divisor]) Vector.create(datum.value) end |
#fdiv_checked(divisor) ⇒ Object
Returns element-wise quotient by double Vector.
This function is a overflow-checking variant of #quotient.
341 342 343 344 345 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 341 def fdiv_checked(divisor) divisor = divisor.data if divisor.is_a?(Vector) datum = find(:divide_checked).execute([Arrow::DoubleArray.new(data), divisor]) Vector.create(datum.value) end |
#fill_null_backward ⇒ Vector Also known as: fill_nil_backward
Use ‘fill_nil(value)` to replace nil by a value.
Carry non-nil values backward to fill nil slots.
Propagate next valid value backward to previous nil values. Or nothing if all next values are nil.
- Unary element-wise function
-
Returns a Vector.
199 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 199 define_unary_element_wise :fill_null_backward |
#fill_null_forward ⇒ Vector Also known as: fill_nil_forward
Use ‘fill_nil(value)` to replace nil by a value.
Carry non-nil values forward to fill nil slots.
Propagate last valid value backward to next nil values. Or nothing if all previous values are nil.
- Unary element-wise function
-
Returns a Vector.
218 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 218 define_unary_element_wise :fill_null_forward |
#float? ⇒ true, false
Test if self is a float Vector.
275 276 277 |
# File 'lib/red_amber/vector.rb', line 275 def float? @data.float? end |
#floor ⇒ Vector
Round down to the nearest integer.
Compute the largest integer value not greater in magnitude than each element.
- Unary element-wise function
-
Returns a Vector.
234 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 234 define_unary_element_wise :floor |
#greater(other) ⇒ Vector Also known as: >, gt
Compare values for ordered inequality (self > other).
A nil on either side emits a nil comparison result.
- Binary element-wise function
-
Returns a Vector.
477 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 477 define_binary_element_wise :greater |
#greater_equal(other) ⇒ Vector Also known as: >=, ge
Compare values for ordered inequality (self >= other).
A nil on either side emits a nil comparison result.
- Binary element-wise function
-
Returns a Vector.
490 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 490 define_binary_element_wise :greater_equal |
#has_nil? ⇒ true, false
Return true if self has any nil.
453 454 455 |
# File 'lib/red_amber/vector.rb', line 453 def has_nil? is_nil.any end |
#indices ⇒ Array Also known as: indexes, indeces
Indeces from 0 to size-1 by Array.
206 207 208 |
# File 'lib/red_amber/vector.rb', line 206 def indices (0...size).to_a end |
#inspect(limit: 80) ⇒ String
String representation of self.
According to ‘ENV [“RED_AMBER_OUTPUT_MODE”].upcase`,
-
If it is ‘MINIMUM’, returns class and size.
-
If it is otherwise, returns class, size and preview. Default value of the ENV is ‘Table’.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/red_amber/vector.rb', line 166 def inspect(limit: 80) if ENV.fetch('RED_AMBER_OUTPUT_MODE', 'Table').casecmp('MINIMUM').zero? # Better performance than `.upcase == 'MINIMUM'` "#{self.class}(:#{type}, size=#{size})" else sio = StringIO.new << '[' each.with_index do |e, i| next_str = "#{sio.size > 1 ? ', ' : ''}#{e.inspect}" if (sio.size + next_str.size) < limit sio << next_str else sio << ', ... ' if i < size break end end sio << ']' chunked = chunked? ? ', chunked' : '' format "#<#{self.class}(:#{type}, size=#{size}#{chunked}):0x%016x>\n%s\n", object_id, sio.string end end |
#integer? ⇒ true, false
Test if self is a integer Vector.
284 285 286 |
# File 'lib/red_amber/vector.rb', line 284 def integer? @data.integer? end |
#invert ⇒ Vector Also known as: !, not
Invert boolean values
- Unary element-wise function
-
Returns a Vector.
513 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 513 define_unary_element_wise :invert |
#is_finite ⇒ Vector
Return true if value is finite.
For each input value, emit true if the value is finite. (i.e. neither NaN, inf, nor -inf).
- Unary element-wise function
-
Returns a Vector.
243 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 243 define_unary_element_wise :is_finite |
#is_inf ⇒ Vector
Return true if value is infinity.
For each input value, emit true if the value is infinite (inf or -inf).
- Unary element-wise function
-
Returns a Vector.
251 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 251 define_unary_element_wise :is_inf |
#is_na ⇒ Vector
return true if value is nil or NaN.
For each input value, emit true if the value is nil or NaN.
259 260 261 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 259 def is_na # rubocop:disable Naming/PredicateName numeric? ? (is_nil | is_nan) : is_nil end |
#is_nan ⇒ Vector
Return true if NaN.
For each input value, emit true if the value is NaN.
- Unary element-wise function
-
Returns a Vector.
269 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 269 define_unary_element_wise :is_nan |
#is_null ⇒ Vector Also known as: is_nil
Arrow::NullOptions is not supported yet.
Return true if nil.
For each input value, emit true if the value is nil.
- Unary element-wise function
-
Returns a Vector.
278 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 278 define_unary_element_wise :is_null |
#is_valid ⇒ Vector
Return true if non-nil.
For each input value, emit true if the value is valid (i.e. non-nil).
- Unary element-wise function
-
Returns a Vector.
287 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 287 define_unary_element_wise :is_valid |
#less(other) ⇒ Vector Also known as: <, lt
Compare values for ordered inequality (self < other).
A nil on either side emits a nil comparison result.
- Binary element-wise function
-
Returns a Vector.
503 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 503 define_binary_element_wise :less |
#less_equal(other) ⇒ Vector Also known as: <=, le
Compare values for ordered inequality (self <= other).
A nil on either side emits a nil comparison result.
- Binary element-wise function
-
Returns a Vector.
516 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 516 define_binary_element_wise :less_equal |
#list? ⇒ true, false
Test if self is a list Vector.
320 321 322 |
# File 'lib/red_amber/vector.rb', line 320 def list? @data.list? end |
#ln ⇒ Vector
Compute natural logarithm.
Non-positive values return -inf or NaN. Nil values return nil.
- Unary element-wise function
-
Returns a Vector.
295 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 295 define_unary_element_wise :ln |
#ln_checked ⇒ Vector
Compute natural logarithm.
This function is a overflow-checking variant of #ln.
- Unary element-wise function
-
Returns a Vector.
302 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 302 define_unary_element_wise :ln_checked |
#log10 ⇒ Vector
Compute base 10 logarithm.
Non-positive values return -inf or NaN. Nil values return nil.
- Unary element-wise function
-
Returns a Vector.
310 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 310 define_unary_element_wise :log10 |
#log10_checked ⇒ Vector
Compute base 10 logarithm.
This function is a overflow-checking variant of #log10.
- Unary element-wise function
-
Returns a Vector.
317 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 317 define_unary_element_wise :log10_checked |
#log1p ⇒ Vector
Compute natural log of (1+x).
Non-positive values return -inf or NaN. Nil values return nil. This function may be more precise than log(1 + x) for x close to zero.
- Unary element-wise function
-
Returns a Vector.
326 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 326 define_unary_element_wise :log1p |
#log1p_checked ⇒ Vector
Compute natural log of (1+x).
This function is a overflow-checking variant of #log1p.
- Unary element-wise function
-
Returns a Vector.
333 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 333 define_unary_element_wise :log1p_checked |
#log2 ⇒ Vector
Compute base 2 logarithm.
Non-positive values return -inf or NaN. Nil values return nil.
- Unary element-wise function
-
Returns a Vector.
341 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 341 define_unary_element_wise :log2 |
#log2_checked ⇒ Vector
Compute base 2 logarithm.
This function is a overflow-checking variant of #log2.
- Unary element-wise function
-
Returns a Vector.
348 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 348 define_unary_element_wise :log2_checked |
#logb(b) ⇒ Vector
Compute base ‘b` logarithm of self.
Non positive values return -inf or NaN. Nil values return nil.
- Binary element-wise function
-
Returns a Vector.
175 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 175 define_binary_element_wise :logb |
#logb_checked ⇒ Vector
Compute base ‘b` logarithm of self.
This function is a overflow-checking variant of #logb.
- Binary element-wise function
-
Returns a Vector.
182 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 182 define_binary_element_wise :logb_checked |
#map ⇒ Enumerator #map {|element| ... } ⇒ self Also known as: collect
Returns a Vector from collected objects from the block.
370 371 372 373 374 |
# File 'lib/red_amber/vector.rb', line 370 def map(&block) return enum_for(:map) unless block Vector.new(to_a.map(&block)) end |
#max(skip_nulls: true, min_count: 1) ⇒ Numeric
Compute maximum value of self.
- Unary aggregation function
-
Returns a scalar.
135 |
# File 'lib/red_amber/vector_aggregation.rb', line 135 define_unary_aggregation :max |
#mean(skip_nulls: true, min_count: 1) ⇒ Numeric
Compute mean value of self.
- Unary aggregation function
-
Returns a scalar.
144 |
# File 'lib/red_amber/vector_aggregation.rb', line 144 define_unary_aggregation :mean |
#min(skip_nulls: true, min_count: 1) ⇒ Numeric
Compute minimum value of self.
- Unary aggregation function
-
Returns a scalar.
153 |
# File 'lib/red_amber/vector_aggregation.rb', line 153 define_unary_aggregation :min |
#min_max(skip_nulls: true, min_count: 1) ⇒ Array<min, max>
Compute the min and max value of self.
- Unary aggregation function
-
Returns a scalar.
162 |
# File 'lib/red_amber/vector_aggregation.rb', line 162 define_unary_aggregation :min_max |
#mode ⇒ Hash{'mode'=>mode, 'count'=>count}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Self must be a numeric or a boolean Vector.
ModeOptions are not supported in 0.5.0 . Only one mode value is returned.
Compute the 1 most common values and their respective
occurence counts.
175 176 177 178 |
# File 'lib/red_amber/vector_aggregation.rb', line 175 def mode datum = find(:mode).execute([data]) datum.value.to_a.first end |
#modulo(divisor) ⇒ Vector Also known as: %
Same behavior as Ruby.
Returns element-wise modulo.
This is equivalent to ‘self-divisor*(self/divisor).floor`.
257 258 259 260 261 262 263 264 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 257 def modulo(divisor) divisor = divisor.data if divisor.is_a?(Vector) d = find(:divide).execute([data, divisor]) d = find(:floor).execute([d]) if d.value.is_a?(Arrow::DoubleArray) m = find(:multiply).execute([d, divisor]) datum = find(:subtract).execute([data, m]) Vector.create(datum.value) end |
#modulo_checked(divisor) ⇒ Vector
Returns element-wise modulo.
This function is a overflow-checking variant of #modulo.
272 273 274 275 276 277 278 279 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 272 def modulo_checked(divisor) divisor = divisor.data if divisor.is_a?(Vector) d = find(:divide_checked).execute([data, divisor]) d = find(:floor).execute([d]) if d.value.is_a?(Arrow::DoubleArray) m = find(:multiply_checked).execute([d, divisor]) datum = find(:subtract_checked).execute([data, m]) Vector.create(datum.value) end |
#multiply(other) ⇒ Vector Also known as: mul, *
Multiply the arguments element-wise.
Results will wrap around on integer overflow.
- Binary element-wise function
-
Returns a Vector.
290 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 290 define_binary_element_wise :multiply |
#multiply_checked ⇒ Vector
Multiply the arguments element-wise.
This function is a overflow-checking variant of #multiply.
- Binary element-wise function
-
Returns a Vector.
299 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 299 define_binary_element_wise :multiply_checked |
#n_chunks ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the number of chunks.
393 394 395 |
# File 'lib/red_amber/vector.rb', line 393 def n_chunks chunked? ? @data.n_chunks : 0 end |
#n_nans ⇒ Integer
Count NaNs in self if self is a numeric Vector
444 445 446 |
# File 'lib/red_amber/vector.rb', line 444 def n_nans numeric? ? is_nan.to_a.count(true) : 0 end |
#n_nulls ⇒ Integer Also known as: n_nils
Count nils in self.
433 434 435 |
# File 'lib/red_amber/vector.rb', line 433 def n_nulls @data.n_nulls end |
#negate ⇒ Vector Also known as: -@
Negate the argument element-wise
Results will wrap around on integer overflow.
- Unary element-wise function
-
Returns a Vector.
523 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 523 define_unary_element_wise :negate |
#negate_checked ⇒ Vector
Negate the argument element-wise
This function is a overflow-checking variant of #negate.
- Unary element-wise function
-
Returns a Vector.
531 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 531 define_unary_element_wise :negate_checked |
#not_equal(other) ⇒ Vector Also known as: !=, ne
Compare values for inequality (self != other).
A nil on either side emits a nil comparison result.
- Binary element-wise function
-
Returns a Vector.
529 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 529 define_binary_element_wise :not_equal |
#numeric? ⇒ true, false
Test if self is a numeric Vector.
266 267 268 |
# File 'lib/red_amber/vector.rb', line 266 def numeric? @data.numeric? end |
#one ⇒ Object?
Get a non-nil element in self.
266 267 268 |
# File 'lib/red_amber/vector_aggregation.rb', line 266 def one each.find { !_1.nil? } end |
#or_kleene(other) ⇒ Vector Also known as: |
Logical ‘or’ boolean values with Kleene logic.
This function behaves as follows with nils:
-
true or nil = true
-
nil or true = true
-
false or nil = nil
-
nil or false = nil
-
nil or nil = nil
In other words, in this context a nil value really means “unknown”, and an unknown value ‘or’ true is always true. For a different nil behavior, see function #or_org.
- Binary element-wise function
-
Returns a Vector.
194 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 194 define_binary_element_wise :or_kleene |
#or_org(other) ⇒ Vector
Logical ‘or’ boolean values.
When a nil is encountered in either input, a nil is output. For a different nil behavior, see function #or_kleene.
- Binary element-wise function
-
Returns a Vector.
207 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 207 define_binary_element_wise_logical(:or_org, :or) |
#power(exponent) ⇒ Vector Also known as: pow, **
Raise arguments to power element-wise.
Integer to negative integer power returns an error. However, integer overflow wraps around. If either self or exponent is nil the result will be nil.
- Binary element-wise function
-
Returns a Vector.
312 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 312 define_binary_element_wise :power |
#power_checked ⇒ Vector
Raise arguments to power element-wise.
This function is a overflow-checking variant of #power.
- Binary element-wise function
-
Returns a Vector.
321 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 321 define_binary_element_wise :power_checked |
#product(skip_nulls: true, min_count: 1) ⇒ Numeric
Self must be a numeric Vector.
Compute product value of self.
- Unary aggregation function
-
Returns a scalar.
188 |
# File 'lib/red_amber/vector_aggregation.rb', line 188 define_unary_aggregation :product |
#propagate(function) ⇒ Vector #propagate {|self| ... } ⇒ Vector Also known as: expand
Spread the return value of an aggregate function as if
it is a element-wise function.
526 527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'lib/red_amber/vector.rb', line 526 def propagate(function = nil, &block) value = if block raise VectorArgumentError, "can't specify both function and block" if function yield self else send(function&.to_sym) end raise VectorArgumentError, 'not an aggregation function' if value.is_a?(Vector) Vector.new([value] * size) end |
#quantile(prob = 0.5, interpolation: :linear, skip_nulls: true, min_count: 0) ⇒ Float
Returns a quantile value.
-
0.5 quantile (median) is returned by default.
-
Or return quantile for specified probability (prob).
-
If quantile lies between two data points, interpolated value is returned based on selected interpolation method.
-
Nils and NaNs are ignored.
-
Nil is returned if there are no valid data point.
290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/red_amber/vector_aggregation.rb', line 290 def quantile(prob = 0.5, interpolation: :linear, skip_nulls: true, min_count: 0) unless (0..1).cover? prob raise VectorArgumentError, "Invalid: probability #{prob} must be between 0 and 1" end datum = find(:quantile).execute([data], q: prob, interpolation: interpolation, skip_nulls: skip_nulls, min_count: min_count) datum.value.to_a.first end |
#quantiles(probs = [0.0, 0.25, 0.5, 0.75, 1.0], interpolation: :linear, skip_nulls: true, min_count: 0) ⇒ DataFrame
Return quantiles in a DataFrame
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/red_amber/vector_aggregation.rb', line 322 def quantiles(probs = [0.0, 0.25, 0.5, 0.75, 1.0], interpolation: :linear, skip_nulls: true, min_count: 0) if probs.empty? || !probs.all? { |q| (0..1).cover?(q) } raise VectorArgumentError, "Invarid probavilities #{probs}" end DataFrame.new( probs: probs, quantiles: probs.map do |q| quantile(q, interpolation: interpolation, skip_nulls: skip_nulls, min_count: min_count) end ) end |
#remainder(divisor) ⇒ Vector
Same behavior as Ruby’s remainder.
Returns element-wise remainder.
This is equivalent to ‘self-divisor*(self/divisor).trunc`.
356 357 358 359 360 361 362 363 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 356 def remainder(divisor) divisor = divisor.data if divisor.is_a?(Vector) d = find(:divide).execute([data, divisor]) d = find(:trunc).execute([d]) if d.value.is_a?(Arrow::DoubleArray) m = find(:multiply).execute([d, divisor]) datum = find(:subtract).execute([data, m]) Vector.create(datum.value) end |
#remainder_checked(divisor) ⇒ Vector
Returns element-wise modulo.
This function is a overflow-checking variant of #modulo.
370 371 372 373 374 375 376 377 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 370 def remainder_checked(divisor) divisor = divisor.data if divisor.is_a?(Vector) d = find(:divide_checked).execute([data, divisor]) d = find(:trunc).execute([d]) if d.value.is_a?(Arrow::DoubleArray) m = find(:multiply_checked).execute([d, divisor]) datum = find(:subtract_checked).execute([data, m]) Vector.create(datum.value) end |
#resolve(other) ⇒ Vector
Return other as a Vector which is same data type as self.
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/red_amber/vector.rb', line 123 def resolve(other) case other when Vector Vector.create(data.resolve(other.data)) when Array, Arrow::Array, Arrow::ChunkedArray Vector.create(data.resolve(other)) else raise VectorArgumentError, "invalid argument: #{other}" end end |
#round(n_digits: 0, round_mode: :half_to_even) ⇒ Vector
Round to a given precision.
Options are used to control the number of digits and rounding mode. Default behavior is to round to the nearest integer and use half-to-even rule to break ties.
- Unary element-wise function
-
Returns a Vector.
412 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 412 define_unary_element_wise :round |
#round_to_multiple(multiple: 1.0, round_mode: :half_to_even) ⇒ Vector
Round to a given multiple.
Options are used to control the rounding multiple and rounding mode. Default behavior is to round to the nearest integer and use half-to-even rule to break ties.
429 430 431 432 433 434 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 429 def round_to_multiple(multiple: 1.0, round_mode: :half_to_even) datum = exec_func_unary(:round_to_multiple, multiple: Arrow::DoubleScalar.new(multiple), round_mode: round_mode) Vector.create(datum.value) end |
#sd(ddof: 1, skip_nulls: true, min_count: 1) ⇒ Float Also known as: std
Self must be a numeric Vector.
Calculate unbiased standard deviation of self.
208 209 210 |
# File 'lib/red_amber/vector_aggregation.rb', line 208 def sd stddev(ddof: 1) end |
#shift_left(amount) ⇒ Vector Also known as: <<
Left shift of self by other.
The shift operates as if on the two’s complement representation of the number. In other words, this is equivalent to multiplying self by 2 to the power ‘amount’, even if overflow occurs. self is returned if ‘amount’ (the amount to shift by) is negative or greater than or equal to the precision of self.
- Binary element-wise function
-
Returns a Vector.
412 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 412 define_binary_element_wise :shift_left |
#shift_left_checked ⇒ Vector
Left shift of self by other.
This function is a overflow-checking variant of #shift_left.
- Binary element-wise function
-
Returns a Vector.
420 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 420 define_binary_element_wise :shift_left_checked |
#shift_right(amount) ⇒ Vector Also known as: >>
Right shift of self by other.
This is equivalent to dividing ‘x` by 2 to the power `y`. Self is returned if ’amount’ (the amount to shift by) is: negative or greater than or equal to the precision of self.
- Binary element-wise function
-
Returns a Vector.
433 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 433 define_binary_element_wise :shift_right |
#shift_right_checked ⇒ Vector
Right shift of self by other.
This function is a overflow-checking variant of #shift_right.
- Binary element-wise function
-
Returns a Vector.
441 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 441 define_binary_element_wise :shift_right_checked |
#sign ⇒ Vector
Get the signedness of the arguments element-wise.
Output is any of (-1,1) for nonzero inputs and 0 for zero input. NaN values return NaN. Integral values return signedness as Int8 and floating-point values return it with the same type as the input values.
- Unary element-wise function
-
Returns a Vector.
444 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 444 define_unary_element_wise :sign |
#sin ⇒ Vector
Compute the sine of self element-wise.
NaN is returned for invalid input values.
- Unary element-wise function
-
Returns a Vector.
452 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 452 define_unary_element_wise :sin |
#sin_checked ⇒ Vector
Compute the sine of self element-wise.
This function is a overflow-checking variant of #sin.
- Unary element-wise function
-
Returns a Vector.
459 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 459 define_unary_element_wise :sin_checked |
#size ⇒ Integer Also known as: length, n_rows, nrow
Vector size.
217 218 219 220 |
# File 'lib/red_amber/vector.rb', line 217 def size # only defined :length in Arrow? @data.length end |
#sqrt ⇒ Vector
Compute square root of self.
NaN is returned for invalid input values.
- Unary element-wise function
-
Returns a Vector.
467 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 467 define_unary_element_wise :sqrt |
#sqrt_checked ⇒ Vector
Compute square root of self.
This function is a overflow-checking variant of #sqrt.
- Unary element-wise function
-
Returns a Vector.
474 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 474 define_unary_element_wise :sqrt_checked |
#stddev(ddof: 0, skip_nulls: true, min_count: 1) ⇒ Float
Self must be a numeric Vector.
Calculate standard deviation of self.
- Unary aggregation function
-
Returns a scalar.
198 |
# File 'lib/red_amber/vector_aggregation.rb', line 198 define_unary_aggregation :stddev |
#string? ⇒ true, false
Test if self is a string Vector.
293 294 295 |
# File 'lib/red_amber/vector.rb', line 293 def string? @data.string? end |
#subtract(other) ⇒ Vector Also known as: sub, -
Subtract the arguments element-wise.
Results will wrap around on integer overflow.
- Binary element-wise function
-
Returns a Vector.
388 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 388 define_binary_element_wise :subtract |
#subtract_checked ⇒ Vector
Subtract the arguments element-wise.
This function is a overflow-checking variant of #subtract.
- Binary element-wise function
-
Returns a Vector.
397 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 397 define_binary_element_wise :subtract_checked |
#sum(skip_nulls: true, min_count: 1) ⇒ Numeric
Self must be a numeric Vector.
Compute sum of self.
- Unary aggregation function
-
Returns a scalar.
221 |
# File 'lib/red_amber/vector_aggregation.rb', line 221 define_unary_aggregation :sum |
#tally ⇒ Hash
Returns a hash containing the counts of equal elements.
-
Each key is an element of self.
-
Each value is the number of elements equal to the key.
406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/red_amber/vector.rb', line 406 def tally hash = values.tally if (type_class < Arrow::FloatingPointDataType) && is_nan.any a = 0 hash.each do |key, value| if key.is_a?(Float) && key.nan? hash.delete(key) a += value end end hash[Float::NAN] = a end hash end |
#tan ⇒ Vector
Compute the tangent of self element-wise.
NaN is returned for invalid input values.
- Unary element-wise function
-
Returns a Vector.
482 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 482 define_unary_element_wise :tan |
#tan_checked ⇒ Vector
Compute the tangent of self element-wise.
This function is a overflow-checking variant of #tan.
- Unary element-wise function
-
Returns a Vector.
489 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 489 define_unary_element_wise :tan_checked |
#temporal? ⇒ true, false
Test if self is a temporal Vector.
311 312 313 |
# File 'lib/red_amber/vector.rb', line 311 def temporal? @data.temporal? end |
#to_ary ⇒ Array Also known as: to_a, values, entries
Convert to an Array.
194 195 196 |
# File 'lib/red_amber/vector.rb', line 194 def to_ary @data.values end |
#to_s ⇒ String
String representation of self like an Array.
139 140 141 |
# File 'lib/red_amber/vector.rb', line 139 def to_s @data.to_a.inspect end |
#trunc ⇒ Vector
Compute the integral part
Compute the nearest integer not greater in magnitude than each element.
- Unary element-wise function
-
Returns a Vector.
497 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 497 define_unary_element_wise :trunc |
#type ⇒ Symbol
Type nickname of self.
239 240 241 |
# File 'lib/red_amber/vector.rb', line 239 def type list? ? :list : @data.value_type.nick.to_sym end |
#type_class ⇒ type_Class
Type Class of self.
248 249 250 |
# File 'lib/red_amber/vector.rb', line 248 def type_class @data.type_class end |
#unbiased_variance(ddof: 1, skip_nulls: true, min_count: 1) ⇒ Float Also known as: var
self must be a numeric Vector.
Calculate unbiased variance of self.
245 246 247 |
# File 'lib/red_amber/vector_aggregation.rb', line 245 def unbiased_variance variance(ddof: 1) end |
#unique ⇒ Vector Also known as: uniq
Compute unique elements
Return an array with distinct values. Nils in the input are ignored.
- Unary element-wise function
-
Returns a Vector.
505 |
# File 'lib/red_amber/vector_unary_element_wise.rb', line 505 define_unary_element_wise :unique |
#value_counts ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Arrow imprementation of #tally
423 424 425 426 |
# File 'lib/red_amber/vector.rb', line 423 def value_counts values, counts = Arrow::Function.find(:value_counts).execute([data]).value.fields values.zip(counts).to_h end |
#variance(ddof: 0, skip_nulls: true, min_count: 1) ⇒ Float
Self must be a numeric Vector.
Calculate variance of self.
- Unary aggregation function
-
Returns a scalar.
235 |
# File 'lib/red_amber/vector_aggregation.rb', line 235 define_unary_aggregation :variance |
#xor(other) ⇒ Vector Also known as: ^
Logical ‘xor’ boolean values
When a nil is encountered in either input, a nil is output.
- Binary element-wise function
-
Returns a Vector.
452 |
# File 'lib/red_amber/vector_binary_element_wise.rb', line 452 define_binary_element_wise :xor |