5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_SCALED_ACCESSOR_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_SCALED_ACCESSOR_HPP_
17#include "arene/base/stdlib_choice/cstddef.hpp"
18#include "arene/base/stdlib_choice/declval.hpp"
19#include "arene/base/stdlib_choice/enable_if.hpp"
20#include "arene/base/stdlib_choice/is_constructible.hpp"
21#include "arene/base/stdlib_choice/is_convertible.hpp"
22#include "arene/base/stdlib_choice/is_copy_constructible.hpp"
23#include "arene/base/stdlib_choice/is_reference.hpp"
24#include "arene/base/stdlib_choice/remove_const.hpp"
43template <
class ScalingFactor,
class NestedAccessor>
47 ScalingFactor scaling_factor_;
79 class OtherNestedAccessor,
93 class OtherNestedAccessor,
107 constexpr scaled_accessor(ScalingFactor
const& scale, NestedAccessor
const& inner_accessor)
noexcept(
111 : NestedAccessor(inner_accessor),
112 scaling_factor_{scale} {}
116 "-Wimplicit-int-float-conversion",
117 "The noexcept specification is unevaluated so it can't lose information"
119 ARENE_IGNORE_CLANG(
"-Wsign-conversion",
"The noexcept specification is unevaluated so it can't lose information");
131 typename NestedAccessor::element_type(
136 return scaling_factor() *
typename NestedAccessor::element_type(NestedAccessor::access(handle, index));
146 return NestedAccessor::offset(handle, index);
151 constexpr auto scaling_factor() const noexcept -> ScalingFactor const& {
return scaling_factor_; }
155 constexpr auto nested_accessor() const noexcept -> NestedAccessor const& {
return *
this; }
158namespace scaled_detail {
163template <
class Mdspan,
class ScalingFactor =
typename Mdspan::value_type>
165 typename scaled_accessor<ScalingFactor, typename Mdspan::accessor_type>::element_type,
166 typename Mdspan::extents_type,
167 typename Mdspan::layout_type,
168 scaled_accessor<ScalingFactor, typename Mdspan::accessor_type>>;
181template <
class ScalingFactor,
class ElementType,
class Extents,
class Layout,
class Accessor>
183 noexcept(scaled_detail::scaled_mdspan<mdspan<ElementType, Extents, Layout, Accessor>, ScalingFactor>{
184 original.data_handle(),
186 {scaling_factor, original.accessor()}
189 return {original.data_handle(), original.mapping(), {scaling_factor, original.accessor()}};
ARENE_IGNORE_CLANG("-Wsign-conversion", "The noexcept specification is unevaluated so it can't lose information")
std::remove_const_t< element_type > reference
Reference type yielded by calls to the access function.
Definition scaled_accessor.hpp:56
constexpr scaled_accessor(scaled_accessor< ScalingFactor, OtherNestedAccessor > other) noexcept(std::is_nothrow_constructible< NestedAccessor, OtherNestedAccessor const & >::value &&std::is_nothrow_copy_constructible< ScalingFactor >::value)
Converting constructor; implicit SFINAE overload for when the nested accessors are implicitly convert...
Definition scaled_accessor.hpp:82
ARENE_IGNORE_CLANG("-Wimplicit-int-float-conversion", "The noexcept specification is unevaluated so it can't lose information")
constexpr scaled_accessor(ScalingFactor const &scale, NestedAccessor const &inner_accessor) noexcept(std::is_nothrow_copy_constructible< NestedAccessor >::value &&std::is_nothrow_copy_constructible< ScalingFactor >::value)
Construct a scaled_accessor from a scaling factor and an instance of the nested accessor.
Definition scaled_accessor.hpp:107
constexpr auto nested_accessor() const noexcept -> NestedAccessor const &
Definition scaled_accessor.hpp:155
constexpr auto offset(data_handle_type handle, std::size_t index) const noexcept(noexcept(std::declval< NestedAccessor >().offset(handle, index))) -> typename offset_policy::data_handle_type
apply an offset to a pointer
Definition scaled_accessor.hpp:143
const element_type
Element type of the element space mapped by the access function (no elements of this type are stored)
Definition scaled_accessor.hpp:52
scaled_accessor< ScalingFactor, typename NestedAccessor::offset_policy > offset_policy
Offset policy type.
Definition scaled_accessor.hpp:60
constexpr auto scaling_factor() const noexcept -> ScalingFactor const &
Definition scaled_accessor.hpp:151
constexpr scaled_accessor()=default
Default constructor.
constexpr auto access(data_handle_type handle, std::size_t index) const noexcept(noexcept(std::declval< ScalingFactor const & >() *typename NestedAccessor::element_type(std::declval< >()))) -> reference
Obtain the element at the specified index, multiplied by the scaling factor.
Definition scaled_accessor.hpp:129
typename NestedAccessor::data_handle_type data_handle_type
Data handle type.
Definition scaled_accessor.hpp:58
A multidimensional view of elements over a contiguous sequence of elements.
Definition mdspan.hpp:158
static constexpr value_type value
Definition integral_constant.hpp:34
Provides macros used to disable and enable compiler specific diagnostics using the _Pragma operator.
#define ARENE_IGNORE_END()
Ends a region of a suppressed diagnostic.
Definition diagnostics.hpp:136
#define ARENE_IGNORE_START()
Begins a region of a suppressed diagnostic.
Definition diagnostics.hpp:131
constexpr auto scaled(ScalingFactor scaling_factor, mdspan< ElementType, Extents, Layout, Accessor > original) noexcept(noexcept(scaled_detail::scaled_mdspan< mdspan< ElementType, Extents, Layout, Accessor >, ScalingFactor >{ original.data_handle(), original.mapping(), {scaling_factor, original.accessor()} })) -> scaled_detail::scaled_mdspan< mdspan< ElementType, Extents, Layout, Accessor >, ScalingFactor >
Return a version of the given mdspan instance that has an accessor which scales by scaling_factor.
Definition scaled_accessor.hpp:182
constexpr bool is_scalar_v
Determine if the given type is a scalar for the purposes of linalg algorithms.
Definition accumulate.hpp:37
constexpr bool is_accessor_policy_v
Check if a type is a valid accessor policy.
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
typename remove_const< Type >::type remove_const_t
remove const from the provided type. An alias for the modified type.
Definition remove_const.hpp:36