|
1 | | -const BlockTensorOrAdjoint = Union{AbstractBlockTensorMap, AdjointBlockTensorMap} |
2 | | - |
3 | 1 | # permute!, braid!, tensoradd!, permute_twist! |
4 | 2 | # -------------------------------------------- |
5 | 3 | # these all unwrap adjoints and then call `_braid!` |
|
59 | 57 |
|
60 | 58 | # transpose! |
61 | 59 | # ---------- |
62 | | -function TK.transpose!( |
63 | | - tdst::BlockTensorMap, tsrc::BlockTensorMap, p::Index2Tuple, |
64 | | - α::Number, β::Number, backend::AbstractBackend, allocator |
| 60 | +# this unwraps adjoints and then calls `_transpose!` |
| 61 | + |
| 62 | +@propagate_inbounds function _transpose_block!(tdst, tsrc, p, conjsrc, α, β, backend, allocator) |
| 63 | + tsrc′, p′, _, conjsrc′ = TK._unwrap_source(tsrc, p, nothing, conjsrc) |
| 64 | + return TK._transpose!(tdst, tsrc′, p′, conjsrc′, α, β, backend, allocator) |
| 65 | +end |
| 66 | +# no `twistmask` here, so the blocks of a `tdst'` can be unwrapped too, returning the block itself |
| 67 | +@propagate_inbounds function _transpose_block!( |
| 68 | + tdst::AdjointTensorMap, tsrc, p, conjsrc, α, β, backend, allocator |
65 | 69 | ) |
66 | | - @boundscheck TK.spacecheck_transform(TK.transpose, space(tdst), space(tsrc), p) |
| 70 | + tdst′, p′, conjsrc′, α′, β′ = TK._unwrap_destination(tdst, p, conjsrc, α, β) |
| 71 | + _transpose_block!(tdst′, tsrc, p′, conjsrc′, α′, β′, backend, allocator) |
| 72 | + return tdst |
| 73 | +end |
67 | 74 |
|
| 75 | +@propagate_inbounds function TK._transpose!( |
| 76 | + tdst::BlockTensorMap, tsrc::BlockTensorMap, p::Index2Tuple, conjsrc::Bool, |
| 77 | + α, β, backend, allocator |
| 78 | + ) |
| 79 | + @boundscheck TK.spacecheck_transform(TK.permute, space(tdst), space(tsrc), p, conjsrc) |
68 | 80 | dstdata = parent(tdst) |
69 | 81 | srcdata = permutedims(StridedView(parent(tsrc)), (p[1]..., p[2]...)) |
70 | | - |
71 | 82 | @inbounds for I in eachindex(dstdata, srcdata) |
72 | | - dstdata[I] = TK.transpose!(dstdata[I], srcdata[I], p, α, β, backend, allocator) |
| 83 | + dstdata[I] = _transpose_block!(dstdata[I], srcdata[I], p, conjsrc, α, β, backend, allocator) |
73 | 84 | end |
74 | 85 | return tdst |
75 | 86 | end |
76 | | -function TK.transpose!( |
77 | | - tdst::AbstractBlockTensorMap, tsrc::BlockTensorOrAdjoint, |
78 | | - p::Index2Tuple, α::Number, β::Number, backend::AbstractBackend, allocator |
| 87 | +@propagate_inbounds function TK._transpose!( |
| 88 | + tdst::AbstractBlockTensorMap, tsrc::AbstractBlockTensorMap, p::Index2Tuple, conjsrc::Bool, |
| 89 | + α, β, backend, allocator |
79 | 90 | ) |
80 | | - @boundscheck TK.spacecheck_transform(TK.transpose, space(tdst), space(tsrc), p) |
| 91 | + @boundscheck TK.spacecheck_transform(TK.permute, space(tdst), space(tsrc), p, conjsrc) |
81 | 92 | p_lin = (p[1]..., p[2]...) |
82 | 93 | _scale_untouched!(tdst, tsrc, β, p_lin) |
83 | 94 | @inbounds for (I, v) in nonzero_pairs(tsrc) |
84 | 95 | I′ = CartesianIndex(TT.getindices(I.I, p_lin)) |
85 | 96 | _addblock!(tdst, I′, β, allocator) do c, γ |
86 | | - TK.transpose!(c, v, p, α, γ, backend, allocator) |
| 97 | + # `@inbounds` doesn't reach into this closure |
| 98 | + @inbounds _transpose_block!(c, v, p, conjsrc, α, γ, backend, allocator) |
87 | 99 | end |
88 | 100 | end |
89 | 101 | return tdst |
90 | 102 | end |
91 | | -function TK.transpose!( |
92 | | - tdst::TensorMap, tsrc::BlockTensorMap, p::Index2Tuple, |
93 | | - α::Number, β::Number, backend::AbstractBackend, allocator |
| 103 | +# a block tensor holding a single block is interchangeable with that block |
| 104 | +@propagate_inbounds function TK._transpose!( |
| 105 | + tdst::TensorMap, tsrc::BlockTensorMap, p::Index2Tuple, conjsrc::Bool, |
| 106 | + α, β, backend, allocator |
94 | 107 | ) |
95 | | - return TK.transpose!(tdst, only(tsrc), p, α, β, backend, allocator) |
| 108 | + return _transpose_block!(tdst, only(tsrc), p, conjsrc, α, β, backend, allocator) |
96 | 109 | end |
97 | | -function TK.transpose!( |
98 | | - tdst::BlockTensorMap, tsrc::TensorMap, p::Index2Tuple, |
99 | | - α::Number, β::Number, backend::AbstractBackend, allocator |
| 110 | +@propagate_inbounds function TK._transpose!( |
| 111 | + tdst::BlockTensorMap, tsrc::TensorMap, p::Index2Tuple, conjsrc::Bool, |
| 112 | + α, β, backend, allocator |
100 | 113 | ) |
101 | | - TK.transpose!(only(tdst), tsrc, p, α, β, backend, allocator) |
| 114 | + TK._transpose!(only(tdst), tsrc, p, conjsrc, α, β, backend, allocator) |
102 | 115 | return tdst |
103 | 116 | end |
104 | 117 |
|
|
0 commit comments