Class: NuLin::LLS_SVD
Instance Attribute Summary collapse
-
#rank ⇒ Object
readonly
The effective rank of the matrix.
-
#singular_values ⇒ Object
readonly
Singular values of the matrix as NArray.
Attributes inherited from LLS
Instance Method Summary collapse
- #compute ⇒ Object
-
#initialize(a, b, options) ⇒ LLS_SVD
constructor
A new instance of LLS_SVD.
Methods inherited from LLS
Constructor Details
#initialize(a, b, options) ⇒ LLS_SVD
Returns a new instance of LLS_SVD.
98 99 100 101 102 |
# File 'lib/nulin/lls.rb', line 98 def initialize(a, b, ) super @rcond = .fetch(:rcond, -1.0) compute end |
Instance Attribute Details
#rank ⇒ Object (readonly)
The effective rank of the matrix.
108 109 110 |
# File 'lib/nulin/lls.rb', line 108 def rank @rank end |
#singular_values ⇒ Object (readonly)
Singular values of the matrix as NArray. The values are ordered decreasingly.
106 107 108 |
# File 'lib/nulin/lls.rb', line 106 def singular_values @singular_values end |
Instance Method Details
#compute ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/nulin/lls.rb', line 110 def compute m, n = @a.shape r, nrhs = @b.shape k = [m, n].min lda = [1, m].max ldb = [1, m, n].max b = NVector.new(@typecode, ldb, nrhs) b[0...m, 0...nrhs] = @b s = NArray.new(NuLin.to_real_typecode(@typecode), k) lwork = 3*k + [2*k, m, n, nrhs].max + 1 work = NVector.new(@typecode, lwork) if @a.complex? rwork = [NArray.new(@typecode, 5*k)] else rwork = [] end @rank, = NuLin::Native.call(@typecode, "gelss", m, n, nrhs, @a, lda, b, ldb, s, @rcond, 0, work, lwork, *rwork, 0) @singular_values = s @solution = b[0...n, true] @solution.flatten! if @b_is_rank1 end |