Module: StairCar::PMatrixTransforms

Included in:
PMatrix
Defined in:
lib/stair_car/pmatrix/transforms.rb

Instance Method Summary collapse

Instance Method Details

#countObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stair_car/pmatrix/transforms.rb', line 48

def count
  count = 0

  each do |val,row,col|
    if yield(val,row,col)
      count += 1
    end
  end

  return count
end

#invObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/stair_car/pmatrix/transforms.rb', line 11

def inv
  algebra = Java::cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra.new
  begin
    return PMatrix.new(algebra.inverse(@data))
  rescue Java::JavaLang::IllegalArgumentException => e
    if e.message == 'Matrix is singular.' || e.message == 'A is singular.'
      raise InverseMatrixIsSignular, e.message
    else
      raise
    end
  end
end

#map(&block) ⇒ Object



24
25
26
# File 'lib/stair_car/pmatrix/transforms.rb', line 24

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

#map!Object



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

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



36
37
38
# File 'lib/stair_car/pmatrix/transforms.rb', line 36

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

#map_non_zero!Object



40
41
42
43
44
45
46
# File 'lib/stair_car/pmatrix/transforms.rb', line 40

def map_non_zero!
  result = @data.for_each_non_zero do |row,col,val|
    yield(val, row, col)
  end

  PMatrix.new(result)
end

#to_aObject

Converts the matrix into an array



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/stair_car/pmatrix/transforms.rb', line 61

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/pmatrix/transforms.rb', line 3

def transpose
  return PMatrix.new(@data.view_dice.copy)
end

#~Object



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

def ~
  return transpose
end