Skip to content

Commit

Permalink
Fix some issues with Adjoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Nov 8, 2024
1 parent 1701179 commit bba49b3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function Base.show(
io::IO, mime::MIME"text/plain", a::Adjoint{<:Any,<:BlockSparseMatrix}; kwargs...
)
axes_a = axes(a)
a_nondual = BlockSparseArray(blocks(a'), dual.(nondual.(axes(a))))'
a_nondual = BlockSparseArray(blocks(a'), dual.(nondual.(axes(a'))))'
return blocksparse_show(io, mime, a_nondual, axes_a; kwargs...)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include("abstractblocksparsearray/arraylayouts.jl")
include("abstractblocksparsearray/sparsearrayinterface.jl")
include("abstractblocksparsearray/broadcast.jl")
include("abstractblocksparsearray/map.jl")
include("abstractblocksparsearray/linearalgebra.jl")
include("blocksparsearray/defaults.jl")
include("blocksparsearray/blocksparsearray.jl")
include("BlockArraysSparseArrayInterfaceExt/BlockArraysSparseArrayInterfaceExt.jl")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using LinearAlgebra: Adjoint, Transpose

# Like: https://github.com/JuliaLang/julia/blob/v1.11.1/stdlib/LinearAlgebra/src/transpose.jl#L184
# but also takes the dual of the axes.
# Fixes an issue raised in:
# https://github.com/ITensor/ITensors.jl/issues/1336#issuecomment-2353434147
function Base.copy(a::Adjoint{T,<:AbstractBlockSparseMatrix{T}}) where {T}
a_dest = similar(parent(a), axes(a))
a_dest .= a
return a_dest
end

# More efficient than the generic `LinearAlgebra` version.
function Base.copy(a::Transpose{T,<:AbstractBlockSparseMatrix{T}}) where {T}
a_dest = similar(parent(a), axes(a))
a_dest .= a
return a_dest
end

0 comments on commit bba49b3

Please sign in to comment.