xtensor icon indicating copy to clipboard operation
xtensor copied to clipboard

Can't check equality of shapes of xtensor_fixed and xscalar

Open tailsu opened this issue 1 year ago • 0 comments

Tested on 0.25.0, Clang 17. Repro code below. Code works when XTENSOR_ENABLE_ASSERT is not defined and doesn't compile when it is defined.

// #define XTENSOR_ENABLE_ASSERT

#include <xtensor/xfixed.hpp>
#include <xtensor/xscalar.hpp>
#include <iostream>

using Point2i = xt::xtensor_fixed<int, xt::xshape<2>>;

int main() {
    Point2i bits{3, 4};
    bool valid = xt::all(bits <= 100);

    std::cout << valid << std::endl;
    return 0;
}

The compiler says it can't equality-compare xtensor_fixed::shape() and xscalar::shape(). The former is an xt::const_array and the latter is an std::array, so maybe that's why.

xtensor/xiterator.hpp:1199:38: error: invalid operands to binary expression ('const xt::fixed_shape<2>' and 'const xt::fixed_shape<2>')
        XTENSOR_ASSERT(this->shape() == rhs.shape());
                       ~~~~~~~~~~~~~ ^  ~~~~~~~~~~~
xtensor/xexception.hpp:331:50: note: expanded from macro 'XTENSOR_ASSERT'
#define XTENSOR_ASSERT(expr) XTENSOR_ASSERT_IMPL(expr, __FILE__, __LINE__)
                                                 ^~~~
xtensor/xexception.hpp:333:11: note: expanded from macro 'XTENSOR_ASSERT_IMPL'
    if (!(expr))                                                                                   \
          ^~~~
xtensor/xiterator.hpp:1213:20: note: in instantiation of member function 'xt::xiterator<xt::xfunction_stepper<xt::detail::less_equal, const xt::xfixed_container<int, xt::fixed_shape<2>, xt::layout_type::row_major> &, xt::xscalar<int>>, xt::fixed_shape<2> *, xt::layout_type::row_major>::equal' requested here
        return lhs.equal(rhs);

This used to compile fine somewhere around version 0.23.4

tailsu avatar May 27 '24 12:05 tailsu