MCPcopy Create free account
hub / github.com/apache/arrow / PairwiseExecImpl

Function PairwiseExecImpl

cpp/src/arrow/compute/kernels/vector_pairwise.cc:55–90  ·  view source on GitHub ↗

A generic pairwise implementation that can be reused by different ops.

Source from the content-addressed store, hash-verified

53
54/// A generic pairwise implementation that can be reused by different ops.
55Status 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
92Status PairwiseExec(KernelContext* ctx, const ExecSpan& batch, ExecResult* out) {
93 const auto& state = checked_cast<const PairwiseState&>(*ctx->state());

Callers 1

PairwiseExecFunction · 0.85

Calls 6

SetBitFunction · 0.85
SetMembersMethod · 0.80
ExecSpanFunction · 0.50
OKFunction · 0.50
IsValidMethod · 0.45
mutable_dataMethod · 0.45

Tested by

no test coverage detected