Class: NuLin::LLS_QR

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

Instance Attribute Summary

Attributes inherited from LLS

#solution

Instance Method Summary collapse

Methods inherited from LLS

#valid_matrix?

Constructor Details

#initialize(a, b, options) ⇒ LLS_QR

Returns a new instance of LLS_QR.



76
77
78
79
# File 'lib/nulin/lls.rb', line 76

def initialize(a, b, options)
  super
  compute
end

Instance Method Details

#computeObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/nulin/lls.rb', line 81

def compute
  m, n = @a.shape
  lda = m
  ldb = [1, m, n].max
  r, nrhs = @b.shape
  b = NVector.new(@typecode, ldb, nrhs)
  b[0...m, 0...nrhs] = @b
  lwork = [1, [m,n].min + [[m,n].min, nrhs].max].max
  work = NArray.new(@typecode, lwork)
  NuLin::Native.call(@typecode, "gels", "N", m, n, nrhs, @a, lda, b, ldb,
                     work, lwork, 0)
  @solution = b[0...n, true]
  @solution.flatten! if @b_is_rank1
end