Class: Steffi::Vector

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/steffi/vector.rb

Defined Under Namespace

Classes: Struct

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVector

Returns a new instance of Vector.

[View source]

28
29
30
31
# File 'lib/steffi/vector.rb', line 28

def initialize
  @ptr = FFI::MemoryPointer.new Vector::Struct
  Igraph.vector_init ptr, 0
end

Instance Attribute Details

#ptrObject (readonly)

Returns the value of attribute ptr.


26
27
28
# File 'lib/steffi/vector.rb', line 26

def ptr
  @ptr
end

Class Method Details

.from_a(ary) ⇒ Object

[View source]

57
58
59
60
61
# File 'lib/steffi/vector.rb', line 57

def self.from_a ary
  v = new
  ary.each { |i| v << i }
  v
end

Instance Method Details

#<<(obj) ⇒ Object

[View source]

33
34
35
# File 'lib/steffi/vector.rb', line 33

def << obj
  Igraph.vector_push_back ptr, obj.to_f
end

#[](i) ⇒ Object

[View source]

37
38
39
# File 'lib/steffi/vector.rb', line 37

def [] i
  Igraph.vector_e ptr, i
end

#[]=(i, obj) ⇒ Object

[View source]

41
42
43
# File 'lib/steffi/vector.rb', line 41

def []= i, obj
  Igraph.vector_set ptr, i, obj.to_f
end

#eachObject

[View source]

49
50
51
# File 'lib/steffi/vector.rb', line 49

def each
  0.upto(size-1) { |i| yield self[i] }
end

#sizeObject

[View source]

45
46
47
# File 'lib/steffi/vector.rb', line 45

def size
  Igraph.vector_size ptr
end

#to_sObject

[View source]

53
54
55
# File 'lib/steffi/vector.rb', line 53

def to_s
  to_a.to_s
end