-
Notifications
You must be signed in to change notification settings - Fork 53
Implement SimpleArray
member functions for searching part 2
#535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
} | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use an
std::vector
to store the indices of elements that satisfy the condition. - Creating the output
coordinates
and 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please profile the runtime performance of the searching functions like what issue #532 does? If the runtime is much worse than numpy, we may not use the implementation in this PR and need to find another approach.
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
SimpleArrayMixinConditional
to 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::function
template, I could use lambdas as argument—letting the API mirror NumPy’s style in Python.