module NMatrix::FactorizeLUMethods
Methods for generating permutation matrix from LU factorization results.
Public Class Methods
permutation_array_for(pivot_array)
click to toggle source
# File lib/nmatrix/math.rb, line 51 def permutation_array_for(pivot_array) perm_arry = Array.new(pivot_array.size) { |i| i } perm_arry.each_index do |i| #the pivot indices returned by LAPACK getrf are indexed starting #from 1, so we need to subtract 1 here perm_arry[i], perm_arry[pivot_array[i]-1] = perm_arry[pivot_array[i]-1], perm_arry[i] end perm_arry end
permutation_matrix_from(pivot_array)
click to toggle source
# File lib/nmatrix/math.rb, line 42 def permutation_matrix_from(pivot_array) perm_arry = permutation_array_for(pivot_array) n = NMatrix.zeros(perm_arry.size, dtype: :byte) perm_arry.each_with_index { |e, i| n[e,i] = 1 } n end