Module: StairCar::UMatrixTransforms

Included in:
UMatrix
Defined in:
lib/stair_car/umatrix/transforms.rb

Instance Method Summary collapse

Instance Method Details

#map(&block) ⇒ Object



11
12
13
# File 'lib/stair_car/umatrix/transforms.rb', line 11

def map(&block)
  dup.map!(&block)
end

#map!Object



15
16
17
18
19
20
21
# File 'lib/stair_car/umatrix/transforms.rb', line 15

def map!
  result = self.each_with_index do |val,row,col|
    self[row,col] = yield(val, row, col)
  end

  return self
end

#map_non_zero(&block) ⇒ Object



23
24
25
# File 'lib/stair_car/umatrix/transforms.rb', line 23

def map_non_zero(&block)
  dup.map_non_zero!(&block)
end

#map_non_zero!Object



27
28
29
30
31
32
33
# File 'lib/stair_car/umatrix/transforms.rb', line 27

def map_non_zero!
  each_non_zero do |val,row,col|
    self[row,col] = yield(val, row, col)
  end

  return self
end

#to_aObject

Converts the matrix into an array



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/stair_car/umatrix/transforms.rb', line 36

def to_a
  array = []
  rows.times do |row|
    col_array = []
    cols.times do |col|
      col_array << self.value_at(row,col)
    end
    array << col_array
  end

  return array
end

#transposeObject



3
4
5
# File 'lib/stair_car/umatrix/transforms.rb', line 3

def transpose
  return UMatrix.new(@data.transpose)
end

#~Object



7
8
9
# File 'lib/stair_car/umatrix/transforms.rb', line 7

def ~
  return transpose
end