-
Notifications
You must be signed in to change notification settings - Fork 4
Incremental fixes for MPSKit #54
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
Changes from all commits
fe37211
9349bb7
dcb2294
677d141
f03b5d2
c0fe19c
b7518f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,11 +25,10 @@ for f! in ( | |
| ) | ||
| @eval function MAK.$f!(t::AbstractBlockTensorMap, F, alg::AbstractAlgorithm) | ||
| TensorKit.foreachblock(t, F...) do _, (tblock, Fblocks...) | ||
| dense_block = similar_dense(tblock) | ||
| Fblocks′ = MAK.$f!(copy_dense!(dense_block, tblock), alg) | ||
| Fblocks′ = MAK.$f!(copy_dense!(similar_dense(tblock), tblock), alg) | ||
| # deal with the case where the output is not in-place | ||
| for (b′, b) in zip(Fblocks′, Fblocks) | ||
| b === b′ || copy!(b, b′) | ||
| b === b′ || copyto!(b, b′) | ||
| end | ||
| return nothing | ||
| end | ||
|
|
@@ -45,10 +44,9 @@ for f! in ( | |
| ) | ||
| @eval function MAK.$f!(t::AbstractBlockTensorMap, N, alg::AbstractAlgorithm) | ||
| TensorKit.foreachblock(t, N) do _, (tblock, Nblock) | ||
| dense_block = similar_dense(tblock) | ||
| Nblock′ = MAK.$f!(copy_dense!(dense_block, tblock), alg) | ||
| Nblock′ = MAK.$f!(copy_dense!(similar_dense(tblock), tblock), alg) | ||
| # deal with the case where the output is not the same as the input | ||
| Nblock === Nblock′ || copy!(Nblock, Nblock′) | ||
| Nblock === Nblock′ || copyto!(Nblock, Nblock′) | ||
| return nothing | ||
| end | ||
| return N | ||
|
|
@@ -190,3 +188,30 @@ for f! in ( | |
| @eval MAK.$f!(::AbstractBlockTensorMap, x, ::DiagonalAlgorithm) = | ||
| error("Blocktensors are incompatible with diagonal algorithm") | ||
| end | ||
|
|
||
| function TensorKit.Factorizations.truncate_domain!(tdst::AbstractBlockTensorMap, tsrc::AbstractBlockTensorMap, inds) | ||
| TensorKit.foreachblock(tdst, tsrc) do c, (dst_block, src_block) | ||
| I = get(inds, c, nothing) | ||
| dst_dense = copy_dense!(similar_dense(dst_block), dst_block) | ||
| src_dense = copy_dense!(similar_dense(src_block), src_block) | ||
| @assert !isnothing(I) | ||
| @views dst_dense .= src_dense[:, I] | ||
| # deal with the case where the output is not in-place | ||
| dst_dense === dst_block || copyto!(dst_block, dst_dense) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity, is this ever in-place?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess in theory, it could be? For now I agree it's always out of place |
||
| return nothing | ||
| end | ||
| return tdst | ||
| end | ||
| function TensorKit.Factorizations.truncate_codomain!(tdst::AbstractBlockTensorMap, tsrc::AbstractBlockTensorMap, inds) | ||
| TensorKit.foreachblock(tdst, tsrc) do c, (dst_block, src_block) | ||
| I = get(inds, c, nothing) | ||
| dst_dense = copy_dense!(similar_dense(dst_block), dst_block) | ||
| src_dense = copy_dense!(similar_dense(src_block), src_block) | ||
| @assert !isnothing(I) | ||
| @views dst_dense .= src_dense[I, :] | ||
| # deal with the case where the output is not in-place | ||
| dst_dense === dst_block || copyto!(dst_block, dst_dense) | ||
| return nothing | ||
| end | ||
| return tdst | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -288,7 +288,7 @@ function similar_tensormaptype( | |
| ) where {S} | ||
| if eltype(t) === T && typeof(space(t)) === typeof(P) | ||
| return T | ||
| elseif isconcretetype(T) | ||
| elseif isconcretetype(T) || T isa Union | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! this is probably already solving a lot of issues? |
||
| return tensormaptype(S, numout(P), numin(P), storagetype(T)) | ||
| else | ||
| return AbstractTensorMap{scalartype(T), S, numout(P), numin(P)} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.