| 100 | } |
| 101 | |
| 102 | Status Finalize(KernelContext* ctx, Datum* out) override { |
| 103 | const int64_t out_length = options.q.size(); |
| 104 | auto out_data = ArrayData::Make(float64(), out_length, 0); |
| 105 | out_data->buffers.resize(2, nullptr); |
| 106 | ARROW_ASSIGN_OR_RAISE(out_data->buffers[1], |
| 107 | ctx->Allocate(out_length * sizeof(double))); |
| 108 | double* out_buffer = out_data->template GetMutableValues<double>(1); |
| 109 | |
| 110 | if (this->tdigest.is_empty() || !this->all_valid || this->count < options.min_count) { |
| 111 | ARROW_ASSIGN_OR_RAISE(out_data->buffers[0], ctx->AllocateBitmap(out_length)); |
| 112 | std::memset(out_data->buffers[0]->mutable_data(), 0x00, |
| 113 | out_data->buffers[0]->size()); |
| 114 | std::fill(out_buffer, out_buffer + out_length, 0.0); |
| 115 | out_data->null_count = out_length; |
| 116 | } else { |
| 117 | for (int64_t i = 0; i < out_length; ++i) { |
| 118 | out_buffer[i] = this->tdigest.Quantile(this->options.q[i]); |
| 119 | } |
| 120 | } |
| 121 | *out = Datum(std::move(out_data)); |
| 122 | return Status::OK(); |
| 123 | } |
| 124 | |
| 125 | const TDigestOptions options; |
| 126 | TDigest tdigest; |
no test coverage detected