Implement SimpleArray member functions for searching part 2#535
Implement SimpleArray member functions for searching part 2#535pchsu-hsupc wants to merge 1 commit intosolvcon:masterfrom
SimpleArray member functions for searching part 2#535Conversation
| } | ||
|
|
||
| template <typename A, typename T> | ||
| SimpleArray<uint64_t> detail::SimpleArrayMixinSearch<A, T>::argwhere(std::function<bool(value_type const &)> const & condition) const |
There was a problem hiding this comment.
- Use an
std::vectorto store the indices of elements that satisfy the condition. - Creating the output
coordinatesand filling the dimensions's information.
| } | ||
|
|
||
| template <typename A, typename T> | ||
| A detail::SimpleArrayMixinSearch<A, T>::where(std::function<bool(value_type const &)> const & condition, A const & other) const |
There was a problem hiding this comment.
- Should output the same shape as input.
- If the condition is met, fill with the original value; otherwise, use the alternative.
| }, | ||
| py::arg("condition") = py::none()) | ||
| .def( | ||
| "where", |
There was a problem hiding this comment.
Numpy's where() says that when only condition is provided, nonzero() should be preferred. So I didn't give SimpleArray::where default operation.
|
Thank you, @ThreeMonth03 and @KHLee529, for your valuable insights. |
|
Sure, I will add it in. |
ProfilingUse the built-in tools Numpy is abbreviated to
With iterations = 50, the test cases were generated using |
|
Please include your profile script in the PR. @KHLee529 could you please help @pchsu-hsupc ? The runtime is much less slower than I thought, but still too slow to be useful. We may not implement the interface by using a Python callable and/or lambda. |
|
@pchsu-hsupc I think it 's worthy to first clarify whether it's the Python callable value that makes runtime slow or the C++ |
|
@pchsu-hsupc In the discussions in the meetup, we concluded that it should use Boolean array to select elements in the way that numpy employs. Please update your progress. |
Completed Tasks
Make Python unittest for
SimpleArray::argwhere()andSimpleArray::where()Using mixin class
SimpleArrayMixinConditionalto collect methodsSimpleArray::argwhere()andSimpleArray::where()Abstraction
As mentioned in #519 , this PR implements
argwhere()andwhere()methods without overloading operators.numpy.argwhere(a): Find the indices of array elements that are non-zero by default, also could add condition as well.numpy.where(condition, [x, y, ]/): Return elements chosen from x or y depending on condition.Implement Method
Thanks to the
std::functiontemplate, I could use lambdas as argument—letting the API mirror NumPy’s style in Python.