58 dtype defaultValue = dtype{ 0 })
60 if (choiceVec.size() != condVec.size())
65 if (choiceVec.size() == 0)
70 auto theShape = condVec.front()->shape();
71 for (
const auto cond : condVec)
73 const auto& theCond = *cond;
74 if (theCond.shape() != theShape)
80 for (
const auto choice : choiceVec)
82 const auto& theChoice = *
choice;
83 if (theChoice.shape() != theShape)
86 "all NdArrays of the choiceVec must be the same shape, and the same as condVec");
91 constexpr auto nullChoice = std::numeric_limits<size_type>::max();
94 choiceIndices.fill(nullChoice);
95 for (size_type condIdx = 0; condIdx < condVec.size(); ++condIdx)
97 const auto& theCond = *condVec[condIdx];
98 for (size_type i = 0; i < theCond.size(); ++i)
100 if (theCond[i] && choiceIndices[i] == nullChoice)
102 choiceIndices[i] = condIdx;
108 result.fill(defaultValue);
109 for (size_type i = 0; i < choiceIndices.size(); ++i)
111 const auto choiceIndex = choiceIndices[i];
112 if (choiceIndex != nullChoice)
114 const auto& theChoice = *choiceVec[choiceIndex];
115 result[i] = theChoice[i];
140 dtype defaultValue = dtype{ 0 })
142 std::vector<const NdArray<bool>*> condVec(condList.size());
146 [](
auto& cond) noexcept ->
const NdArray<bool>* { return &cond; });
148 std::vector<const NdArray<dtype>*> choiceVec(choiceList.size());
152 [](
auto& choice) noexcept ->
const NdArray<dtype>* { return &choice; });
154 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:56