| 236 | |
| 237 | template <typename OptionsType> |
| 238 | Result<std::unique_ptr<KernelState>> StatisticInit( |
| 239 | StatisticType stat_type, const DataType& in_type, |
| 240 | const std::shared_ptr<DataType>& out_type, const OptionsType& options) { |
| 241 | auto make_kernel_state = [&](auto&& type, int32_t decimal_scale = 0) { |
| 242 | using Type = std::decay_t<decltype(type)>; |
| 243 | return std::unique_ptr<KernelState>( |
| 244 | new StatisticImpl<Type>(stat_type, decimal_scale, out_type, options)); |
| 245 | }; |
| 246 | |
| 247 | auto visit = [&](auto&& type) -> Result<std::unique_ptr<KernelState>> { |
| 248 | using Type = std::decay_t<decltype(type)>; |
| 249 | // Decimals |
| 250 | if constexpr (is_decimal_type<Type>::value) { |
| 251 | return make_kernel_state(type, type.scale()); |
| 252 | } |
| 253 | // Numbers (except half-float) |
| 254 | if constexpr (is_number_type<Type>::value && !is_half_float_type<Type>::value) { |
| 255 | return make_kernel_state(type); |
| 256 | } |
| 257 | return Status::NotImplemented("No variance/stddev implemented for ", |
| 258 | in_type.ToString()); |
| 259 | }; |
| 260 | return VisitType(in_type, visit); |
| 261 | } |
| 262 | |
| 263 | template <typename OptionsType, StatisticType kStatType> |
| 264 | Result<std::unique_ptr<KernelState>> StatisticInit(KernelContext* ctx, |