Skip to content

[ITensors] [BUG] Elementwise operations/Broadcasting bug #1668

@kmp5VT

Description

@kmp5VT

Description of bug
Broadcast does not work for elementwise operations on ITensor. This operation should also be covered by hadamard_product so maybe we should forward the operation to that function?

Minimal runnable code

julia> m = random_itensor(Index.((5,6)))
julia> m .* m

ERROR: The noncommon indices of ((dim=5|id=769), (dim=6|id=415)) and ((dim=5|id=769), (dim=6|id=415)) must be the same as the indices ((dim=5|id=769), (dim=6|id=415)).
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] compute_contraction_labels(Cis::Tuple{…}, Ais::Tuple{…}, Bis::Tuple{…})
   @ ITensors ~/.julia/packages/ITensors/VGXV2/src/indexset.jl:715
 [3] _contract!!(C::NDTensors.DenseTensor{…}, A::NDTensors.DenseTensor{…}, B::NDTensors.DenseTensor{…})
   @ ITensors ~/.julia/packages/ITensors/VGXV2/src/tensor_operations/tensor_algebra.jl:172
 [4] contract!(C::ITensor, A::ITensor, B::ITensor)
   @ ITensors ~/.julia/packages/ITensors/VGXV2/src/tensor_operations/tensor_algebra.jl:181
 [5] mul!
   @ ~/.julia/packages/ITensors/VGXV2/src/itensor.jl:1857 [inlined]
 [6] copyto!
   @ ~/.julia/packages/ITensors/VGXV2/src/broadcast.jl:470 [inlined]
 [7] copy
   @ ./broadcast.jl:897 [inlined]
 [8] materialize(bc::Base.Broadcast.Broadcasted{ITensors.ITensorStyle, Nothing, typeof(*), Tuple{ITensor, ITensor}})
   @ Base.Broadcast ./broadcast.jl:872
 [9] top-level scope
   @ ~/.julia/dev/ITensorCPD/test/runtests.jl:18
Some type information was truncated. Use `show(err)` to see complete types.

I think this might also be a bug

m .+ m
ERROR: When adding two ITensors in-place, one must be the same as the output ITensor
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] copyto!
   @ ~/.julia/packages/ITensors/VGXV2/src/broadcast.jl:308 [inlined]
 [3] copy
   @ ./broadcast.jl:897 [inlined]
 [4] materialize(bc::Base.Broadcast.Broadcasted{ITensors.ITensorStyle, Nothing, typeof(+), Tuple{ITensor, ITensor}})
   @ Base.Broadcast ./broadcast.jl:872
 [5] top-level scope
   @ ~/.julia/dev/ITensorCPD/test/runtests.jl:18

Metadata

Metadata

Assignees

No one assigned

    Labels

    ITensorsIssues or pull requests related to the `ITensors` package.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions