The Promoted type can cause a mismatch with the runtime promotion in certain cases when combining tensors with scalar values.
The reason is, that the type promotion , somewhat unintuitively, does not promote scalars the same way as tensors, but only to the next category. So if we combine a float32 tensor with a double/float64 scalar, the result will be a float32 tensor:
import torch.*
Tensor(1f) + Tensor(1d)
// res1: Tensor[Float64] = tensor dtype=float64, shape=[], device=CPU
// 2.0000
Tensor(1f) + 1d
// res2: Tensor[Float64] = tensor dtype=float32, shape=[], device=CPU
// 2.0000
1f + Tensor(1d)
// res3: Tensor[Float64] = tensor dtype=float64, shape=[], device=CPU
// 2.0000
Tensor(1) + 1d
// res4: Tensor[Float64] = tensor dtype=float32, shape=[], device=CPU
// 2.0000
More details are in the type promotion docs. So we need a diffrent Promoted type for tensor/scalar ops, taking that into account.
The
Promotedtype can cause a mismatch with the runtime promotion in certain cases when combining tensors with scalar values.The reason is, that the type promotion , somewhat unintuitively, does not promote scalars the same way as tensors, but only to the next category. So if we combine a
float32tensor with adouble/float64scalar, the result will be afloat32tensor:More details are in the type promotion docs. So we need a diffrent
Promotedtype for tensor/scalar ops, taking that into account.