close
The Wayback Machine - https://web.archive.org/web/20220526174012/https://github.com/xtensor-stack/xsimd/issues/729
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

Add a batch_cast equivalent for batch_bool #729

Open
marzer opened this issue May 5, 2022 · 2 comments
Open

Add a batch_cast equivalent for batch_bool #729

marzer opened this issue May 5, 2022 · 2 comments

Comments

@marzer
Copy link
Contributor

@marzer marzer commented May 5, 2022

Hiya,

Recently I've found myself having to do math on floats, but do testing against associated integer masks, and I'd like to reduce the pain associated with working with select() in these scenarios.

The library has batch_cast for regular batch, but no equivalent for their batch_bool friends. There's some undocumented bool_cast() functions but they aren't generalized at all and don't appear to be what I'm looking for. Also the somewhat ominous //FIXME comment next to them suggests that I maybe shouldn't depend on these being present 😅

I have hacked this together in my own codebase, and it seems to serve the purpose:

	template <class Dest, class Source, class A>
	inline batch_bool<Dest, A> batch_bool_cast(const batch_bool<Source, A>& x) noexcept
	{
		static_assert(batch_bool<Source, A>::size == batch_bool<Dest, A>::size);

		if constexpr (std::is_same_v<Source, Dest>)
		{
			return x;
		}
		else if constexpr (std::is_same_v<typename batch_bool<Source, A>::register_type,
										  typename batch_bool<Dest, A>::register_type>)
		{
			return batch_bool<Dest, A>(x.data);
		}
		else
		{
			return batch_bool<Dest, A>(batch_cast<Dest>(batch<Source, A>(x)).data);
		}
	}

I think something like this would be a useful addition to the library itself to complement the existing batch_cast().

@serge-sans-paille
Copy link
Contributor

@serge-sans-paille serge-sans-paille commented May 21, 2022

+1 for that one. Please not thet we're still in C++11 though. Waiting for you PR :-)

@marzer
Copy link
Contributor Author

@marzer marzer commented May 21, 2022

Waiting for you PR :-)

Sure, I'd be happy to give this a crack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants