diff --git a/Project.toml b/Project.toml index 633566a..d1519b1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "TensorAlgebra" uuid = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a" -version = "0.11.0" +version = "0.11.1" authors = ["ITensor developers and contributors"] [workspace] diff --git a/src/matricize.jl b/src/matricize.jl index 6930fc4..4e28422 100644 --- a/src/matricize.jl +++ b/src/matricize.jl @@ -339,8 +339,17 @@ function unmatricizeadd!( invperm_codomain::Tuple{Vararg{Int}}, invperm_domain::Tuple{Vararg{Int}}, α::Number, β::Number ) - a = unmatricize(style, m, axes(a_dest), invperm_codomain, invperm_domain) - return add!(a_dest, a, α, β) + invbiperm = BiTuple(invperm_codomain, invperm_domain) + ndims(a_dest) == length(invbiperm) || + throw(ArgumentError("destination does not match permutation")) + # Reshape `m` to the destination's matricized axes (a view), then permute it + # straight into `a_dest` with accumulation in a single pass, rather than + # allocating a permuted copy and then adding it. Mirrors `unmatricize!`. + a_perm = unmatricize(style, m, bipartition(axes(a_dest), invbiperm)...) + biperm_dest = BiTuple(Tuple(invperm(invbiperm)), Val(length_codomain(axes(a_dest)))) + return bipermutedimsopadd!( + a_dest, identity, a_perm, biperm_dest.t1, biperm_dest.t2, α, β + ) end # Defaults to ReshapeFusion, a simple reshape