Class: NuLin::LLS

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

Direct Known Subclasses

LLS_QR, LLS_SVD

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b, options) ⇒ LLS

Returns a new instance of LLS.



53
54
55
56
57
58
59
60
61
62
# File 'lib/nulin/lls.rb', line 53

def initialize(a, b, options)
  if !valid_matrix?(a, b)
    raise NuLin::DimensionError, "Invalid matrix/vector shape"
  end
  @a = a.transpose
  @b_is_rank1 = b.rank == 1
  @b = (@b_is_rank1) ? b.reshape(b.shape[0], 1) : b
  
  @typecode = a.typecode
end

Instance Attribute Details

#solutionObject (readonly)

Return the solution of the LLS problem as NVector.



72
73
74
# File 'lib/nulin/lls.rb', line 72

def solution
  @solution
end

Instance Method Details

#valid_matrix?(a, b) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
# File 'lib/nulin/lls.rb', line 64

def valid_matrix?(a, b)
  a.rank == 2 &&
    (b.rank == 1 || b.rank == 2) &&
    a.shape[1] == b.shape[0] &&
    a.typecode == b.typecode 
end