-
Notifications
You must be signed in to change notification settings - Fork 1
Abelian symmetric SVD #33
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
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
33893cf
Symmetric SVD
mtfishman 559f5bc
Merge branch 'main' into svd
mtfishman 176571e
Bump to v0.4.3
mtfishman 92cd9e4
Fix similar(::GradedUnitRange)
mtfishman dd93426
Fix a truncation bug
mtfishman 62c9b3f
Fix another truncation bug
mtfishman cb8ef44
Small cleanup
mtfishman a1e9381
Add tests, fix bugs
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 = "GradedArrays" | ||
uuid = "bc96ca6e-b7c8-4bb6-888e-c93f838762c2" | ||
authors = ["ITensor developers <[email protected]> and contributors"] | ||
version = "0.4.2" | ||
version = "0.4.3" | ||
|
||
[deps] | ||
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" | ||
|
@@ -11,6 +11,7 @@ DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f" | |
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" | ||
HalfIntegers = "f0d1745a-41c9-11e9-1dd9-e5d34d218721" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4" | ||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66" | ||
TensorProducts = "decf83d6-1968-43f4-96dc-fdb3fe15fc6d" | ||
|
@@ -24,12 +25,13 @@ GradedArraysTensorAlgebraExt = "TensorAlgebra" | |
|
||
[compat] | ||
BlockArrays = "1.6.0" | ||
BlockSparseArrays = "0.5" | ||
BlockSparseArrays = "0.5.2" | ||
Compat = "4.16.0" | ||
DerivableInterfaces = "0.4.4" | ||
FillArrays = "1.13.0" | ||
HalfIntegers = "1.6.0" | ||
LinearAlgebra = "1.10.0" | ||
MatrixAlgebraKit = "0.1.2" | ||
Random = "1.10.0" | ||
SplitApplyCombine = "1.2.3" | ||
TensorAlgebra = "0.3.2" | ||
|
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
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,75 @@ | ||
using BlockArrays: blocks | ||
using BlockSparseArrays: | ||
BlockSparseArrays, | ||
BlockSparseMatrix, | ||
BlockPermutedDiagonalAlgorithm, | ||
BlockPermutedDiagonalTruncationStrategy, | ||
diagview, | ||
eachblockaxis, | ||
mortar_axis | ||
using LinearAlgebra: Diagonal | ||
using MatrixAlgebraKit: MatrixAlgebraKit, svd_compact!, svd_full!, svd_trunc! | ||
|
||
function BlockSparseArrays.similar_output( | ||
::typeof(svd_compact!), | ||
A::GradedMatrix, | ||
s_axis::AbstractUnitRange, | ||
alg::BlockPermutedDiagonalAlgorithm, | ||
) | ||
u_axis = s_axis | ||
flx = flux(A) | ||
axs = eachblockaxis(s_axis) | ||
# TODO: Use `gradedrange` constructor. | ||
v_axis = mortar_axis( | ||
map(axs) do ax | ||
return sectorrange(dual(sector(ax)) ⊗ flx, ungrade(ax)) | ||
end, | ||
) | ||
U = similar(A, axes(A, 1), dual(u_axis)) | ||
T = real(eltype(A)) | ||
S = BlockSparseMatrix{T,Diagonal{T,Vector{T}}}(undef, (u_axis, dual(v_axis))) | ||
Vt = similar(A, v_axis, axes(A, 2)) | ||
return U, S, Vt | ||
end | ||
|
||
function BlockSparseArrays.similar_output( | ||
::typeof(svd_full!), | ||
A::GradedMatrix, | ||
s_axis::AbstractUnitRange, | ||
alg::BlockPermutedDiagonalAlgorithm, | ||
) | ||
U = similar(A, axes(A, 1), dual(s_axis)) | ||
T = real(eltype(A)) | ||
S = similar(A, T, (s_axis, axes(A, 2))) | ||
Vt = similar(A, dual(axes(A, 2)), axes(A, 2)) | ||
return U, S, Vt | ||
end | ||
|
||
const TGradedUSVᴴ = Tuple{<:GradedMatrix,<:GradedMatrix,<:GradedMatrix} | ||
|
||
function BlockSparseArrays.similar_truncate( | ||
::typeof(svd_trunc!), | ||
(U, S, Vᴴ)::TGradedUSVᴴ, | ||
strategy::BlockPermutedDiagonalTruncationStrategy, | ||
indexmask=MatrixAlgebraKit.findtruncated(diagview(S), strategy), | ||
) | ||
ax = axes(S, 1) | ||
counter = Base.Fix1(count, Base.Fix1(getindex, indexmask)) | ||
s_lengths = map(counter, blocks(ax)) | ||
s_sectors = sectors(ax) .=> s_lengths | ||
s_sectors_filtered = filter(>(0) ∘ last, s_sectors) | ||
s_axis = gradedrange(s_sectors_filtered) | ||
u_axis = s_axis | ||
flx = flux(S) | ||
axs = eachblockaxis(s_axis) | ||
# TODO: Use `gradedrange` constructor. | ||
v_axis = mortar_axis( | ||
map(axs) do ax | ||
return sectorrange(dual(sector(ax)) ⊗ flx, ungrade(ax)) | ||
end, | ||
) | ||
Ũ = similar(U, axes(U, 1), dual(u_axis)) | ||
S̃ = similar(S, u_axis, dual(v_axis)) | ||
Ṽᴴ = similar(Vᴴ, v_axis, axes(Vᴴ, 2)) | ||
return Ũ, S̃, Ṽᴴ | ||
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that this is not very general (for example it would be bad on GPU), probably it should be factored out into a
similar_diagonal_blocks
function or something like that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this is more or less why I had an original function
_similar_S
there to specialize on, since I don't think we really have the infrastructure right now to make that work.The only thing I can come up with is trying to get type inference to tell us what the output type of
initialize_output
would be on the blocktypes of the input, but that also seems somewhat brittle.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it would be nice to come up with a good code pattern for this. I think
promote_op
oninitialize_output
of the input blocktypes could be a good general fallback definition, and then we could usesimilar(a, BlockType(...))
once we define that.