31#include <initializer_list>
57 template<
typename dtype>
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");
95 NdArray<size_type> choiceIndices(theShape);
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;
109 NdArray<dtype> result(theShape);
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];
139 template<
typename dtype>
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);
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
uint32 size_type
Definition: NdArrayCore.hpp:156
dtype choice(GeneratorType &generator, const NdArray< dtype > &inArray)
Definition: choice.hpp:53
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:775
Definition: Cartesian.hpp:40
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
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:44