ITensor / NDTensors.jl

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

Fix bug in scalar contract with mixed element types #58

Closed mtfishman closed 3 years ago

mtfishman commented 3 years ago

This is an extremely particular bug introduced by the recent optimizations to contractions involving scalar-like tensors. It affects contractions involving a scalar tensor with a non-scalar tensor, where the tensors have different element types. The cause of the bug is that we are using BLAS.axpby!, but in the mixed element type case, it gets dispatched to a generic Julia fallback. However, the generic Julia fallback and BLAS version handle NaN different with beta = 0. When beta = 0, BLAS overwrites the modified array with zeros, but Julia forwards the NaN. This is fixed by creating our own dispatch path for the mixed element type case.