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

Function ValidateTakeXAImpl

cpp/src/arrow/compute/kernels/vector_selection_test.cc:1382–1415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1380
1381template <typename ValuesType, typename IndexType>
1382void ValidateTakeXAImpl(const std::shared_ptr<Array>& values,
1383 const std::shared_ptr<Array>& indices,
1384 const std::shared_ptr<Array>& result) {
1385 using ValuesArrayType = typename TypeTraits<ValuesType>::ArrayType;
1386 using IndexArrayType = typename TypeTraits<IndexType>::ArrayType;
1387 auto typed_values = checked_pointer_cast<ValuesArrayType>(values);
1388 auto typed_result = checked_pointer_cast<ValuesArrayType>(result);
1389 auto typed_indices = checked_pointer_cast<IndexArrayType>(indices);
1390 for (int64_t i = 0; i < indices->length(); ++i) {
1391 if (typed_indices->IsNull(i) || typed_values->IsNull(typed_indices->Value(i))) {
1392 ASSERT_TRUE(result->IsNull(i)) << i;
1393 // The value of a null element is undefined, but right
1394 // out of the Take kernel it is expected to be 0.
1395 if constexpr (is_primitive(ValuesType::type_id)) {
1396 if constexpr (ValuesType::type_id == Type::BOOL) {
1397 ASSERT_EQ(typed_result->Value(i), false);
1398 } else {
1399 ASSERT_EQ(typed_result->Value(i), 0);
1400 }
1401 }
1402 } else {
1403 ASSERT_FALSE(result->IsNull(i)) << i;
1404 ASSERT_EQ(typed_result->GetView(i), typed_values->GetView(typed_indices->Value(i)))
1405 << i;
1406 }
1407 }
1408 // DoCheckTakeCACWithArrays transforms the indices which has a risk of
1409 // overflow, so we only call it if the index type is not too wide.
1410 if (indices->type()->byte_width() <= 4) {
1411 auto cast_options = CastOptions::Safe(TypeHolder{int64()});
1412 ASSERT_OK_AND_ASSIGN(auto indices64, Cast(indices, cast_options));
1413 DoCheckTakeCACWithArrays(values, indices64.make_array(), /*expected=*/result);
1414 }
1415}
1416
1417template <typename ValuesType>
1418void ValidateTakeXA(const std::shared_ptr<Array>& values,

Callers

nothing calls this directly

Calls 10

SafeFunction · 0.85
DoCheckTakeCACWithArraysFunction · 0.85
make_arrayMethod · 0.80
is_primitiveFunction · 0.50
lengthMethod · 0.45
IsNullMethod · 0.45
ValueMethod · 0.45
GetViewMethod · 0.45
byte_widthMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected