Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XSIMD bool <-> bool assignment problem #123

Open
Ivorforce opened this issue Oct 9, 2024 · 0 comments
Open

XSIMD bool <-> bool assignment problem #123

Ivorforce opened this issue Oct 9, 2024 · 0 comments
Labels
feature New feature or request

Comments

@Ivorforce
Copy link
Owner

We have worked around an XTENSOR / XSIMD assignment problem from bool to bool. My reproduction code does not compile, because of simd errors. Why does it compile in our project? If we can get it to compile, and produce the same problems, we should report it.

#define XTENSOR_USE_XSIMD
#include <iostream>
#include <set>

#include "xtensor/xarray.hpp"
#include "xtensor/xstrided_view.hpp"
#include "xtensor/xadapt.hpp"
#include "xtensor/xrandom.hpp"
#include "xtensor/xio.hpp"
#include "xtensor/xmasked_view.hpp"
#include "xtensor/xpad.hpp"

template<typename T, typename E>
inline void broadcasting_assign(xt::xexpression<T>& t, const xt::xexpression<E>& e) {
	xt::assert_compatible_shape(t, e);
	xt::assign_data(t, e, xt::detail::get_rhs_triviality(e.derived_cast()));
}

using size_type = std::size_t;
// Refer to xarray
using shape_type = xt::dynamic_shape<size_type>;
// Refer to xarray xcontainer_inner_types.
using strides_type = xt::get_strides_t<shape_type>;
using axes_type = strides_type;

template<typename T>
using compute_case = xt::xarray_adaptor<
	xt::xbuffer_adaptor<T, xt::no_ownership, xt::detail::default_allocator_for_ptr_t<T>>,
	xt::layout_type::dynamic,
	shape_type
>;

template<typename V>
	static compute_case<V> make_compute(V&& ptr, const shape_type& shape, const strides_type& strides, xt::layout_type layout) {
	auto size_ = std::accumulate(shape.begin(), shape.end(), static_cast<std::size_t>(1), std::multiplies());

	switch (layout) {
		case xt::layout_type::row_major:
		case xt::layout_type::column_major:
			return xt::adapt<xt::layout_type::dynamic, V>(std::forward<V>(ptr), size_, xt::no_ownership(), shape, layout);
		default: {
			return xt::adapt<V>(std::forward<V>(ptr), size_, xt::no_ownership(), shape, strides);
		}
	}
}

int main()
{
	xt::xarray<bool> a = xt::zeros<bool>({80, 80});
	auto shape = a.shape();
	shape[0] -= 2;
	shape[1] -= 2;
	auto adaptA = make_compute<bool*>(a.data() + 81, shape, a.strides(), xt::layout_type::dynamic);

	xt::xarray<bool> b = xt::ones<bool>({78, 78});
	const auto adaptB = make_compute<const bool*>(b.data(), b.shape(), b.strides(), xt::layout_type::dynamic);

	broadcasting_assign(adaptA, adaptB);

	std::cout << a << std::endl;
}
@Ivorforce Ivorforce added the feature New feature or request label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant