107#include <type_traits>
113#if ALEPH_HAS_STD_MDSPAN
120#if ALEPH_HAS_STD_MDSPAN
127template <
class IndexType,
size_t Rank>
128using dextents = std::dextents<IndexType, Rank>;
130using layout_right = std::layout_right;
131using layout_left = std::layout_left;
133template <
class ElementType>
134using default_accessor = std::default_accessor<ElementType>;
160 using impl_type = std::mdspan<T, Extents, LayoutPolicy, AccessorPolicy>;
164 template <
class,
class,
class,
class>
169 using layout_type =
typename impl_type::layout_type;
173 using value_type =
typename impl_type::value_type;
174 using index_type =
typename impl_type::index_type;
175 using rank_type =
typename impl_type::rank_type;
177 using reference =
typename impl_type::reference;
212 requires(
sizeof...(IndexTypes) >= 1
and
213 (std::is_convertible_v<IndexTypes, index_type>
and ...))
219 template <
class OtherIndexType>
220 requires std::is_convertible_v<const OtherIndexType &, index_type>
227 template <
class OtherT,
class OtherAccessor>
228 requires(
not std::is_same_v<OtherT, T>
and std::is_convertible_v<
OtherT (*)[],
T (*)[]>)
250 requires(
sizeof...(Indices) == extents_type::rank())
262 requires(
sizeof...(Indices) == extents_type::rank())
268 <<
"Aleph::mdspan::at(): index[" <<
r <<
"]=" << idx[
r] <<
" out of [0, "
282template <
size_t...
Exts>
304 static_assert(std::is_integral_v<IndexType>,
305 "Aleph::extents: IndexType must be an integral type");
307 static constexpr std::array<size_t,
sizeof...(Exts)>
Static{
Exts...};
322 return mdspan_detail::count_dynamic<
Exts...>;
342 requires(
sizeof...(IndexTypes) == mdspan_detail::count_dynamic<Exts...>
and
343 (std::is_convertible_v<IndexTypes, IndexType>
and ...))
357 template <
class OtherIndexType>
358 requires std::is_convertible_v<const OtherIndexType &, IndexType>
360 const std::array<
OtherIndexType, mdspan_detail::count_dynamic<Exts...>> &
dyn)
noexcept
376 return a.values_ == b.values_;
387 using type = extents<IndexType, ((void) Is, dynamic_extent)...>;
401template <
class IndexType,
size_t Rank>
403 typename decltype(mdspan_detail::dextents_of<IndexType>(
404 std::make_index_sequence<Rank>{}))::type;
414 template <
class Extents>
437 requires(
sizeof...(Indices) == Extents::rank())
468 template <
class Extents>
491 requires(
sizeof...(Indices) == Extents::rank())
524template <
class ElementType>
649 requires(
sizeof...(IndexTypes) >= 1
and
650 (std::is_convertible_v<IndexTypes, index_type>
and ...))
662 template <
class OtherIndexType>
663 requires std::is_convertible_v<const OtherIndexType &, index_type>
680 return map_.extents().extent(
r);
727 requires(
sizeof...(Indices) == extents_type::rank())
740 requires(
sizeof...(Indices) == extents_type::rank())
746 <<
"Aleph::mdspan::at(): index[" <<
r <<
"]=" << idx[
r] <<
" out of [0, "
C++20/23 compatibility layer: feature detection + Aleph:: polyfills.
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Shape (per-axis sizes) of an mdspan, mixing compile-time and run-time extents.
static constexpr rank_type rank_dynamic() noexcept
Number of axes whose extent is dynamic_extent (compile-time constant).
std::make_unsigned_t< IndexType > size_type
constexpr index_type extent(rank_type r) const noexcept
Run-time size of axis r.
static constexpr rank_type rank() noexcept
Number of axes (compile-time constant).
std::array< IndexType, sizeof...(Exts)> values_
constexpr extents(IndexTypes... dyn) noexcept
Construct providing a value for each dynamic axis, in rank order.
friend constexpr bool operator==(const extents &a, const extents &b) noexcept
static constexpr std::array< size_t, sizeof...(Exts)> Static
constexpr extents(const std::array< OtherIndexType, mdspan_detail::count_dynamic< Exts... > > &dyn) noexcept
Construct providing every dynamic axis's value packed in an array.
static constexpr size_t static_extent(rank_type r) noexcept
Compile-time size of axis r, or dynamic_extent if axis r is dynamic.
constexpr extents() noexcept
All-static-or-default-initialised extents (dynamic axes start at 0).
Mapping from column-major multi-indices to linear offsets.
constexpr index_type required_span_size() const noexcept
typename Extents::index_type index_type
static constexpr bool is_always_exhaustive() noexcept
typename Extents::rank_type rank_type
static constexpr bool is_always_unique() noexcept
static constexpr bool is_always_strided() noexcept
constexpr const extents_type & extents() const noexcept
constexpr mapping() noexcept=default
Mapping from row-major multi-indices to linear offsets.
static constexpr bool is_always_strided() noexcept
constexpr mapping() noexcept=default
static constexpr bool is_always_exhaustive() noexcept
constexpr index_type required_span_size() const noexcept
constexpr const extents_type & extents() const noexcept
typename Extents::index_type index_type
static constexpr bool is_always_unique() noexcept
typename Extents::rank_type rank_type
Non-owning view of a contiguous buffer as a multidimensional grid.
constexpr mdspan(data_handle_type p, const extents_type &e) noexcept
View p through the shape e.
static constexpr rank_type rank() noexcept
Number of axes (compile-time constant).
constexpr index_type extent(rank_type r) const noexcept
Run-time size of axis r.
constexpr mdspan(data_handle_type p, IndexTypes... exts) noexcept
View p as a grid with the given per-axis sizes.
typename accessor_type::reference reference
std::remove_cv_t< T > value_type
constexpr mdspan(data_handle_type p, const mapping_type &m, const accessor_type &a) noexcept
View p through mapping m, reading via accessor a.
typename extents_type::index_type index_type
constexpr const accessor_type & accessor() const noexcept
The element-access policy of this view.
constexpr mdspan(data_handle_type p, const std::array< OtherIndexType, extents_type::rank_dynamic()> &dyn) noexcept
View p as a grid whose dynamic axes are packed in an array.
constexpr mdspan() noexcept=default
Empty view: data_handle() == nullptr, every extent is 0.
constexpr data_handle_type data() const noexcept
typename accessor_type::data_handle_type data_handle_type
constexpr const mapping_type & mapping() const noexcept
The index-to-offset mapping (layout + shape) of this view.
constexpr data_handle_type data_handle() const noexcept
Underlying pointer to the first element (nullptr for a default-built view).
AccessorPolicy accessor_type
typename extents_type::rank_type rank_type
constexpr mdspan(data_handle_type p, const mapping_type &m) noexcept
View p through an already-built mapping.
constexpr reference at(Indices... idxs) const
Bounds-checked element access.
constexpr bool empty() const noexcept
Checks if the view has no elements.
typename layout_type::template mapping< extents_type > mapping_type
constexpr index_type size() const noexcept
Total element count: the product of every extent(r).
constexpr const extents_type & extents() const noexcept
The shape of this view.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
const long double offset[]
Offset values indexed by symbol string length (bounded by MAX_OFFSET_INDEX)
Main namespace for Aleph-w library functions.
constexpr size_t dynamic_extent
Sentinel marking an axis whose extent is only known at run time.
and
Check uniqueness with explicit hash + equality functors.
std::decay_t< typename HeadC::Item_Type > T
typename decltype(mdspan_detail::dextents_of< IndexType >(std::make_index_sequence< Rank >{}))::type dextents
extents<IndexType, ...> with all Rank axes dynamic — the common case.
Trivial accessor policy: access(p, i) is just p[i].
constexpr reference access(data_handle_type p, size_t i) const noexcept
Access an element from a pointer and an offset.
ElementType * data_handle_type
constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept
constexpr default_accessor() noexcept=default
Column-major layout: the first axis varies fastest (Fortran convention).
Row-major layout: the last axis varies fastest (C convention).
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)