Not Implemented Error in Diagonal ITensor Contraction

I encountered a ‘not implemented’ error when trying to contract a diagonal tensor with a delta tensor. I generally prefer using A*delta(i,j) to replace tensor indices, rather than replacind(A,i,j). However, I noticed that when A is a diagonal tensor—such as the S matrix from an svd decomposition—the contraction A*delta(i,j) results in an error, whereas replacind(A,i,j) works as expected.

I’m wondering if this is a bug or an intentional feature of diagonal ITensors.

Here is a minimal example code.

using ITensors

i, j, k = Index(4, "i"), Index(4, "j"), Index(4, "k")
D = diag_itensor(1., i, j)
@show D * delta(j, k)

The error information is

ERROR: Not implemented
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] datatype(::Type{NDTensors.Diag{Float64}})
    @ NDTensors ~/.julia/packages/NDTensors/F4sTz/src/tensorstorage/tensorstorage.jl:7
  [3] similartype(storagetype::Type{NDTensors.Diag{Float64}}, dims::Tuple{Index{Int64}, Index{Int64}})
    @ NDTensors ~/.julia/packages/NDTensors/F4sTz/src/tensorstorage/similar.jl:79
  [4] similartype(tensortype::Type{NDTensors.DiagTensor{…}}, dims::Tuple{Index{…}, Index{…}})
    @ NDTensors ~/.julia/packages/NDTensors/F4sTz/src/tensor/similar.jl:69
  [5] contraction_output_type(tensortype1::Type{…}, tensortype2::Type{…}, indsR::Tuple{…})
    @ NDTensors ~/.julia/packages/NDTensors/F4sTz/src/diag/tensoralgebra/contract.jl:28
  [6] zero_contraction_output(T1::NDTensors.DiagTensor{…}, T2::NDTensors.DiagTensor{…}, indsR::Tuple{…})
    @ NDTensors ~/.julia/packages/NDTensors/F4sTz/src/tensor/tensor.jl:461
  [7] contraction_output(T1::NDTensors.DiagTensor{…}, T2::NDTensors.DiagTensor{…}, indsR::Tuple{…})
    @ NDTensors ~/.julia/packages/NDTensors/F4sTz/src/diag/tensoralgebra/contract.jl:38
  [8] contraction_output(tensor1::NDTensors.DiagTensor{…}, labelstensor1::Tuple{…}, tensor2::NDTensors.DiagTensor{…}, labelstensor2::Tuple{…}, labelsoutput_tensor::Tuple{…})
    @ NDTensors ~/.julia/packages/NDTensors/F4sTz/src/tensoroperations/generic_tensor_operations.jl:62
  [9] contract(tensor1::NDTensors.DiagTensor{…}, labelstensor1::Tuple{…}, tensor2::NDTensors.DiagTensor{…}, labelstensor2::Tuple{…}, labelsoutput_tensor::Tuple{…})
    @ NDTensors ~/.julia/packages/NDTensors/F4sTz/src/tensoroperations/generic_tensor_operations.jl:108
 [10] contract(::Type{…}, tensor1::NDTensors.DiagTensor{…}, labels_tensor1::Tuple{…}, tensor2::NDTensors.DiagTensor{…}, labels_tensor2::Tuple{…})
    @ NDTensors ~/.julia/packages/NDTensors/F4sTz/src/tensoroperations/generic_tensor_operations.jl:91
 [11] contract
    @ ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:331 [inlined]
 [12] _contract(A::NDTensors.DiagTensor{…}, B::NDTensors.DiagTensor{…})
    @ ITensors ~/.julia/packages/ITensors/KvHvB/src/tensor_operations/tensor_algebra.jl:3
 [13] _contract(A::ITensor, B::ITensor)
    @ ITensors ~/.julia/packages/ITensors/KvHvB/src/tensor_operations/tensor_algebra.jl:9
 [14] contract(A::ITensor, B::ITensor)
    @ ITensors ~/.julia/packages/ITensors/KvHvB/src/tensor_operations/tensor_algebra.jl:74
 [15] *(A::ITensor, B::ITensor)
    @ ITensors ~/.julia/packages/ITensors/KvHvB/src/tensor_operations/tensor_algebra.jl:61
 [16] macro expansion
    @ show.jl:1232 [inlined]
 [17] top-level scope
    @ REPL[38]:1
Some type information was truncated. Use `show(err)` to see complete types.

here is the environment info

julia> versioninfo()
Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

and the ITensors version info

julia> using Pkg; Pkg.status("ITensors")
Status `~/.julia/environments/v1.11/Project.toml`
  [9136182c] ITensors v0.7.11