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



102
103
104
105
106
# File 'lib/cicada/mutable_matrix.rb', line 102

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



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

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



118
119
120
121
122
123
124
125
126
# File 'lib/cicada/mutable_matrix.rb', line 118

def replace(other)

  self.each_with_index do |e,i|

    self[i] = other[i]
  
  end

end