Skip to content

Commit

Permalink
lu, lu_factor, lu_solve
Browse files Browse the repository at this point in the history
  • Loading branch information
Uditgulati committed Aug 26, 2019
1 parent 5569f62 commit 4e4daf2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
Gemfile.lock
/.yardoc
.rake_tasks~
*.so
*.so
.vscode

16 changes: 0 additions & 16 deletions .vscode/c_cpp_properties.json

This file was deleted.

30 changes: 28 additions & 2 deletions lib/nmatrix/lapack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,42 @@ def self.eigvalsh
# Matrix Decomposition


def self.lu(matrix)
def self.lu(matrix, permute_l: False)
if not matrix.is_a?(NMatrix)
raise("Invalid matrix. Not of type NMatrix.")
end
if matrix.dim != 2
raise("Invalid shape of matrix. Should be 2.")
end

lu, ipiv = NumRuby::Linalg.getrf(matrix)

# TODO: calulate p, l, u
end

def self.lu_factor(matrix)
if not matrix.is_a?(NMatrix)
raise("Invalid matrix. Not of type NMatrix.")
end
if matrix.dim != 2
raise("Invalid shape of matrix. Should be 2.")
end
if matrix.shape[0] != matrix.shape[1]
raise("Invalid shape. Expected square matrix.")
end

lu, ipiv = NumRuby::Linalg.getrf(matrix)

return [lu, ipiv]
end

def self.lu_solve(matrix, rhs_val)
def self.lu_solve(lu, ipiv, b, trans: 0)
if lu.shape[0] != b.shape[0]
raise("Incompatibel dimensions.")
end

x = NumRuby::Lapack.getrs(lu, ipiv, b, trans)
return x
end

# Computes the SVD decomposition of matrix.
Expand Down

0 comments on commit 4e4daf2

Please sign in to comment.