Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NumRuby::Linalg #30

Merged
merged 4 commits into from
Dec 2, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
lu, lu_factor, lu_solve
  • Loading branch information
Uditgulati committed Aug 26, 2019
commit 4e4daf2d24529860a598458f1edecfb330226c62
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -3,4 +3,6 @@
Gemfile.lock
/.yardoc
.rake_tasks~
*.so
*.so
.vscode

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you shouldn't add this here, you could place this in a .global-gitignore as you can see here https://gist.github.com/subfuzion/db7f57fff2fb6998a16c WDYT? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think *.so should be in .gitignore, .vscode can be shifted to .global-gitignore.


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
@@ -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.