xtensor-stack / xtensor

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

xtensor_fixed broadcasting bug? #1392

Closed cmauney closed 5 years ago

cmauney commented 5 years ago

This may be related to #1345 The follow code demonstrates the difficulty:

int main() {

  xt::xtensor<double, 1> t;
  xt::xtensor_fixed<double, xt::xshape<16>> t_f;

  t = xt::linspace<double>(1.0, 10.0, 16);
  t_f = t;

  std::cout << 2.0 * t << std::endl;  // <--compiles, executes fine
  std::cout << 2.0 * t_f << std::endl; // <--does NOT compile

  return 0;
}

The error is the following:

include/xtensor/xstrides.hpp:305:36: error: lvalue required as left operand of assignment
                     strides[i - 1] = data_size;
                     ~~~~~~~~~~~~~~~^~~~~~~~~~~
include/xtensor/xstrides.hpp:314:32: error: lvalue required as left operand of assignment
                     strides[i] = data_size;

Using the latest version on master. GCC v8.2.1.

EDIT: updated error;

cmauney commented 5 years ago

This was due to confusion on my part. Forcing evaluation (xt::eval) fixed it.

wolfv commented 5 years ago

I think this is a valid issue with printing xfunctions with xtensor_fixed containers.

There seems to be some code which tries to assign a value to a non-writable strides in xaccumulator. We need to check that we use the correct assignable strides type.