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
transpose(E && e) matches too greedily #711
Comments
I also attempted to use auto t = xt::transpose(v); results in an exception: "cannot compute transposed layout of dynamic layout". Moreover, auto t = xt::eval(xt::transpose(v)); fails to compile with error message
|
I guess you can fully qualify your function call as |
|
Totally agree. I just meant it as a workaround for you to be able to move forward.
I think that it would be reasonable for us to at least specialize On whether we would want like-named functions in your own namespace to take precedence, I need to think about whether it makes sense from an ADL perspective. (It is easy to get it wrong, so we should probably think more about it before being opinionated). Regarding the "extension of the xexpression framework", this is something that we do for xframe. In fact, xtensor expressions can be extended with a tags system, and reused to make another expression system, but it might be overkill for the vigra usecase. |
It seems I found a solution: I must also provide template <index_t N, class T>
auto transpose(view_nd<N, T> & array); Conversion to const made the compiler prefer the universal reference. This is a pretty strange rule... Maybe one can formulate the concept check (or whatever solution) such that I don't have to duplicate all functions for const and non-const references. |
@ukoethe I spent a bit of time looking at why you encounter in this issue with Basically,
The code in question is here. The test used to check if the underlying expression has strides is not the best one. We basically check the So one thing you probably want to add in your expression is the |
I implemented the required API, and |
Yeah! Regardless of the discussion on transpose, there are some benefits of having this API in terms of speed.
Well, |
Looking at how the view_type is selected in |
Maybe a good way to do this is that transpose should be renamed "transposed" and continue returning a view. You could define transpose as a mutating operation on your containers. A mutating transpose function is another story. |
I don't want transpose to be mutating. I just want it to return |
Gotcha |
This would make sense, but is inconsistent with numpy. So I'd rather vote to keep the established name. |
@ukoethe what you're suggesting is that xexpression have a type trait such as |
@wolfv this type traits can be external to the expression, and may not be limited to the |
I see, sounds like a good idea. |
I'm also not sure about the best solution. At the moment, I need four overloads of template <class T, index_t N>
decltype(auto) transpose(view_nd<T, N> const & array);
template <class T, index_t N>
decltype(auto) transpose(view_nd<T, N> & array);
template <class T, index_t N, class A>
decltype(auto) transpose(array_nd<T, N, A> const & array);
template <class T, index_t N, class A>
decltype(auto) transpose(array_nd<T, N, A> & array); If one of the overloads is missing, Since xtensor provides many functions taking universal references, it is a general problem to determine exactly when one of those "universal" functions should be called. As a user, I'd like to have some control over the resolution of universal references (e.g. by means of an enable_if), so that the universal function can be switched off when necessary. However, this control should be somewhat fine-grained because I want |
Okay, if I understand @JohanMabille correctly, the idea here would be to do something like
so that you or other library authors can specialize this template, and that's the one we'd be using in functions that return a strided view.
However, that wouldn't solve any problems with other functions that take universal references ... |
Note that the views would have to be equivalent in the template paramters that they are supplied with (or one can probably drop some params if necessary). We're planning to add a layout template parameter to the view by the way. |
I'm making good progress deriving my own array classes from
xview_semantic
(thanks for suggesting this approach, @SylvainCorlay!), but encountered a problem that I cannot solve on my own. I declare the array view and transpose function like this:Unfortunately, I cannot call my transpose function:
Since my class is derived from
xt::xview_semantic
, namespacext
participates in name lookup, andxt::transpose()
, whose argument is a universal reference, is a better match thanxvigra::transpose()
. The straightforward idea to add a concept check forxt::is_xexpression
to xtensor's function does not work, becauseview_nd
fulfills the concept as well. What can I do to get my function called?The text was updated successfully, but these errors were encountered: