31 #include <initializer_list>
56 template<
typename dtype>
59 dtype defaultValue = dtype{ 0 })
61 if (choiceVec.size() != condVec.size())
66 if (choiceVec.size() == 0)
71 auto theShape = condVec.front()->shape();
72 for (
const auto cond : condVec)
74 const auto& theCond = *cond;
75 if (theCond.shape() != theShape)
81 for (
const auto choice : choiceVec)
83 const auto& theChoice = *
choice;
84 if (theChoice.shape() != theShape)
87 "all NdArrays of the choiceVec must be the same shape, and the same as condVec");
94 NdArray<size_type> choiceIndices(theShape);
95 choiceIndices.fill(nullChoice);
96 for (size_type condIdx = 0; condIdx < condVec.size(); ++condIdx)
98 const auto& theCond = *condVec[condIdx];
99 for (size_type i = 0; i < theCond.size(); ++i)
101 if (theCond[i] && choiceIndices[i] == nullChoice)
103 choiceIndices[i] = condIdx;
108 NdArray<dtype> result(theShape);
109 result.fill(defaultValue);
110 for (size_type i = 0; i < choiceIndices.size(); ++i)
112 const auto choiceIndex = choiceIndices[i];
113 if (choiceIndex != nullChoice)
115 const auto& theChoice = *choiceVec[choiceIndex];
116 result[i] = theChoice[i];
138 template<
typename dtype>
141 dtype defaultValue = dtype{ 0 })
143 std::vector<const NdArray<bool>*> condVec;
144 condVec.reserve(condList.size());
145 for (
auto& cond : condList)
147 condVec.push_back(&cond);
150 std::vector<const NdArray<dtype>*> choiceVec;
151 choiceVec.reserve(choiceList.size());
152 for (
auto&
choice : choiceList)
154 choiceVec.push_back(&
choice);
157 return select(condVec, choiceVec, defaultValue);
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
uint32 size_type
Definition: NdArrayCore.hpp:88
dtype choice(GeneratorType &generator, const NdArray< dtype > &inArray)
Definition: choice.hpp:54
Definition: Coordinate.hpp:45
NdArray< dtype > select(const std::vector< const NdArray< bool > * > &condVec, const std::vector< const NdArray< dtype > * > &choiceVec, dtype defaultValue=dtype{ 0 })
Definition: select.hpp:57
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:44