Class: Daru::Accessors::GSLWrapper

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
GSLStatistics, Enumerable
Defined in:
lib/daru/accessors/gsl_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GSLStatistics

#kurtosis, #median, #sample_with_replacement, #sample_without_replacement, #skew, #standard_deviation_population, #standard_deviation_sample, #variance_population, #variance_sample, #vector_centered_compute, #vector_standardized_compute

Constructor Details

#initialize(data, context) ⇒ GSLWrapper

Returns a new instance of GSLWrapper.



87
88
89
90
# File 'lib/daru/accessors/gsl_wrapper.rb', line 87

def initialize data, context
  @data = ::GSL::Vector.alloc(data)
  @context = context
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



61
62
63
# File 'lib/daru/accessors/gsl_wrapper.rb', line 61

def data
  @data
end

Instance Method Details

#==(other) ⇒ Object



119
120
121
# File 'lib/daru/accessors/gsl_wrapper.rb', line 119

def == other
  @data == other.data
end

#[]=(index, element) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/daru/accessors/gsl_wrapper.rb', line 92

def []= index, element
  if index == size
    push element
  else
    @data[index] = element
  end
end

#compactObject



63
64
65
66
67
# File 'lib/daru/accessors/gsl_wrapper.rb', line 63

def compact
  # set missing to [] incase @context is not Daru::Vector
  missing = @context.missing_values rescue []
  ::GSL::Vector.alloc(@data.to_a - missing.map(&:to_f))
end

#delete_at(index) ⇒ Object



100
101
102
# File 'lib/daru/accessors/gsl_wrapper.rb', line 100

def delete_at index
  @data.delete_at index
end

#dupObject



115
116
117
# File 'lib/daru/accessors/gsl_wrapper.rb', line 115

def dup
  GSLWrapper.new(@data.to_a, @context)
end

#each(&block) ⇒ Object



77
78
79
80
# File 'lib/daru/accessors/gsl_wrapper.rb', line 77

def each(&block)
  @data.each(&block)
  self
end

#index(key) ⇒ Object



104
105
106
# File 'lib/daru/accessors/gsl_wrapper.rb', line 104

def index key
  @data.to_a.index key
end

#map!(&block) ⇒ Object



82
83
84
85
# File 'lib/daru/accessors/gsl_wrapper.rb', line 82

def map!(&block)
  @data.map!(&block)
  self
end

#push(value) ⇒ Object Also known as: <<, concat



108
109
110
111
# File 'lib/daru/accessors/gsl_wrapper.rb', line 108

def push value
  @data = @data.concat value
  self
end