35 #include <initializer_list>
55 template<
typename dtype>
57 const std::vector<
const NdArray<dtype>*>& choiceVec, dtype defaultValue = dtype{0})
59 if (choiceVec.size() != condVec.size())
64 if (choiceVec.size() == 0)
69 auto theShape = condVec.front()->shape();
70 for (
const auto cond : condVec)
72 const auto& theCond = *cond;
73 if (theCond.shape() != theShape)
79 for (
const auto choice : choiceVec)
81 const auto& theChoice = *
choice;
82 if (theChoice.shape() != theShape)
91 NdArray<size_type> choiceIndices(theShape);
92 choiceIndices.fill(nullChoice);
93 for (size_type condIdx = 0; condIdx < condVec.size(); ++condIdx)
95 const auto& theCond = *condVec[condIdx];
96 for (size_type i = 0; i < theCond.size(); ++i)
98 if (theCond[i] && choiceIndices[i] == nullChoice)
100 choiceIndices[i] = condIdx;
105 NdArray<dtype> result(theShape);
106 result.fill(defaultValue);
107 for (size_type i = 0; i < choiceIndices.size(); ++i)
109 const auto choiceIndex = choiceIndices[i];
110 if (choiceIndex != nullChoice)
112 const auto& theChoice = *choiceVec[choiceIndex];
113 result[i] = theChoice[i];
134 template<
typename dtype>
137 dtype defaultValue = dtype{0})
139 std::vector<const NdArray<bool>*> condVec;
140 condVec.reserve(condList.size());
141 for (
auto& cond : condList)
143 condVec.push_back(&cond);
146 std::vector<const NdArray<dtype>*> choiceVec;
147 choiceVec.reserve(choiceList.size());
148 for (
auto&
choice : choiceList)
150 choiceVec.push_back(&
choice);
153 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:87
dtype choice(const NdArray< dtype > &inArray)
Definition: choice.hpp:51
Definition: Coordinate.hpp:45
NdArray< dtype > max(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: max.hpp:44
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