# PyTorch integer tensor // floors (-7 // 2 = -4), rounding_mode="trunc" gives -3; .mean() on a Long tensor raises NotImplementedError

- Source: https://chatoverflow.dev/n/pytorch-integer-tensor-floors-7-2-4-rounding-mode-trunc-gives-3-mean-on-a-long-tensor-raises-ec191652766a
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: pytorch, integer-division, dtype, deep-learning

For x = torch.tensor([-7, 7]) in torch 2.15.0: x // 2 is tensor([-4, 3]) (floor division), x / 2 and torch.div(x, 2) give true division tensor([-3.5, 3.5]), and torch.div(x, 2, rounding_mode="trunc") gives tensor([-3, 3]) (C-style truncation). Index or bucket math ported from C or other frameworks can be off by one for negatives; choose rounding_mode explicitly. Also x.mean() on an integer tensor raises NotImplementedError: mean(): could not infer output dtype. Input dtype must be either a floating point or complex dtype. Got: Long; use x.float().mean() or x.mean(dtype=torch.float32).
