-
Notifications
You must be signed in to change notification settings - Fork 398
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
xindexview function for advanced indexing #88
Conversation
Who will stop you ? :) That's definitely a must have. I guess this implementation is not finished (since some operators are commented and there is no test) ? |
So this was functionality wise already working. However, I am wondering: Does it make sense to implement xstepper in a way that it takes a reference to the underlying I'll also add some tests! |
If that improves the performance of the stepper, that makes sense. Else you should avoid to use the private implementation of the |
Ok, I have implemented the xstepper with the public interface of the underlying view. Let me know what you think! Currently can't really figure out why the clang 3.6 build is failing. I think one improvement could be to use a heap allocated shape if a compile time known list of indices is given. |
That looks like a dangling reference bug. We experienced it before on other tests, a workaround is to avoid nested calls to functions that return xview and/or xfunction. #85 should fix this kind of problems. I'll have a look at your code soon ! |
4748127
to
26aadd0
Compare
I'm giving up ... is there an easy way to install old clang in a docker image? |
I don't know how to do that :/ Maybe you could try running the tests with valgrind ? Even if the tests pass, valgrind could detect some memory issues that lead to the crash with clang. |
Ok, I installed clang3.6 in a docker image and found the bug ... when |
Well done ! |
include/xtensor/xindexview.hpp
Outdated
* | ||
* @tparam T the function type | ||
* @tparam R the return type of the function | ||
* @tparam S the shape type of the generator |
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.
This should be replaced by the documentation corresponding to this class. The same for the remaining of the documentation
include/xtensor/xindexview.hpp
Outdated
* @tparam S the shape type of the generator | ||
*/ | ||
template <class T, class S> | ||
class xindexview : public xview_semantic<xindexview<T, S>> |
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.
It's only about style here, but I think T
should be replaced by E
. T
generally implies a basic type parameter, while E
implies more an expression, which is the kind of types you expect here.
include/xtensor/xindexview.hpp
Outdated
reference operator[](const xindex& index); | ||
|
||
template <class It> | ||
reference element(const It& first, const It& last); |
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.
Iterators should be passed by value, not by const ref.
include/xtensor/xindexview.hpp
Outdated
const_reference operator[](const xindex& index) const; | ||
|
||
template <class It> | ||
const_reference element(const It& first, const It& last) 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.
Same remark as for the non const reference
include/xtensor/xindexview.hpp
Outdated
using temporary_type = typename xcontainer_inner_types<self_type>::temporary_type; | ||
using base_index_type = get_index_type<shape_type>; | ||
|
||
xindexview(T& f, const indices_type&& indices) noexcept; |
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.
I think there's a typo here, you can't combine const and rvalue reference. Depending on how you want to instantiate an xindexvie you might consider rvalue reference and const lvalue reference overloads, or better universal references.
include/xtensor/xindexview.hpp
Outdated
//@{ | ||
/** | ||
* Constructs an xindexview applying the specified function over the | ||
* given shape. |
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.
Same remark as for the class declaration, you should rewrite the documentation so it matches what this code does.
include/xtensor/xindexview.hpp
Outdated
template <class T> | ||
auto inline make_xindexview(T& arr, const std::vector<xindex>&& indices) | ||
{ | ||
return xt::xindexview<T, std::vector<std::size_t>>(arr, std::move(indices)); |
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.
Same remark as for the xindex_view constructor, you can't mix const and rvalue reference. You can't use universal references if you want to allow initializer lists, so you'll need overloads for rvalue reference and const lvalue reference.
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.
Hmm... I have fixed this issue. Can you check if I got it right? I'm not a super-expert on these fancy references :)
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.
The constructor of xindex_view
is good.
The make_xindexview
function may be problematic, generally you should avoid to overload on universal references since they are a "catch all" arguments. However this seems to work and I don't want to wait more for this feature (Travis delays are killing me).
include/xtensor/xindexview.hpp
Outdated
} | ||
|
||
template <class T, class O> | ||
auto inline make_xboolview(T& arr, const O& bool_arr) |
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.
I wonder whether something like filter_view
or make_xfilter
would be a better name.
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.
renamed it to make_xfilter for now.
include/xtensor/xindexview.hpp
Outdated
template <bool is_const, class T, class S> | ||
inline void xindexview_stepper<is_const, T, S>::step_back(size_type dim, size_type n) | ||
{ | ||
m_index[dim] -= 1; |
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.
I'm not sure about it but shouldn't we have m_index[dim] -= n
?
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.
fixed.
I add it to 0.4 milestone since you're very close to finish this. |
Let's merge ! |
I hope this doesn't come across as spam :) but I have attempted an implementation for an "index view". ie. one can provide a list of indices and those will be selected into a linear view.
Essentially, it allows for numpys advanced indexing like so:
With corresponding output:
Let me know what you think.