Closed blackccpie closed 6 years ago
Finally I made this work with std::make_unsigned_t
:
template <typename... Values>
Tensor<U, xt::xview<Storage &, xt::xrange<std::make_unsigned_t<Values>>...>> subView(
std::initializer_list<Values>... lists) {
using SharedTensor = Tensor<U, xt::xview<Storage &, xt::xrange<std::make_unsigned_t<Values>>...>>;
return SharedTensor(storage_,
xt::range(*(lists.begin()), *(lists.begin() + 1))...);
}
Anyway is it really normal to have this constraint using xrange?
Hi, sorry for the late reply.
Unfortunately this constraint is normal; xrange
can be instantiated with signed integers to avoid mixing signed / unsigned arithmetic when used in a view also containing an xstepped_range
with a negative step for instance.
Note that with xtensor 0.14.0
, the xrange
takes three template parameters, and your first code:
int main()
{
Tensor<float_t> tensor({3, 3, 3, 3}, 2);
auto t_view = tensor.subView({0, 2}, {0, 1}, {0, 3}, {0, 3});
return 0;
}
should compile fine without using any std::make_unsigned_t
. The range will be instantiated with signed integers, though.
@JohanMabille : thx for the precisions. For now I targeted an xtensor version not depending on xtl, but I will try to remember your hint for a future update.
@blackccpie no problem. Out of curiosity, what does prevent you from depending on xtl?
@JohanMabille : the thing is I just needed tiny-dnn to compile fine with emscripten, and as xtensor is embedded in tiny-dnn, and as I'm not a main contributor of the project, I wanted my PR to have limited impact on third party dependencies.
@JohanMabille : but all things considered I admit that shouldn't be too much work to embed xtl headers alongside with xtensor.
ah indeed, I forgot that tiny-dnn was embedding xtensor headers (rather than only depend on them). Indeed embedding xtl headers should be quite straightforward, but I agree that many PRs with limited impact are better than a single one with big changes.
Hi,
I'm working on upgrading currently embedded tiny-dnn's xtensor version (0.10.9) to version 0.11.3, but I have some compilation issues. I've isolated my problem in the following code:
If I replace the
subView
call in the main function by this one then it compiles fine:So the problem is related to signed/unsigned conversion issues, but I don't know what's the cleanest way to correct this in the subView method. I've been struggling to try to use std::make_unsigned_t to operate on the parameter pack, without success for now...
Could someone help me on this? Thx
Albert