xtensor icon indicating copy to clipboard operation
xtensor copied to clipboard

[Bug] Error when using vstack with mixed shape type

Open spectre-ns opened this issue 2 years ago • 1 comments

See the following godbolt link: https://godbolt.org/z/e11s1999W

The issue appears to be due to the following code:

    /**
     * @brief Stack xexpressions in sequence vertically (row wise).
     * This is equivalent to concatenation along the first axis after
     * 1-D arrays of shape (N) have been reshape to (1, N).
     *
     * @param t \ref xtuple of xexpressions to stack
     * @return xgenerator evaluating to stacked elements
     */
    template <class... CT>
    inline auto vstack(std::tuple<CT...>&& t)
    {
        using shape_type = promote_shape_t<typename std::decay_t<CT>::shape_type...>;
        using source_shape_type = decltype(std::get<0>(t).shape());
        auto new_shape = detail::vstack_shape(
            t,
            xtl::forward_sequence<shape_type, source_shape_type>(std::get<0>(t).shape())
        );
        return detail::make_xgenerator(detail::vstack_impl<CT...>(std::move(t), size_t(0)), new_shape);
    }

There should be a check to make sure that the most generic shape type is used rather than just the first type.

spectre-ns avatar Dec 08 '23 18:12 spectre-ns

@JohanMabille @SylvainCorlay Is the intent with Xtensor that all interfaces calls work with all expressions? I'm finding that in this case and others that I need to insert xt::eval() calls strategically to 'flatten' the expressions which reduces the power of the lazy computing paradigm.

spectre-ns avatar Dec 12 '23 13:12 spectre-ns