60 dtype defaultValue = dtype{ 0 })
62 if (choiceVec.size() != condVec.size())
67 if (choiceVec.size() == 0)
72 auto theShape = condVec.front()->shape();
73 for (
const auto cond : condVec)
75 const auto& theCond = *cond;
76 if (theCond.shape() != theShape)
82 for (
const auto choice : choiceVec)
84 const auto& theChoice = *
choice;
85 if (theChoice.shape() != theShape)
88 "all NdArrays of the choiceVec must be the same shape, and the same as condVec");
93 constexpr auto nullChoice = std::numeric_limits<size_type>::max();
96 choiceIndices.fill(nullChoice);
97 for (size_type condIdx = 0; condIdx < condVec.size(); ++condIdx)
99 const auto& theCond = *condVec[condIdx];
100 for (size_type i = 0; i < theCond.size(); ++i)
102 if (theCond[i] && choiceIndices[i] == nullChoice)
104 choiceIndices[i] = condIdx;
110 result.fill(defaultValue);
111 for (size_type i = 0; i < choiceIndices.size(); ++i)
113 const auto choiceIndex = choiceIndices[i];
114 if (choiceIndex != nullChoice)
116 const auto& theChoice = *choiceVec[choiceIndex];
117 result[i] = theChoice[i];
142 dtype defaultValue = dtype{ 0 })
144 std::vector<const NdArray<bool>*> condVec(condList.size());
148 [](
auto& cond) noexcept ->
const NdArray<bool>* { return &cond; });
150 std::vector<const NdArray<dtype>*> choiceVec(choiceList.size());
154 [](
auto& choice) noexcept ->
const NdArray<dtype>* { return &choice; });
156 return select(condVec, choiceVec, defaultValue);
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:776
NdArray< dtype > select(const std::vector< const NdArray< bool > * > &condVec, const std::vector< const NdArray< dtype > * > &choiceVec, dtype defaultValue=dtype{ 0 })
Definition select.hpp:58