xtensor-stack / xtensor

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

vstack with fixed shapes doesn't compile #2372

Open tailsu opened 3 years ago

tailsu commented 3 years ago

The following code:

#include "xtensor/xfixed.hpp"

template <std::size_t Dim>
using PointList = xt::xtensor_fixed<float, xt::xshape<Dim, 2>>;

int main() {

  PointList<1> a;
  PointList<2> b;

  PointList<3> c = xt::vstack(xt::xtuple(a, b));
}

fails to compile on clang 12 with the following error:

xtensor/include/xtensor/xbuilder.hpp:850:17: error: no matching constructor for initialization of 'xt::fixed_shape<2, 2>'
                S({sizeof...(CT), shape[0]}) :
                ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
xtensor/include/xtensor/xbuilder.hpp:876:34: note: in instantiation of function template specialization 'xt::detail::vstack_shape<xt::fixed_shape<2, 2>, const xt::xfixed_container<float, xt::fixed_shape<1, 2>, xt::layout_type::row_major, true, xt::xtensor_expression_tag> &, const xt::xfixed_container<float, xt::fixed_shape<2, 2>, xt::layout_type::row_major, true, xt::xtensor_expression_tag> &>' requested here
        auto new_shape = detail::vstack_shape(t, xtl::forward_sequence<shape_type, source_shape_type>(std::get<0>(t).shape()));
                                 ^
main.cpp:12:24: note: in instantiation of function template specialization 'xt::vstack<const xt::xfixed_container<float, xt::fixed_shape<1, 2>, xt::layout_type::row_major, true, xt::xtensor_expression_tag> &, const xt::xfixed_container<float, xt::fixed_shape<2, 2>, xt::layout_type::row_major, true, xt::xtensor_expression_tag> &>' requested here
  PointList<3> c = xt::vstack(xt::xtuple(a, b));

vstack is supposed to support fixed tensors as well, right?

Tested on today's master.

tailsu commented 3 years ago

xt::hstack works correctly in the same scenario