xtensor-stack / xtensor

C++ tensors with broadcasting and lazy computing
BSD 3-Clause "New" or "Revised" License
3.33k stars 398 forks source link

Add strides to xbroadcast #917

Open wolfv opened 6 years ago

wolfv commented 6 years ago

We can trivially add strides to xbroadcast by prepending 0 where broadcast occurs.

This will allow for speed up in the strided loop as we can use the step_simd functions of the underlying steppers.

However, for broadcast of scalar (as done in xt::ones<double>({...}) we need to somehow special case a set of 0 strides.

wolfv commented 6 years ago

@SylvainCorlay and me were discussing to use the strided_view as replacement for xbroadcast (we could just set strides to 0 for broadcast).

benbovy commented 6 years ago

Would it also allow to use xt::view with a xbroadcast?

Currently it seems that xt::strided_view is required.

double a = 1.;

auto arr = xt::broadcast(a, {3, 4, 4});

auto v = xt::strided_view(arr, {0, xt::all(), xt::all()});
auto v2 = xt::view(arr, 0, xt::all(), xt::all());

std::cout << v;  // works
std::cout << v2;  // error: no matching member function for call to 'strides'
wolfv commented 6 years ago

Hi @benbovy that's definitely a bug in it's own right -- printing a view on something non-strided should always work. Would you mind opening another bug report? Thanks!

But -- it would be solved by adding strides to broadcast, yes.

wolfv commented 6 years ago

I'm working on a big xview PR right now and your issue will be fixed. would still be useful to make a bug so we can track this kind of stuff.

benbovy commented 6 years ago

I'm working on a big xview PR right now and your issue will be fixed. would still be useful to make a bug so we can track this kind of stuff.

Great, thanks! Opened #1033.