Class: NLopt::Gradient

Inherits:
Object
  • Object
show all
Defined in:
lib/nlopt/gradient.rb

Instance Method Summary collapse

Constructor Details

#initialize(ptr, n) ⇒ Gradient

Returns a new instance of Gradient.



3
4
5
6
# File 'lib/nlopt/gradient.rb', line 3

def initialize(ptr, n)
  @ptr = ptr
  @n = n
end

Instance Method Details

#[](index) ⇒ Object



8
9
10
11
# File 'lib/nlopt/gradient.rb', line 8

def [](index)
  check_index(index)
  @ptr[index * Fiddle::SIZEOF_DOUBLE, Fiddle::SIZEOF_DOUBLE].unpack1("d")
end

#[]=(index, value) ⇒ Object



13
14
15
16
# File 'lib/nlopt/gradient.rb', line 13

def []=(index, value)
  check_index(index)
  @ptr[index * Fiddle::SIZEOF_DOUBLE, Fiddle::SIZEOF_DOUBLE] = [value].pack("d")
end

#inspectObject Also known as: to_s



22
23
24
# File 'lib/nlopt/gradient.rb', line 22

def inspect
  "#<#{self.class.name} #{@n.times.map { |i| self[i] }.inspect}>"
end

#sizeObject



18
19
20
# File 'lib/nlopt/gradient.rb', line 18

def size
  @n
end