Skip to content

Commit bba49b3

Browse files
committed
Fix some issues with Adjoint
1 parent 1701179 commit bba49b3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/src/BlockSparseArraysGradedAxesExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function Base.show(
138138
io::IO, mime::MIME"text/plain", a::Adjoint{<:Any,<:BlockSparseMatrix}; kwargs...
139139
)
140140
axes_a = axes(a)
141-
a_nondual = BlockSparseArray(blocks(a'), dual.(nondual.(axes(a))))'
141+
a_nondual = BlockSparseArray(blocks(a'), dual.(nondual.(axes(a'))))'
142142
return blocksparse_show(io, mime, a_nondual, axes_a; kwargs...)
143143
end
144144

NDTensors/src/lib/BlockSparseArrays/src/BlockSparseArrays.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ include("abstractblocksparsearray/arraylayouts.jl")
1616
include("abstractblocksparsearray/sparsearrayinterface.jl")
1717
include("abstractblocksparsearray/broadcast.jl")
1818
include("abstractblocksparsearray/map.jl")
19+
include("abstractblocksparsearray/linearalgebra.jl")
1920
include("blocksparsearray/defaults.jl")
2021
include("blocksparsearray/blocksparsearray.jl")
2122
include("BlockArraysSparseArrayInterfaceExt/BlockArraysSparseArrayInterfaceExt.jl")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using LinearAlgebra: Adjoint, Transpose
2+
3+
# Like: https://github.com/JuliaLang/julia/blob/v1.11.1/stdlib/LinearAlgebra/src/transpose.jl#L184
4+
# but also takes the dual of the axes.
5+
# Fixes an issue raised in:
6+
# https://github.com/ITensor/ITensors.jl/issues/1336#issuecomment-2353434147
7+
function Base.copy(a::Adjoint{T,<:AbstractBlockSparseMatrix{T}}) where {T}
8+
a_dest = similar(parent(a), axes(a))
9+
a_dest .= a
10+
return a_dest
11+
end
12+
13+
# More efficient than the generic `LinearAlgebra` version.
14+
function Base.copy(a::Transpose{T,<:AbstractBlockSparseMatrix{T}}) where {T}
15+
a_dest = similar(parent(a), axes(a))
16+
a_dest .= a
17+
return a_dest
18+
end

0 commit comments

Comments
 (0)