| 198 | } |
| 199 | |
| 200 | Status Finalize(KernelContext*, Datum* out) override { |
| 201 | if (state.count() <= ddof || state.count() < min_count || |
| 202 | (!state.all_valid && !skip_nulls) || |
| 203 | (stat_type == StatisticType::Skew && !biased && state.count() < 3) || |
| 204 | (stat_type == StatisticType::Kurtosis && !biased && state.count() < 4)) { |
| 205 | out->value = std::make_shared<DoubleScalar>(); |
| 206 | } else { |
| 207 | switch (stat_type) { |
| 208 | case StatisticType::Std: |
| 209 | out->value = std::make_shared<DoubleScalar>(state.moments.Stddev(ddof)); |
| 210 | break; |
| 211 | case StatisticType::Var: |
| 212 | out->value = std::make_shared<DoubleScalar>(state.moments.Variance(ddof)); |
| 213 | break; |
| 214 | case StatisticType::Skew: |
| 215 | out->value = std::make_shared<DoubleScalar>(state.moments.Skew(biased)); |
| 216 | break; |
| 217 | case StatisticType::Kurtosis: |
| 218 | out->value = std::make_shared<DoubleScalar>(state.moments.Kurtosis(biased)); |
| 219 | break; |
| 220 | default: |
| 221 | return Status::NotImplemented("Unsupported statistic type ", |
| 222 | static_cast<int>(stat_type)); |
| 223 | } |
| 224 | } |
| 225 | return Status::OK(); |
| 226 | } |
| 227 | |
| 228 | std::shared_ptr<DataType> out_type; |
| 229 | StatisticType stat_type; |