2 #include <ATen/NativeFunctions.h> 7 Scalar item(
const Tensor&
self) {
8 int64_t numel =
self.numel();
9 AT_CHECK(numel == 1,
"a Tensor with ", numel,
" elements cannot be converted to Scalar");
10 if (
self.is_sparse()) {
11 if (
self._nnz() == 0)
return Scalar(0);
12 if (
self.is_coalesced())
return at::_local_scalar_dense(
self._values());
13 return at::_local_scalar_dense(
self._values().sum());
15 return _local_scalar_dense(
self);
19 Scalar _local_scalar_dense_cpu(
const Tensor&
self) {
21 AT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND(
22 at::ScalarType::Half, at::ScalarType::Bool,
self.scalar_type(),
"_local_scalar_dense_cpu", [&] {
23 scalar_t value = *
self.data<scalar_t>();
Flush-To-Zero and Denormals-Are-Zero mode.