Class: MVector

Inherits:
Vector
  • Object
show all
Defined in:
lib/cicada/mutable_matrix.rb

Overview

Extension to the standard library Vector class making them mutable and adding some additional functionality.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.unit(size) ⇒ MVector

Generates a unit vector of specified size.

Parameters:

  • size (Integer)

    the size of the unit vector

Returns:

  • (MVector)

    a mutable vector of specified size containing all 1.0



91
92
93
# File 'lib/cicada/mutable_matrix.rb', line 91

def MVector.unit(size)
  MVector.elements(Array.new(size, 1.0), false)
end

.zero(size) ⇒ MVector

Generates a zero vector of specified size.

Parameters:

  • size (Integer)

    the size of the zero vector

Returns:

  • (MVector)

    a mutable vector of specified size containing all 0.0



80
81
82
# File 'lib/cicada/mutable_matrix.rb', line 80

def MVector.zero(size)
  elements(Array.new(size, 0.0), false)
end

Instance Method Details

#replace(other) ⇒ void

This method returns an undefined value.

Replaces the contents of this vector with the contents of another vector. This will not change the size of the current vector and will replace entries only up to the current size.

Parameters:

  • other (Vector<Numeric>, Array<Numeric>)

    a vector (or array, or other indexable collection) with at least as many elements as this vector; its entries will replace this vector’s entries



105
106
107
108
109
# File 'lib/cicada/mutable_matrix.rb', line 105

def replace(other)
  self.each_with_index do |e,i|
    self[i] = other[i]
  end
end