Class: NuLin::Cholesky
- Inherits:
-
Object
- Object
- NuLin::Cholesky
- Defined in:
- lib/nulin/cholesky.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #clear_lower ⇒ Object
- #clear_upper ⇒ Object
- #compute ⇒ Object
-
#initialize(matrix, options) ⇒ Cholesky
constructor
A new instance of Cholesky.
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, ) @a = matrix @typecode = matrix.typecode case .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
#result ⇒ Object (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_lower ⇒ Object
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_upper ⇒ Object
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 |
#compute ⇒ Object
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 |