ITensor / NDTensors.jl

A Julia package for n-dimensional sparse tensors.
Apache License 2.0
27 stars 7 forks source link

Contracting DiagTensor with DenseTensor may be a bit slow #41

Open mtfishman opened 3 years ago

mtfishman commented 3 years ago

I noticed when comparing CTMRG benchmarks in ITensors.jl to C++ ITensor, ITensors.jl is a bit slower (maybe by 20% with no BLAS threading). Based on profiling, it looks like the contraction between DiagTensor and DenseTensor is probably the culprit.

mtfishman commented 3 years ago

Something to consider is having a specialized version for contract(::DiagTensor, ::DenseTensor) for cases when the diagonal tensor is order-2, and only contracts one index with the dense tensor, i.e.:

        /       /
---D---T  = ---R
        \       \

This type of contraction could be treated directly as a diagonal matrix-dense matrix multiplication, where we could make a special optimized algorithm (or try out Julia's Diagonal * Matrix operation).

mtfishman commented 3 years ago

Also another data point: in CTMRG, right now it is faster to convert the diagonal tensor to dense, and then do a dense-dense tensor contraction. So a concrete goal would be to make the diag-dense contraction faster than converting to dense.