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

Made replace_ignored a new format callable #2061

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 53 additions & 48 deletions include/eve/module/core/regular/replace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,61 @@

namespace eve
{
// TODO DOC is it to be in user interface ?
//================================================================================================
//! @addtogroup core_logical
//! @{
//! @var replace_ignored
//! @brief A small helper to replace ignored values
//!
//! @groupheader{Header file}
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! A convinience wrapper around if_else.
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace eve
//! {
//! template< eve::value T, eve::conditional_expr Ignore, eve::value Other >
//! auto replace_ignored(T x, Ignore ignore, Other with )
//! -> decltype(eve::if_else(ignore, x, with))
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `x` - main value
//! * `ignore` - selection
//! * `with` - value to replace with
//!
//! **Return value**
//!
//! Same as if_else.
//!
//================================================================================================
template<typename Options>
struct replace_ignored_t : callable<replace_ignored_t, Options>
{
template<simd_value T, relative_conditional_expr Ignore, value Other>
constexpr EVE_FORCEINLINE T operator()(T x, Ignore ignore, Other with) const noexcept
{
return eve::if_else(ignore, x, with);
}

EVE_MAKE_CALLABLE(replace_ignored_, replace_ignored);
template<simd_value T, relative_conditional_expr Ignore, generator Other>
constexpr EVE_FORCEINLINE T operator()(T x, Ignore ignore, Other with) const noexcept
{
return eve::if_else(ignore, x, with);
}
};

namespace detail
{
//================================================================================================
// Helper function - Replace ignored value with an alternative
//! @addtogroup core_logical
//! @{
//! @var replace_ignored
//! @brief A small helper to replace ignored values
//!
//! @groupheader{Header file}
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! A convinience wrapper around if_else.
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace eve
//! {
//! template<simd_value T, relative_conditional_expr Ignore, value Other>
//! T replace_ignored(T x, Ignore ignore, Other with);
//!
//! template<simd_value T, relative_conditional_expr Ignore, generator Other>
//! T replace_ignored(T x, Ignore ignore, Other with);
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `x` - main value
//! * `ignore` - selection
//! * `with` - value to replace with
//!
//! **Return value**
//!
//! Same as if_else.
//!
//================================================================================================
inline constexpr auto replace_ignored = functor<replace_ignored_t>;
//================================================================================================
//! @}
//================================================================================================
template<simd_value Wide, conditional_expr Ignore, typename Other>
EVE_FORCEINLINE auto
replace_ignored_(EVE_SUPPORTS(cpu_), Wide x, Ignore ignore, Other with) noexcept
-> decltype(eve::if_else(ignore, x, with))
{
return eve::if_else(ignore, x, with);
}
}
}