Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::UnaryExecutor Struct Reference

Static Public Member Functions

template<class INPUT_TYPE , class RESULT_TYPE , class OP >
static void Execute (Vector &input, Vector &result, idx_t count)
 
template<class INPUT_TYPE , class RESULT_TYPE , class FUNC = std::function<RESULT_TYPE(INPUT_TYPE)>>
static void Execute (Vector &input, Vector &result, idx_t count, FUNC fun, FunctionErrors errors=FunctionErrors::CAN_THROW_RUNTIME_ERROR)
 
template<class INPUT_TYPE , class RESULT_TYPE , class OP >
static void GenericExecute (Vector &input, Vector &result, idx_t count, void *dataptr, bool adds_nulls=false)
 
template<class INPUT_TYPE , class RESULT_TYPE , class FUNC = std::function<RESULT_TYPE(INPUT_TYPE, ValidityMask &, idx_t)>>
static void ExecuteWithNulls (Vector &input, Vector &result, idx_t count, FUNC fun)
 
template<class INPUT_TYPE , class RESULT_TYPE , class OP >
static void ExecuteString (Vector &input, Vector &result, idx_t count)
 
template<class INPUT_TYPE , class FUNC = std::function<bool(INPUT_TYPE)>>
static idx_t Select (Vector &input, const SelectionVector *sel, const idx_t count, FUNC fun, SelectionVector *true_sel, SelectionVector *false_sel)
 

Static Private Member Functions

template<class INPUT_TYPE , class RESULT_TYPE , class OPWRAPPER , class OP >
static void ExecuteLoop (const INPUT_TYPE *__restrict ldata, RESULT_TYPE *__restrict result_data, idx_t count, const SelectionVector *__restrict sel_vector, ValidityMask &mask, ValidityMask &result_mask, void *dataptr, bool adds_nulls)
 
template<class INPUT_TYPE , class RESULT_TYPE , class OPWRAPPER , class OP >
static void ExecuteFlat (const INPUT_TYPE *__restrict ldata, RESULT_TYPE *__restrict result_data, idx_t count, ValidityMask &mask, ValidityMask &result_mask, void *dataptr, bool adds_nulls)
 
template<class INPUT_TYPE , class RESULT_TYPE , class OPWRAPPER , class OP >
static void ExecuteStandard (Vector &input, Vector &result, idx_t count, void *dataptr, bool adds_nulls, FunctionErrors errors=FunctionErrors::CAN_THROW_RUNTIME_ERROR)
 
template<class INPUT_TYPE , class FUNC = std::function<bool(INPUT_TYPE)>, bool NO_NULL, bool HAS_TRUE_SEL, bool HAS_FALSE_SEL>
static idx_t SelectLoop (const INPUT_TYPE *__restrict input_data, const SelectionVector *result_sel, const idx_t count, FUNC fun, const SelectionVector &input_sel, ValidityMask &input_validity, SelectionVector *true_sel, SelectionVector *false_sel)
 
template<class INPUT_TYPE , class FUNC = std::function<bool(INPUT_TYPE)>, bool NO_NULL>
static idx_t SelectLoopSelSwitch (UnifiedVectorFormat &input_data, const SelectionVector *sel, const idx_t count, FUNC fun, SelectionVector *true_sel, SelectionVector *false_sel)
 
template<class INPUT_TYPE , class FUNC = std::function<bool(INPUT_TYPE)>>
static idx_t SelectLoopSwitch (UnifiedVectorFormat &input_data, const SelectionVector *sel, const idx_t count, FUNC fun, SelectionVector *true_sel, SelectionVector *false_sel)
 

Member Function Documentation

◆ ExecuteLoop()

static void duckdb::UnaryExecutor::ExecuteLoop ( const INPUT_TYPE *__restrict  ldata,
RESULT_TYPE *__restrict  result_data,
idx_t  count,
const SelectionVector *__restrict  sel_vector,
ValidityMask mask,
ValidityMask result_mask,
void dataptr,
bool  adds_nulls 
)
inlinestaticprivate
12593 {
12594#ifdef DEBUG
12595 // ldata may point to a compressed dictionary buffer which can be smaller than ldata + count
12596 idx_t max_index = 0;
12597 for (idx_t i = 0; i < count; i++) {
12598 auto idx = sel_vector->get_index(i);
12599 max_index = MaxValue(max_index, idx);
12600 }
12601 ASSERT_RESTRICT(ldata, ldata + max_index, result_data, result_data + count);
12602#endif
12603
12604 if (!mask.AllValid()) {
12605 for (idx_t i = 0; i < count; i++) {
12606 auto idx = sel_vector->get_index(i);
12607 if (mask.RowIsValidUnsafe(idx)) {
12608 result_data[i] =
12609 OPWRAPPER::template Operation<OP, INPUT_TYPE, RESULT_TYPE>(ldata[idx], result_mask, i, dataptr);
12610 } else {
12611 result_mask.SetInvalid(i);
12612 }
12613 }
12614 } else {
12615 for (idx_t i = 0; i < count; i++) {
12616 auto idx = sel_vector->get_index(i);
12617 result_data[i] =
12618 OPWRAPPER::template Operation<OP, INPUT_TYPE, RESULT_TYPE>(ldata[idx], result_mask, i, dataptr);
12619 }
12620 }
12621 }
GMat mask(const GMat &src, const GMat &mask)

◆ ExecuteFlat()

static void duckdb::UnaryExecutor::ExecuteFlat ( const INPUT_TYPE *__restrict  ldata,
RESULT_TYPE *__restrict  result_data,
idx_t  count,
ValidityMask mask,
ValidityMask result_mask,
void dataptr,
bool  adds_nulls 
)
inlinestaticprivate
12626 {
12627 ASSERT_RESTRICT(ldata, ldata + count, result_data, result_data + count);
12628
12629 if (!mask.AllValid()) {
12630 if (!adds_nulls) {
12631 result_mask.Initialize(mask);
12632 } else {
12633 result_mask.Copy(mask, count);
12634 }
12635 idx_t base_idx = 0;
12636 auto entry_count = ValidityMask::EntryCount(count);
12637 for (idx_t entry_idx = 0; entry_idx < entry_count; entry_idx++) {
12638 auto validity_entry = mask.GetValidityEntry(entry_idx);
12639 idx_t next = MinValue<idx_t>(base_idx + ValidityMask::BITS_PER_VALUE, count);
12640 if (ValidityMask::AllValid(validity_entry)) {
12641 // all valid: perform operation
12642 for (; base_idx < next; base_idx++) {
12643 result_data[base_idx] = OPWRAPPER::template Operation<OP, INPUT_TYPE, RESULT_TYPE>(
12644 ldata[base_idx], result_mask, base_idx, dataptr);
12645 }
12646 } else if (ValidityMask::NoneValid(validity_entry)) {
12647 // nothing valid: skip all
12648 base_idx = next;
12649 continue;
12650 } else {
12651 // partially valid: need to check individual elements for validity
12652 idx_t start = base_idx;
12653 for (; base_idx < next; base_idx++) {
12654 if (ValidityMask::RowIsValid(validity_entry, base_idx - start)) {
12655 D_ASSERT(mask.RowIsValid(base_idx));
12656 result_data[base_idx] = OPWRAPPER::template Operation<OP, INPUT_TYPE, RESULT_TYPE>(
12657 ldata[base_idx], result_mask, base_idx, dataptr);
12658 }
12659 }
12660 }
12661 }
12662 } else {
12663 for (idx_t i = 0; i < count; i++) {
12664 result_data[i] =
12665 OPWRAPPER::template Operation<OP, INPUT_TYPE, RESULT_TYPE>(ldata[i], result_mask, i, dataptr);
12666 }
12667 }
12668 }

◆ ExecuteStandard()

static void duckdb::UnaryExecutor::ExecuteStandard ( Vector input,
Vector result,
idx_t  count,
void dataptr,
bool  adds_nulls,
FunctionErrors  errors = FunctionErrors::CAN_THROW_RUNTIME_ERROR 
)
inlinestaticprivate
12673 {
12674 switch (input.GetVectorType()) {
12675 case VectorType::CONSTANT_VECTOR: {
12676 result.SetVectorType(VectorType::CONSTANT_VECTOR);
12677 auto result_data = ConstantVector::GetData<RESULT_TYPE>(result);
12678 auto ldata = ConstantVector::GetData<INPUT_TYPE>(input);
12679
12680 if (ConstantVector::IsNull(input)) {
12681 ConstantVector::SetNull(result, true);
12682 } else {
12683 ConstantVector::SetNull(result, false);
12684 *result_data = OPWRAPPER::template Operation<OP, INPUT_TYPE, RESULT_TYPE>(
12685 *ldata, ConstantVector::Validity(result), 0, dataptr);
12686 }
12687 break;
12688 }
12689#ifndef DUCKDB_SMALLER_BINARY
12690 case VectorType::FLAT_VECTOR: {
12691 result.SetVectorType(VectorType::FLAT_VECTOR);
12692 auto result_data = FlatVector::GetData<RESULT_TYPE>(result);
12693 auto ldata = FlatVector::GetData<INPUT_TYPE>(input);
12694
12695 ExecuteFlat<INPUT_TYPE, RESULT_TYPE, OPWRAPPER, OP>(ldata, result_data, count, FlatVector::Validity(input),
12696 FlatVector::Validity(result), dataptr, adds_nulls);
12697 break;
12698 }
12699 case VectorType::DICTIONARY_VECTOR: {
12700 // dictionary vector - we can run the function ONLY on the dictionary in some cases
12701 // we can only do this if the function does not throw errors
12702 // we can execute the function on a value that is in the dictionary but that is not referenced
12703 // if the function can throw errors - this will result in us (incorrectly) throwing an error
12704 if (errors == FunctionErrors::CANNOT_ERROR) {
12705 static constexpr idx_t DICTIONARY_THRESHOLD = 2;
12706 auto dict_size = DictionaryVector::DictionarySize(input);
12707 if (dict_size.IsValid() && dict_size.GetIndex() * DICTIONARY_THRESHOLD <= count) {
12708 // we can operate directly on the dictionary if we have a dictionary size
12709 // but this only makes sense if the dictionary size is smaller than the count by some factor
12710 auto &dictionary_values = DictionaryVector::Child(input);
12711 if (dictionary_values.GetVectorType() == VectorType::FLAT_VECTOR) {
12712 // execute the function over the dictionary
12713 auto result_data = FlatVector::GetData<RESULT_TYPE>(result);
12714 auto ldata = FlatVector::GetData<INPUT_TYPE>(dictionary_values);
12715 ExecuteFlat<INPUT_TYPE, RESULT_TYPE, OPWRAPPER, OP>(
12716 ldata, result_data, dict_size.GetIndex(), FlatVector::Validity(dictionary_values),
12717 FlatVector::Validity(result), dataptr, adds_nulls);
12718 // slice the result with the original offsets
12719 auto &offsets = DictionaryVector::SelVector(input);
12720 result.Dictionary(result, dict_size.GetIndex(), offsets, count);
12721 break;
12722 }
12723 }
12724 }
12725 DUCKDB_EXPLICIT_FALLTHROUGH;
12726 }
12727#endif
12728 default: {
12729 UnifiedVectorFormat vdata;
12730 input.ToUnifiedFormat(count, vdata);
12731
12732 result.SetVectorType(VectorType::FLAT_VECTOR);
12733 auto result_data = FlatVector::GetData<RESULT_TYPE>(result);
12734 auto ldata = UnifiedVectorFormat::GetData<INPUT_TYPE>(vdata);
12735
12736 ExecuteLoop<INPUT_TYPE, RESULT_TYPE, OPWRAPPER, OP>(ldata, result_data, count, vdata.sel, vdata.validity,
12737 FlatVector::Validity(result), dataptr, adds_nulls);
12738 break;
12739 }
12740 }
12741 }

◆ Execute() [1/2]

static void duckdb::UnaryExecutor::Execute ( Vector input,
Vector result,
idx_t  count 
)
inlinestatic
12745 {
12746 ExecuteStandard<INPUT_TYPE, RESULT_TYPE, UnaryOperatorWrapper, OP>(input, result, count, nullptr, false);
12747 }

◆ Execute() [2/2]

template<class INPUT_TYPE , class RESULT_TYPE , class FUNC = std::function<RESULT_TYPE(INPUT_TYPE)>>
static void duckdb::UnaryExecutor::Execute ( Vector input,
Vector result,
idx_t  count,
FUNC  fun,
FunctionErrors  errors = FunctionErrors::CAN_THROW_RUNTIME_ERROR 
)
inlinestatic
12751 {
12752 ExecuteStandard<INPUT_TYPE, RESULT_TYPE, UnaryLambdaWrapper, FUNC>(
12753 input, result, count, reinterpret_cast<void *>(&fun), false, errors);
12754 }

◆ GenericExecute()

static void duckdb::UnaryExecutor::GenericExecute ( Vector input,
Vector result,
idx_t  count,
void dataptr,
bool  adds_nulls = false 
)
inlinestatic
12757 {
12758 ExecuteStandard<INPUT_TYPE, RESULT_TYPE, GenericUnaryWrapper, OP>(input, result, count, dataptr, adds_nulls);
12759 }

◆ ExecuteWithNulls()

template<class INPUT_TYPE , class RESULT_TYPE , class FUNC = std::function<RESULT_TYPE(INPUT_TYPE, ValidityMask &, idx_t)>>
static void duckdb::UnaryExecutor::ExecuteWithNulls ( Vector input,
Vector result,
idx_t  count,
FUNC  fun 
)
inlinestatic
12763 {
12764 ExecuteStandard<INPUT_TYPE, RESULT_TYPE, UnaryLambdaWrapperWithNulls, FUNC>(input, result, count, (void *)&fun,
12765 true);
12766 }

◆ ExecuteString()

static void duckdb::UnaryExecutor::ExecuteString ( Vector input,
Vector result,
idx_t  count 
)
inlinestatic
12769 {
12770 UnaryExecutor::GenericExecute<INPUT_TYPE, RESULT_TYPE, UnaryStringOperator<OP>>(input, result, count,
12771 (void *)&result);
12772 }

◆ SelectLoop()

template<class INPUT_TYPE , class FUNC = std::function<bool(INPUT_TYPE)>, bool NO_NULL, bool HAS_TRUE_SEL, bool HAS_FALSE_SEL>
static idx_t duckdb::UnaryExecutor::SelectLoop ( const INPUT_TYPE *__restrict  input_data,
const SelectionVector result_sel,
const idx_t  count,
FUNC  fun,
const SelectionVector input_sel,
ValidityMask input_validity,
SelectionVector true_sel,
SelectionVector false_sel 
)
inlinestaticprivate
12781 {
12782 idx_t true_count = 0, false_count = 0;
12783 for (idx_t i = 0; i < count; i++) {
12784 const auto result_idx = result_sel->get_index(i);
12785 const auto idx = input_sel.get_index(i);
12786 const bool comparison_result = (NO_NULL || input_validity.RowIsValid(idx)) && fun(input_data[idx]);
12787 if (HAS_TRUE_SEL) {
12788 true_sel->set_index(true_count, result_idx);
12789 true_count += comparison_result;
12790 }
12791 if (HAS_FALSE_SEL) {
12792 false_sel->set_index(false_count, result_idx);
12793 false_count += !comparison_result;
12794 }
12795 }
12796 if (HAS_TRUE_SEL) {
12797 return true_count;
12798 } else {
12799 return count - false_count;
12800 }
12801 }

◆ SelectLoopSelSwitch()

template<class INPUT_TYPE , class FUNC = std::function<bool(INPUT_TYPE)>, bool NO_NULL>
static idx_t duckdb::UnaryExecutor::SelectLoopSelSwitch ( UnifiedVectorFormat input_data,
const SelectionVector sel,
const idx_t  count,
FUNC  fun,
SelectionVector true_sel,
SelectionVector false_sel 
)
inlinestaticprivate
12806 {
12807 if (true_sel && false_sel) {
12808 return SelectLoop<INPUT_TYPE, FUNC, NO_NULL, true, true>(
12809 UnifiedVectorFormat::GetData<INPUT_TYPE>(input_data), sel, count, fun, *input_data.sel,
12810 input_data.validity, true_sel, false_sel);
12811 } else if (true_sel) {
12812 return SelectLoop<INPUT_TYPE, FUNC, NO_NULL, true, false>(
12813 UnifiedVectorFormat::GetData<INPUT_TYPE>(input_data), sel, count, fun, *input_data.sel,
12814 input_data.validity, true_sel, false_sel);
12815 } else {
12816 D_ASSERT(false_sel);
12817 return SelectLoop<INPUT_TYPE, FUNC, NO_NULL, false, true>(
12818 UnifiedVectorFormat::GetData<INPUT_TYPE>(input_data), sel, count, fun, *input_data.sel,
12819 input_data.validity, true_sel, false_sel);
12820 }
12821 }

◆ SelectLoopSwitch()

template<class INPUT_TYPE , class FUNC = std::function<bool(INPUT_TYPE)>>
static idx_t duckdb::UnaryExecutor::SelectLoopSwitch ( UnifiedVectorFormat input_data,
const SelectionVector sel,
const idx_t  count,
FUNC  fun,
SelectionVector true_sel,
SelectionVector false_sel 
)
inlinestaticprivate
12825 {
12826 if (!input_data.validity.AllValid()) {
12827 return SelectLoopSelSwitch<INPUT_TYPE, FUNC, false>(input_data, sel, count, fun, true_sel, false_sel);
12828 } else {
12829 return SelectLoopSelSwitch<INPUT_TYPE, FUNC, true>(input_data, sel, count, fun, true_sel, false_sel);
12830 }
12831 }

◆ Select()

template<class INPUT_TYPE , class FUNC = std::function<bool(INPUT_TYPE)>>
static idx_t duckdb::UnaryExecutor::Select ( Vector input,
const SelectionVector sel,
const idx_t  count,
FUNC  fun,
SelectionVector true_sel,
SelectionVector false_sel 
)
inlinestatic
12836 {
12837 if (!sel) {
12838 sel = FlatVector::IncrementalSelectionVector();
12839 }
12840 UnifiedVectorFormat input_data;
12841 input.ToUnifiedFormat(count, input_data);
12842
12843 return SelectLoopSwitch<INPUT_TYPE, FUNC>(input_data, sel, count, fun, true_sel, false_sel);
12844 }

The documentation for this struct was generated from the following file: