class Charty::VectorAdapters::BaseAdapter
Attributes
data[R]
Public Class Methods
adapter_name()
click to toggle source
# File lib/charty/vector_adapters.rb, line 26 def self.adapter_name name[/:?(\w+)Adapter\z/, 1] end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
# File lib/charty/vector_adapters.rb, line 39 def ==(other) case other.adapter when BaseAdapter return false if other.index != index if respond_to?(:compare_data_equality) compare_data_equality(other.adapter) elsif other.adapter.respond_to?(:compare_data_equality) other.adapter.compare_data_equality(self) else case other.adapter when self.class data == other.data else false end end else super end end
inverse_log_scale(method)
click to toggle source
# File lib/charty/vector_adapters.rb, line 115 def inverse_log_scale(method) Charty::Vector.new( self.map {|x| 10.0 ** x }, index: index, name: name ) end
log_scale(method)
click to toggle source
# File lib/charty/vector_adapters.rb, line 107 def log_scale(method) Charty::Vector.new( self.map {|x| Math.log10(x) }, index: index, name: name ) end
mean()
click to toggle source
# File lib/charty/vector_adapters.rb, line 95 def mean Statistics.mean(data) end
percentile(q)
click to toggle source
# File lib/charty/vector_adapters.rb, line 103 def percentile(q) Statistics.percentile(data, q) end
stdev(population: false)
click to toggle source
# File lib/charty/vector_adapters.rb, line 99 def stdev(population: false) Statistics.stdev(data, population: population) end
values_at(*indices)
click to toggle source
Take values at the given positional indices (without indexing)
# File lib/charty/vector_adapters.rb, line 64 def values_at(*indices) indices.map {|i| data[i] } end
where_in_array(mask)
click to toggle source
# File lib/charty/vector_adapters.rb, line 68 def where_in_array(mask) mask = check_mask_vector(mask) masked_data = [] masked_index = [] mask.each_with_index do |f, i| case f when true, 1 masked_data << data[i] masked_index << index[i] end end return masked_data, masked_index end
Private Instance Methods
check_data(data)
click to toggle source
# File lib/charty/vector_adapters.rb, line 30 def check_data(data) return data if self.class.supported?(data) raise UnsupportedVectorData, "Unsupported vector data (#{data.class})" end
check_mask_vector(mask)
click to toggle source
# File lib/charty/vector_adapters.rb, line 82 def check_mask_vector(mask) # ensure mask is boolean vector case mask when Charty::Vector unless mask.boolean? raise ArgumentError, "Unable to lookup items by a nonboolean vector" end mask else Charty::Vector.new(mask) end end