ITensor / NDTensors.jl

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

Speed up very small tensor contractions a little bit #34

Closed mtfishman closed 4 years ago

mtfishman commented 4 years ago

This implements #32, which speeds up very small tensor contractions a little bit by using Base.ReshapedArray instead of the reshape function in the Dense contract! function. It is only noticeable for contractions of matrices with dimensions of less than 20, i.e. running:

using ITensors

d = 5

a = randn(d, d)
b = randn(d, d)
c = randn(d, d)

i = Index(d)
A = itensor(a, i, i')
B = itensor(b, i', i'')
C = itensor(c, i, i'')

it = @belapsed $C .= $A .* $B
mm = @belapsed mul!($c, $a, $b)
@show it / mm

on the latest version of NDTensors gives:

it / mm = 3.7810970267495194

while on this branch it gives:

it / mm = 3.143474129969966

Nothing amazing, but also a good sign that something like that even shows up in the timings.