#define TORCH_ASSERT_ONLY_METHOD_OPERATORS #include #include #include #include namespace at { namespace { template inline void fill_inplace(Tensor& self, const Scalar& value_scalar) { auto value = value_scalar.to(); scalar_t* dptr = static_cast(self.data_ptr()); *dptr = value; } } namespace detail { Tensor& scalar_fill(Tensor& self, const Scalar& value) { AT_DISPATCH_V2( self.scalar_type(), "fill_out", AT_WRAP([&]() { fill_inplace(self, value); }), kComplexHalf, kHalf, kBool, kBFloat16, AT_EXPAND(AT_ALL_TYPES_AND_COMPLEX), AT_EXPAND(AT_BAREBONES_UNSIGNED_TYPES)); return self; } Tensor scalar_tensor_static(const Scalar& s, std::optional dtype_opt, std::optional device_opt) { at::tracer::impl::NoTracerDispatchMode tracer_guard; at::AutoDispatchBelowAutograd mode; Tensor result = at::detail::empty_cpu( {}, dtype_opt, std::nullopt, device_opt, std::nullopt, std::nullopt); scalar_fill(result, s); return result; } } // namespace detail } // namespace at