Class: Ignis::Solver::LUSolver

Inherits:
Object
  • Object
show all
Defined in:
lib/nvruby/solver/lu.rb

Overview

LU Solver plan for repeated solves with the same matrix Caches the LU factorization for efficiency

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matrix) ⇒ LUSolver

Create an LU solver for the given matrix

Parameters:

  • matrix (NvArray)

    Coefficient matrix (n x n)



227
228
229
230
231
232
# File 'lib/nvruby/solver/lu.rb', line 227

def initialize(matrix)
  @matrix = matrix
  validate!
  @n = matrix.shape[0]
  factorize!
end

Instance Attribute Details

#luNvArray (readonly)

Returns LU factored matrix.

Returns:



217
218
219
# File 'lib/nvruby/solver/lu.rb', line 217

def lu
  @lu
end

#matrixNvArray (readonly)

Returns Original matrix.

Returns:



214
215
216
# File 'lib/nvruby/solver/lu.rb', line 214

def matrix
  @matrix
end

#nInteger (readonly)

Returns Matrix dimension.

Returns:

  • (Integer)

    Matrix dimension



223
224
225
# File 'lib/nvruby/solver/lu.rb', line 223

def n
  @n
end

#pivotFFI::Pointer (readonly)

Returns Pivot indices.

Returns:

  • (FFI::Pointer)

    Pivot indices



220
221
222
# File 'lib/nvruby/solver/lu.rb', line 220

def pivot
  @pivot
end

Instance Method Details

#destroy!void

This method returns an undefined value.

Release resources



244
245
246
247
248
# File 'lib/nvruby/solver/lu.rb', line 244

def destroy!
  @pivot&.free!
  @pivot = nil
  @factorized = false
end

#solve(b, trans: :none) ⇒ NvArray

Solve Ax = b using the cached factorization

Parameters:

  • b (NvArray)

    Right-hand side (n x nrhs)

  • trans (Symbol) (defaults to: :none)

    :none, :transpose, or :conjugate

Returns:



238
239
240
# File 'lib/nvruby/solver/lu.rb', line 238

def solve(b, trans: :none)
  LU.getrs(@lu, b, pivot: @pivot, trans: trans)
end