-
Notifications
You must be signed in to change notification settings - Fork 2
More matrix factorizations #52
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
16aca55
More matrix factorizations
mtfishman 14c971d
More matrix factorizations
mtfishman e1edd71
Simplifications based on Lukas's comments
mtfishman 9e02367
Update export list
mtfishman e68a135
Exports
mtfishman 94aad1d
Add tests for TensorAlgebra.MatrixAlgebra
mtfishman 89c8d33
Add missing import
mtfishman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "TensorAlgebra" | ||
uuid = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a" | ||
authors = ["ITensor developers <[email protected]> and contributors"] | ||
version = "0.2.9" | ||
version = "0.2.10" | ||
|
||
[deps] | ||
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
module MatrixAlgebra | ||
|
||
using LinearAlgebra: LinearAlgebra | ||
using MatrixAlgebraKit: | ||
eig_full, | ||
eig_full!, | ||
eig_trunc, | ||
eig_trunc!, | ||
eig_vals, | ||
eig_vals!, | ||
eigh_full, | ||
eigh_full!, | ||
eigh_trunc, | ||
eigh_trunc!, | ||
eigh_vals, | ||
eigh_vals!, | ||
left_orth, | ||
left_orth!, | ||
left_polar, | ||
left_polar!, | ||
lq_full, | ||
lq_full!, | ||
lq_compact, | ||
lq_compact!, | ||
qr_full, | ||
qr_full!, | ||
qr_compact, | ||
qr_compact!, | ||
right_orth, | ||
right_orth!, | ||
right_polar, | ||
right_polar!, | ||
svd_full, | ||
svd_full!, | ||
svd_compact, | ||
svd_compact!, | ||
svd_trunc, | ||
svd_trunc! | ||
|
||
for (f, f_full, f_compact) in ( | ||
(:qr, :qr_full, :qr_compact), | ||
(:qr!, :qr_full!, :qr_compact!), | ||
(:lq, :lq_full, :lq_compact), | ||
(:lq!, :lq_full!, :lq_compact!), | ||
) | ||
@eval begin | ||
function $f(A::AbstractMatrix; full::Bool=false, kwargs...) | ||
f = full ? $f_full : $f_compact | ||
return f(A; kwargs...) | ||
end | ||
end | ||
end | ||
|
||
for (eigen, eigh_full, eig_full, eigh_trunc, eig_trunc) in ( | ||
(:eigen, :eigh_full, :eig_full, :eigh_trunc, :eig_trunc), | ||
(:eigen!, :eigh_full!, :eig_full!, :eigh_trunc!, :eig_trunc!), | ||
) | ||
@eval begin | ||
function $eigen(A::AbstractMatrix; trunc=nothing, ishermitian=nothing, kwargs...) | ||
ishermitian = @something ishermitian LinearAlgebra.ishermitian(A) | ||
f = if !isnothing(trunc) | ||
ishermitian ? $eigh_trunc : $eig_trunc | ||
else | ||
ishermitian ? $eigh_full : $eig_full | ||
end | ||
return f(A; kwargs...) | ||
end | ||
end | ||
end | ||
|
||
for (eigvals, eigh_vals, eig_vals) in | ||
((:eigvals, :eigh_vals, :eig_vals), (:eigvals!, :eigh_vals!, :eig_vals!)) | ||
@eval begin | ||
function $eigvals(A::AbstractMatrix; ishermitian=nothing, kwargs...) | ||
ishermitian = @something ishermitian LinearAlgebra.ishermitian(A) | ||
f = (ishermitian ? $eigh_vals : $eig_vals) | ||
return f(A; kwargs...) | ||
end | ||
end | ||
end | ||
|
||
for (svd, svd_trunc, svd_full, svd_compact) in ( | ||
(:svd, :svd_trunc, :svd_full, :svd_compact), | ||
(:svd!, :svd_trunc!, :svd_full!, :svd_compact!), | ||
) | ||
@eval begin | ||
function $svd(A::AbstractMatrix; full::Bool=false, trunc=nothing, kwargs...) | ||
return if !isnothing(trunc) | ||
@assert !full "Specified both full and truncation, currently not supported" | ||
$svd_trunc(A; trunc, kwargs...) | ||
else | ||
(full ? $svd_full : $svd_compact)(A; kwargs...) | ||
end | ||
end | ||
end | ||
end | ||
|
||
for (polar, left_polar, right_polar) in | ||
((:polar, :left_polar, :right_polar), (:polar!, :left_polar!, :right_polar!)) | ||
@eval begin | ||
function $polar(A::AbstractMatrix; side=:left, kwargs...) | ||
f = if side == :left | ||
$left_polar | ||
elseif side == :right | ||
$right_polar | ||
else | ||
throw(ArgumentError("`side=$side` not supported.")) | ||
end | ||
return f(A; kwargs...) | ||
end | ||
end | ||
end | ||
|
||
for (orth, left_orth, right_orth) in | ||
((:orth, :left_orth, :right_orth), (:orth!, :left_orth!, :right_orth!)) | ||
@eval begin | ||
function $orth(A::AbstractMatrix; side=:left, kwargs...) | ||
f = if side == :left | ||
$left_orth | ||
elseif side == :right | ||
$right_orth | ||
else | ||
throw(ArgumentError("`side=$side` not supported.")) | ||
end | ||
return f(A; kwargs...) | ||
end | ||
end | ||
end | ||
|
||
for (factorize, orth_f) in ((:factorize, :(MatrixAlgebra.orth)), (:factorize!, :orth!)) | ||
@eval begin | ||
function $factorize(A::AbstractMatrix; orth=:left, kwargs...) | ||
f = if orth in (:left, :right) | ||
$orth_f | ||
else | ||
throw(ArgumentError("`orth=$orth` not supported.")) | ||
end | ||
return f(A; kwargs...) | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.