Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/ryeppp/bench.rb

Instance Method Summary collapse

Instance Method Details

#cosObject



196
197
198
# File 'lib/ryeppp/bench.rb', line 196

def cos
  self.map{|o| Math.cos(o)}
end

#dot_product_f(v2) ⇒ Object



338
339
340
341
342
# File 'lib/ryeppp/bench.rb', line 338

def dot_product_f(v2)
  self.each.with_index.inject(0) do |sum, (o, idx)|
    sum + o.to_f * v2[idx]
  end
end

#evaluate_polynomial(x) ⇒ Object



374
375
376
377
378
379
380
# File 'lib/ryeppp/bench.rb', line 374

def evaluate_polynomial(x)
  if self.size == 1
    self.first
  else
    self.last + x * self[0..-2].evaluate_polynomial(x)
  end
end

#evaluate_polynomial_iter(x) ⇒ Object



381
382
383
384
385
# File 'lib/ryeppp/bench.rb', line 381

def evaluate_polynomial_iter(x)
  self.map.with_index do |o, i|
    self[i] * x ** (self.size - 1 - i)
  end.sum
end

#expObject



190
191
192
# File 'lib/ryeppp/bench.rb', line 190

def exp
  self.map{|o| Math::E ** o}
end

#logObject



187
188
189
# File 'lib/ryeppp/bench.rb', line 187

def log
  self.map{|o| Math.log(o)}
end

#max_v64f_s64fObject Also known as: max_v64s_s64s



21
22
23
# File 'lib/ryeppp/bench.rb', line 21

def max_v64f_s64f
  self.inject(self[0]){|maximum, o| o > maximum ? o : maximum}
end

#max_v64fs64f_v64f(c) ⇒ Object



153
154
155
# File 'lib/ryeppp/bench.rb', line 153

def max_v64fs64f_v64f(c)
  self.map{|o| o > c ? o : c}
end

#max_v64fv64f_v64f(b) ⇒ Object



108
109
110
111
# File 'lib/ryeppp/bench.rb', line 108

def max_v64fv64f_v64f(b)
  raise "Invalid sizes: #{self.size}, #{b.size}" unless self.size == b.size
  self.zip(b).map(&:max)
end

#min_v64f_s64fObject Also known as: min_v64s_s64s



17
18
19
# File 'lib/ryeppp/bench.rb', line 17

def min_v64f_s64f
  self.inject(self[0]){|minimum, o| o < minimum ? o : minimum}
end

#min_v64fs64f_v64f(c) ⇒ Object



150
151
152
# File 'lib/ryeppp/bench.rb', line 150

def min_v64fs64f_v64f(c)
  self.map{|o| o < c ? o : c}
end

#min_v64fv64f_v64f(b) ⇒ Object



104
105
106
107
# File 'lib/ryeppp/bench.rb', line 104

def min_v64fv64f_v64f(b)
  raise "Invalid sizes: #{self.size}, #{b.size}" unless self.size == b.size
  self.zip(b).map(&:min)
end

#sinObject



193
194
195
# File 'lib/ryeppp/bench.rb', line 193

def sin
  self.map{|o| Math.sin(o)}
end

#sumObject



271
272
273
# File 'lib/ryeppp/bench.rb', line 271

def sum
  self.inject(0){|sum, o| sum + o}
end

#sumabsObject



274
275
276
# File 'lib/ryeppp/bench.rb', line 274

def sumabs
  self.inject(0){|sum, o| sum + o.abs}
end

#sumsquaresObject



277
278
279
# File 'lib/ryeppp/bench.rb', line 277

def sumsquares
  self.inject(0){|sum, o| sum + o**2}
end

#tanObject



199
200
201
# File 'lib/ryeppp/bench.rb', line 199

def tan
  self.map{|o| Math.tan(o)}
end