Class: NLopt::Gradient
- Inherits:
-
Object
- Object
- NLopt::Gradient
- Defined in:
- lib/nlopt/gradient.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #[]=(index, value) ⇒ Object
-
#initialize(ptr, n) ⇒ Gradient
constructor
A new instance of Gradient.
- #inspect ⇒ Object (also: #to_s)
- #size ⇒ Object
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 |
#inspect ⇒ Object 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 |
#size ⇒ Object
18 19 20 |
# File 'lib/nlopt/gradient.rb', line 18 def size @n end |