A generic pairwise implementation that can be reused by different ops.
| 53 | |
| 54 | /// A generic pairwise implementation that can be reused by different ops. |
| 55 | Status PairwiseExecImpl(KernelContext* ctx, const ArraySpan& input, |
| 56 | const ArrayKernelExec& scalar_exec, int64_t periods, |
| 57 | ArrayData* result) { |
| 58 | // We only compute values in the region where the input-with-offset overlaps |
| 59 | // the original input. The margin where these do not overlap gets filled with null. |
| 60 | const auto margin_length = std::min(abs(periods), input.length); |
| 61 | const auto computed_length = input.length - margin_length; |
| 62 | const auto computed_start = periods > 0 ? margin_length : 0; |
| 63 | const auto left_start = computed_start; |
| 64 | const auto right_start = margin_length - computed_start; |
| 65 | // prepare null bitmap |
| 66 | int64_t null_count = margin_length; |
| 67 | for (int64_t i = computed_start; i < computed_start + computed_length; i++) { |
| 68 | if (input.IsValid(i) && input.IsValid(i - periods)) { |
| 69 | bit_util::SetBit(result->buffers[0]->mutable_data(), i); |
| 70 | } else { |
| 71 | ++null_count; |
| 72 | } |
| 73 | } |
| 74 | result->null_count = null_count; |
| 75 | // prepare input span |
| 76 | ArraySpan left(input); |
| 77 | left.SetSlice(left_start, computed_length); |
| 78 | ArraySpan right(input); |
| 79 | right.SetSlice(right_start, computed_length); |
| 80 | // prepare output span |
| 81 | ArraySpan output_span; |
| 82 | output_span.SetMembers(*result); |
| 83 | output_span.offset = computed_start; |
| 84 | output_span.length = computed_length; |
| 85 | ExecResult output{output_span}; |
| 86 | // execute scalar function |
| 87 | RETURN_NOT_OK(scalar_exec(ctx, ExecSpan({left, right}, computed_length), &output)); |
| 88 | |
| 89 | return Status::OK(); |
| 90 | } |
| 91 | |
| 92 | Status PairwiseExec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) { |
| 93 | const auto& state = checked_cast<const PairwiseState&>(*ctx->state()); |
no test coverage detected