Class: NuLin::Cholesky

Inherits:
Object
  • Object
show all
Defined in:
lib/nulin/cholesky.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matrix, options) ⇒ Cholesky

Returns a new instance of Cholesky.



26
27
28
29
30
31
32
33
34
35
# File 'lib/nulin/cholesky.rb', line 26

def initialize(matrix, options)
  @a = matrix
  @typecode = matrix.typecode
  case options.fetch(:type, :U)
  when :U then @upper_triangular = true
  when :L then @upper_triangular = false
  else raise ArgumentError, "NuLin.cholesky: :type argument should be :U or :L"
  end
  compute
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



37
38
39
# File 'lib/nulin/cholesky.rb', line 37

def result
  @result
end

Instance Method Details

#clear_lowerObject



53
54
55
56
# File 'lib/nulin/cholesky.rb', line 53

def clear_lower
  n, = @result.shape
  0.upto(n-1){|i| (i+1).upto(n-1){|j| @result[i, j] = 0.0 } }
end

#clear_upperObject



58
59
60
61
# File 'lib/nulin/cholesky.rb', line 58

def clear_upper
  n, = @result.shape
  0.upto(n-1){|i| (i+1).upto(n-1){|j| @result[j, i] = 0.0 } }
end

#computeObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/nulin/cholesky.rb', line 39

def compute
  n, = @a.shape
  @result = @a.transpose
  NuLin::Native.call(@typecode, "potrf", @upper_triangular ? "L" : "U",
                     n, @result, n, 0)
  if @upper_triangular
    clear_lower
  else
    clear_upper
  end

  @result.conj!
end