Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
layout_constant_diagonal.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5// parasoft-suppress CERT_C-EXP37-a "False positive: there is no function named '()' in this header"
6#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_LAYOUT_CONSTANT_DIAGONAL_HPP_
7#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_LAYOUT_CONSTANT_DIAGONAL_HPP_
8
14#include "arene/base/mdspan/detail/representable_cast.hpp"
15#include "arene/base/mdspan/detail/to_array.hpp"
17#include "arene/base/stdlib_choice/cstddef.hpp"
18#include "arene/base/stdlib_choice/enable_if.hpp"
19#include "arene/base/stdlib_choice/integer_sequence.hpp"
20#include "arene/base/stdlib_choice/is_same.hpp"
22
23namespace arene {
24namespace base {
25namespace linalg {
26
27namespace layout_constant_diagonal_detail {
28
29/// @brief The maximum required span size for the underlying layout
30/// @tparam IndexType the type required
31template <typename IndexType>
32extern constexpr IndexType max_required_span_size{2};
33
34/// @brief Check if any extents are zero
35/// @tparam ExtentsType The type of the extents
36/// @tparam Indices The indices into the dimensions of the extents object
37/// @param extents The extents object
38/// @return @c true if any of @c extents.extent(Indices)... are zero, @c false otherwise
39template <typename ExtentsType, std::size_t... Indices>
40constexpr auto any_extents_are_zero(ExtentsType const& extents, std::index_sequence<Indices...>) noexcept -> bool {
41 return any_of({(extents.extent(Indices) == typename ExtentsType::index_type{})...});
42}
43
44/// @brief Check if any extents are zero
45/// @tparam ExtentsType The type of the extents
46/// @param extents The extents object
47/// @return @c true if any of @c extents.extent(Index) is zero for all values of @c Index in the range @c 0 to @c
48/// extents.rank()-1 , @c false otherwise
49template <typename ExtentsType>
50constexpr auto any_extents_are_zero(ExtentsType const& extents) noexcept -> bool {
51 return any_extents_are_zero(extents, std::make_index_sequence<ExtentsType::rank()>());
52}
53
54/// @brief Check if any static extents are zero
55/// @tparam ExtentsType The type of the extents
56/// @tparam Indices The indices into the dimensions of the extents object
57/// @return @c true if any of @c ExtentsType::static_extent(Indices)... are zero, @c false otherwise
58template <typename ExtentsType, std::size_t... Indices>
59constexpr auto any_static_extents_are_zero(std::index_sequence<Indices...>) noexcept -> bool {
60 return any_of({(ExtentsType::static_extent(Indices) == std::size_t{})...});
61}
62
63/// @brief Check if any static extents are zero
64/// @tparam ExtentsType The type of the extents
65/// @return @c true if any of @c ExtentsType::static_extent(Index) is zero for all values of @c Index in the range @c 0
66/// to
67/// @c ExtentsType::rank()-1 , @c false otherwise
68template <typename ExtentsType>
69constexpr auto any_static_extents_are_zero() noexcept -> bool {
70 return any_static_extents_are_zero<ExtentsType>(std::make_index_sequence<ExtentsType::rank()>());
71}
72
73/// @brief Check if the supplied set of extents and offsets is exhaustive
74///
75/// This handles the rank-1 layouts
76/// @tparam OffsetType The type of the offsets
77/// @tparam IndexType The type of the extents
78/// @param extents The array of extents
79/// @return @c true if the extent is zero, @c false otherwise
80///
81/// A rank-1 layout is treated as a full (1-D) diagonal matrix, so every index is on the diagonal and maps to slot 0. A
82/// non-empty layout therefore reports <c>required_span_size() == 2</c> while slot 1 is never referenced, so it is not
83/// exhaustive. Rank-reduced slices of a higher-rank diagonal matrix -- where a rank-1 view could sit off the diagonal
84/// -- are a separate layout
85template <typename OffsetType, typename IndexType>
86constexpr auto is_exhaustive(array<OffsetType, 1> const&, array<IndexType, 1> const& extents) noexcept -> bool {
87 return extents[0U] == IndexType{};
88}
89
90/// @brief Check if the supplied set of extents and offsets is exhaustive
91///
92/// This handles the layouts with a rank greater than 1
93/// @tparam OffsetType The type of the offsets
94/// @tparam IndexType The type of the extents
95/// @param offsets The array of offsets
96/// @param extents The array of extents
97/// @return @c true if any extent is zero, or if there is at least one dimension with an extent of two or more, no
98/// dimensions with an extent of zero, and there is at least one value of @c index for each dimension such that @c
99/// index+offset is the same for all dimensions, @c false otherwise
100template <typename OffsetType, typename IndexType, std::size_t Rank>
101constexpr auto is_exhaustive(array<OffsetType, Rank> const& offsets, array<IndexType, Rank> const& extents) noexcept
102 -> bool {
103 auto const dim_zero_extent = extents[0U];
104 if (dim_zero_extent == IndexType{}) {
105 return true;
106 }
107 bool has_exhaustive_extent{dim_zero_extent >= max_required_span_size<IndexType>};
108 IndexType min_overlap_position{mdspan_detail::representable_cast<IndexType>(offsets[0U])};
109 IndexType max_overlap_position{min_overlap_position + dim_zero_extent};
110 for (std::size_t index{1U}; index < Rank; ++index) {
111 auto const this_extent = extents[index];
112 if (this_extent == IndexType{}) {
113 return true;
114 }
115 if (this_extent >= max_required_span_size<IndexType>) {
116 has_exhaustive_extent = true;
117 }
118 IndexType const min_value_this_extent{mdspan_detail::representable_cast<IndexType>(offsets[index])};
119 IndexType const max_value_this_extent{min_value_this_extent + this_extent};
120 if (min_value_this_extent > min_overlap_position) {
121 min_overlap_position = min_value_this_extent;
122 }
123 if (max_value_this_extent < max_overlap_position) {
124 max_overlap_position = max_value_this_extent;
125 }
126 }
127 return (max_overlap_position > min_overlap_position) && has_exhaustive_extent;
128}
129} // namespace layout_constant_diagonal_detail
130
131/// @brief An @c mdspan layout mapping policy for a diagonal tensorlet.
132/// @tparam OffsetExtentsType An instantiation of @c extents which specifies the offset of the diagonal
133///
134/// Within the mapped layouts, the @c OffsetExtentsType determine where the diagonal is
135/// - For a rank 0 tensorlet, there are no offsets, and the one element is always on the diagonal
136/// - For a rank 1 tensorlet, all elements are on the diagonal
137/// - For a rank <c>N>=2</c> tensorlet, the diagonal is where all values of <c>index_n + offsets.extent(n)</c> are
138/// equal, where @c index_n is an index for dimension @c n, such that <c>index_n>=0</c> and <c>index_n <
139/// extents.extent(n)</c>
140template <typename OffsetExtentsType>
142 static_assert(is_extents_v<OffsetExtentsType>, "The offsets must be an instantiation of arene::base::extents");
143
144 /// @brief Tag type to use for selecting the extents instance held via @c ebo_holder
145 struct extents_tag {};
146 /// @brief Tag type to use for selecting the offsets instance held via @c ebo_holder
147 struct offsets_tag {};
148
149 public:
150 /// @brief An @c mdspan layout mapping for the specified @c ExtentsType
151 template <typename ExtentsType>
152 // parasoft-begin-suppress AUTOSAR-A10_1_1-a "Multiple base classes needed for empty-base-class optimizations."
153 // parasoft-begin-suppress AUTOSAR-A2_10_1 "False positive: There is no identifier 'mapping' being hidden"
155 // parasoft-end-suppress AUTOSAR-A2_10_1
156 // parasoft-end-suppress AUTOSAR-A10_1_1-a
157 : ebo_holder<extents_tag, ExtentsType>
158 , ebo_holder<offsets_tag, OffsetExtentsType> {
159 static_assert(is_extents_v<ExtentsType>, "The extents must be an instantiation of arene::base::extents");
160 // parasoft-begin-suppress CERT_C-PRE31-c-3 "False positive: static_assert is a compile-time assert"
161 static_assert(ExtentsType::rank() == OffsetExtentsType::rank(), "The offsets and extents must have the same rank");
162 // parasoft-end-suppress CERT_C-PRE31-c-3
163
164 /// @brief Base class for holding the extents
165 using extents_base = ebo_holder<extents_tag, ExtentsType>;
166
167 /// @brief Base class for holding the offsets
169
170 public:
171 /// @brief The type of the offsets
172 using offsets_type = OffsetExtentsType;
173 /// @brief The type of the extents
174 using extents_type = ExtentsType;
175 /// @brief The index type for the extents
176 using index_type = typename extents_type::index_type;
177 /// @brief The rank type for the extents
178 using rank_type = typename extents_type::rank_type;
179 /// @brief The layout mapping policy type for this mapping
181
182 private:
183 /// @brief The mapped index to return for an empty index list
184 /// @return Zero
185 // parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
186 static constexpr auto mapped_index(std::index_sequence<>) noexcept -> index_type { return 0; }
187 // parasoft-end-suppress CERT_C-EXP37-a
188
189 /// @brief The mapped index to return for a single index
190 /// @tparam FirstAccessIndex The type of the index
191 /// @return Zero; all elements in a rank-1 layout are on the "diagonal"
192 ///
193 /// @note This never returns 1, so slot 1 of the (size-2) span is unused; see the rank-1 @c is_exhaustive overload.
194 template <typename FirstAccessIndex>
195 static constexpr auto mapped_index(std::index_sequence<0>, FirstAccessIndex) noexcept -> index_type {
196 return index_type{};
197 }
198
199 /// @brief The mapped index to return for a list of indices
200 /// @tparam DimensionIndices The indices into the dimensions
201 /// @tparam FirstAccessIndex The type of the first index value
202 /// @tparam AccessIndices The type of the remaining index values
203 /// @param first_access_index The first index value supplied
204 /// @param access_indices The remaining index values supplied
205 /// @return Zero if the specified access indices are on the "diagonal" (all equal, when added to the corresponding
206 /// offsets), one otherwise
207 template <std::size_t... DimensionIndices, typename FirstAccessIndex, typename... AccessIndices>
208 constexpr auto mapped_index(
210 FirstAccessIndex first_access_index,
211 AccessIndices... access_indices
212 ) const noexcept -> index_type {
213 index_type const first_index{
214 mdspan_detail::representable_cast<index_type>(this->offsets().extent(0U)) +
215 mdspan_detail::representable_cast<index_type>(first_access_index) //
216 };
217 return all_of(
218 {((mdspan_detail::representable_cast<index_type>(this->offsets().extent(DimensionIndices)) +
219 mdspan_detail::representable_cast<index_type>(access_indices)) == first_index)...}
220 )
221 ? index_type{}
222 : index_type{1};
223 }
224
225 public:
226 /// @brief Construct the mapping with default-constructed extents and offsets
227 constexpr mapping() = default;
228
229 /// @brief Construct the mapping with the specified extents
230 /// @param source_extents the extents to use for this mapping
231 explicit constexpr mapping(extents_type const& source_extents) noexcept
232 : extents_base(source_extents),
233 offsets_base{} {}
234
235 /// @brief Construct the mapping with the specified extents and offsets
236 /// @param source_extents the extents to use for this mapping
237 /// @param offset_extents an extents object specifying the offsets to use for this mapping
238 constexpr mapping(extents_type const& source_extents, offsets_type const& offset_extents) noexcept
239 : extents_base(source_extents),
240 offsets_base(offset_extents) {}
241
242 /// @brief Default destructor
243 ~mapping() = default;
244
245 // parasoft-begin-suppress AUTOSAR-A12_8_6-a "False positive: this is not the base class of a hierarchy"
246 // parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
247 /// @brief Default copy constructor
248 mapping(mapping const&) = default;
249 /// @brief Default move constructor
250 mapping(mapping&&) = default;
251
252 /// @brief Default copy assignment operator
253 auto operator=(mapping const&) -> mapping& = default;
254 /// @brief Default move constructor
255 auto operator=(mapping&&) -> mapping& = default;
256 // parasoft-end-suppress CERT_C-EXP37-a
257 // parasoft-end-suppress AUTOSAR-A12_8_6-a
258
259 /// @brief The required span size for the underlying storage.
260 ///
261 /// This is 1 for a zero-rank @c mdspan since there is exactly one element
262 ///
263 /// @return 1
264 // parasoft-begin-suppress AUTOSAR-M9_3_3-a "Constrained overload of non-static member function"
265 template <
266 typename SfinaeExtentsType = ExtentsType,
269 std::enable_if_t<SfinaeExtentsType::rank() == 0>> = nullptr>
270 constexpr auto required_span_size() const noexcept -> index_type {
271 return index_type{1};
272 }
273 // parasoft-end-suppress AUTOSAR-M9_3_3-a
274
275 /// @brief The required span size for the underlying storage.
276 ///
277 /// This is 0 where any of the extents are statically zero
278 /// @return 0
279 // parasoft-begin-suppress AUTOSAR-M9_3_3-a "Constrained overload of non-static member function"
280 template <
281 typename SfinaeExtentsType = ExtentsType,
285 std::enable_if_t<SfinaeExtentsType::rank() != 0>> = nullptr>
286 constexpr auto required_span_size() const noexcept -> index_type {
287 return index_type{};
288 }
289 // parasoft-end-suppress AUTOSAR-M9_3_3-a
290
291 /// @brief The required span size for the underlying storage.
292 ///
293 /// This is 2 where all extents are statically non-zero
294 /// @return 2
295 // parasoft-begin-suppress AUTOSAR-M9_3_3-a "Constrained overload of non-static member function"
296 template <
297 typename SfinaeExtentsType = ExtentsType,
301 std::enable_if_t<SfinaeExtentsType::rank_dynamic() == 0>,
302 std::enable_if_t<SfinaeExtentsType::rank() != 0>> = nullptr>
303 constexpr auto required_span_size() const noexcept -> index_type {
304 return layout_constant_diagonal_detail::max_required_span_size<index_type>;
305 }
306 // parasoft-end-suppress AUTOSAR-M9_3_3-a
307
308 /// @brief The required span size for the underlying storage.
309 ///
310 /// This is 0 or 2 for a non-zero-rank @c mdspan : zero where any of the extents are zero, 2 otherwise (on diagonal
311 /// and off-diagonal)
312 /// @return 0 if any extent is zero, 2 otherwise
313 template <
314 typename SfinaeExtentsType = ExtentsType,
318 std::enable_if_t<SfinaeExtentsType::rank_dynamic() != 0>,
319 std::enable_if_t<SfinaeExtentsType::rank() != 0>> = nullptr>
320 constexpr auto required_span_size() const noexcept -> index_type {
321 if (layout_constant_diagonal_detail::any_extents_are_zero(extents())) {
322 return index_type{};
323 }
324 return layout_constant_diagonal_detail::max_required_span_size<index_type>;
325 }
326
327 /// @brief Check if this layout is exhaustive
328 ///
329 /// For rank zero layouts, this is always true
330 ///
331 /// @return @c true if exhaustive, @c false otherwise
332 // parasoft-begin-suppress AUTOSAR-M9_3_3-a "Constrained overload of non-static member function"
333 template <
334 typename SfinaeExtentsType = ExtentsType,
337 std::enable_if_t<SfinaeExtentsType::rank() == 0>> = nullptr>
338 constexpr auto is_exhaustive() const noexcept -> bool {
339 return true;
340 }
341 // parasoft-end-suppress AUTOSAR-M9_3_3-a
342
343 /// @brief Check if this layout is exhaustive
344 ///
345 /// This is always @c true for extents that have a dimension with a static extent of zero
346 ///
347 /// @return @c true if exhaustive, @c false otherwise
348 // parasoft-begin-suppress AUTOSAR-M9_3_3-a "Constrained overload of non-static member function"
349 template <
350 typename SfinaeExtentsType = ExtentsType,
354 std::enable_if_t<SfinaeExtentsType::rank() != 0>> = nullptr>
355 constexpr auto is_exhaustive() const noexcept -> bool {
356 return true;
357 }
358 // parasoft-end-suppress AUTOSAR-M9_3_3-a
359
360 /// @brief Check if this layout is exhaustive
361 ///
362 /// For non-rank-zero layouts, this depends on the extents and offsets: if there is at least one dimension with an
363 /// extent of two or more, no dimensions with an extent of zero, and there is at least one value of @c index for
364 /// each dimension such that @c index+offset is the same for all dimensions
365 ///
366 /// @return @c true if exhaustive, @c false otherwise
367 template <
368 typename SfinaeExtentsType = ExtentsType,
369 typename SfinaeOffsets = OffsetExtentsType,
373 std::enable_if_t<SfinaeExtentsType::rank_dynamic() == 0>,
374 std::enable_if_t<SfinaeOffsets::rank_dynamic() == 0>,
375 std::enable_if_t<SfinaeExtentsType::rank() != 0>> = nullptr>
376 constexpr auto is_exhaustive() const noexcept -> bool {
377 constexpr bool result = layout_constant_diagonal_detail::is_exhaustive(
378 mdspan_detail::to_array(OffsetExtentsType{}),
379 mdspan_detail::to_array(ExtentsType{})
380 );
381 return result;
382 }
383
384 /// @brief Check if this layout is exhaustive
385 ///
386 /// For non-rank-zero layouts, this depends on the extents and offsets: if there is at least one dimension with an
387 /// extent of two or more, no dimensions with an extent of zero, and there is at least one value of @c index for
388 /// each dimension such that @c index+offset is the same for all dimensions
389 ///
390 /// @return @c true if exhaustive, @c false otherwise
391 template <
392 typename SfinaeExtentsType = ExtentsType,
393 typename SfinaeOffsets = OffsetExtentsType,
397 std::enable_if_t<(SfinaeExtentsType::rank_dynamic() != 0) || (SfinaeOffsets::rank_dynamic() != 0)>,
398 std::enable_if_t<SfinaeExtentsType::rank() != 0>> = nullptr>
399 constexpr auto is_exhaustive() const noexcept -> bool {
400 return layout_constant_diagonal_detail::is_exhaustive(
401 mdspan_detail::to_array(offsets()),
402 mdspan_detail::to_array(this->extents())
403 );
404 }
405
406 /// @brief Check if there is exactly one index combination for each target element
407 ///
408 /// This must be the case of it returns @c true, may or not be the case if it returns @c false ; identifying all the
409 /// cases where it is @c true requires too much implementation complexity.
410 ///
411 /// @return @c true if conclusively so, @c false if not guaranteed
412 // parasoft-begin-suppress CERT_CPP-MSC52-a "False positive: There is a return statement with a value"
413 // parasoft-begin-suppress CERT_C-MSC37-a "False positive: There is a return statement with a value"
414 // parasoft-begin-suppress AUTOSAR-A8_4_2-a "False positive: There is a return statement with a value"
415 // parasoft-begin-suppress AUTOSAR-M9_3_3-a "False positive: This calls a non-static member function"
416 constexpr auto is_unique() const noexcept -> bool {
417 return required_span_size() < layout_constant_diagonal_detail::max_required_span_size<index_type>;
418 }
419 // parasoft-end-suppress AUTOSAR-A8_4_2-a
420 // parasoft-end-suppress AUTOSAR-M9_3_3-a
421 // parasoft-end-suppress CERT_C-MSC37-a
422 // parasoft-end-suppress CERT_CPP-MSC52-a
423
424 /// @brief Check if this is a strided layout, which it is not
425 /// @return @c false
426 static constexpr auto is_strided() noexcept -> bool { return false; }
427 /// @brief Check if this is always a strided layout, which it is not
428 /// @return @c false
429 static constexpr auto is_always_strided() noexcept -> bool { return false; }
430
431 /// @brief Get the stride for the provided dimension. Provided for interface compatibility only
432 /// @pre This function cannot be legitimately called
433 /// @return Never returns
434 // parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
435 constexpr auto stride(rank_type) const noexcept -> index_type {
437 return index_type{};
438 }
439 // parasoft-end-suppress CERT_C-EXP37-a
440
441 /// @brief Check if this is always a unique layout.
442 ///
443 /// Identifying all the cases where this is @c true requires too much implementation complexity, so this function
444 /// may return @c false even if the layout is always a unique layout.
445 ///
446 /// @return @c true if always unique, @c false if it may not be always unique
447 static constexpr auto is_always_unique() noexcept -> bool {
448 return (ExtentsType::rank() == 0U) || layout_constant_diagonal_detail::any_static_extents_are_zero<ExtentsType>();
449 }
450
451 /// @brief Check if this is always an exhaustive layout.
452 ///
453 /// This requires that all extents and offsets are static constants, and that the specific values give an exhaustive
454 /// layout
455 /// @return @c true if always unique, @c false otherwise
456 static constexpr auto is_always_exhaustive() noexcept -> bool {
457 return (ExtentsType::rank_dynamic() == 0U) && (OffsetExtentsType::rank_dynamic() == 0U) &&
458 mapping{}.is_exhaustive();
459 }
460
461 /// @brief Get the index from the underlying storage to use for the specified combination of indices
462 /// @tparam Indices The types of the indices
463 /// @param indices The indices to retrieve the mapped index for
464 /// @pre The number of elements in @c Indices must equal @c ExtentsType::rank()
465 /// @return The mapped index, which is 0 for values on the diagonal, 1 otherwise.
466 template <typename... Indices, constraints<std::enable_if_t<sizeof...(Indices) == ExtentsType::rank()>> = nullptr>
467 constexpr auto operator()(Indices... indices) const noexcept -> index_type {
468 return mapped_index(std::make_index_sequence<sizeof...(Indices)>(), indices...);
469 }
470
471 /// @brief Obtain the extents of the layout
472 /// @return The stored @c ExtentsType object
473 constexpr auto extents() const noexcept -> ExtentsType const& { return extents_base::get_value(extents_tag{}); }
474
475 /// @brief Obtain the offsets of the layout
476 /// @return The stored @c OffsetExtentsType object
477 constexpr auto offsets() const noexcept -> OffsetExtentsType const& {
478 return offsets_base::get_value(offsets_tag{});
479 }
480
481 /// @brief Equality comparison: two mappings are equal if they have the same offsets and extents
482 /// @param lhs The first mapping
483 /// @param rhs The second mapping
484 /// @return @c true if the mappings are the same, @c false otherwise
485 // parasoft-begin-suppress AUTOSAR-A7_1_5-a "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
486 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "False positive: comparison operators are permitted"
487 // parasoft-begin-suppress AUTOSAR-A0_1_3-a "False positive: This is an inline function used in multiple TUs"
488 friend constexpr auto operator==(mapping const& lhs, mapping const& rhs) noexcept -> bool {
489 return (lhs.extents() == rhs.extents()) && (lhs.offsets() == rhs.offsets());
490 }
491 // parasoft-end-suppress AUTOSAR-A0_1_3-a
492 // parasoft-end-suppress AUTOSAR-A11_3_1-a
493 // parasoft-end-suppress AUTOSAR-A7_1_5-a
494
495 /// @brief Inequality comparison: two mappings are not equal if they have the different offsets or extents
496 /// @param lhs The first mapping
497 /// @param rhs The second mapping
498 /// @return @c true if the mappings are not the same, @c false otherwise
499 // parasoft-begin-suppress AUTOSAR-A7_1_5-a "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
500 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "False positive: comparison operators are permitted"
501 // parasoft-begin-suppress AUTOSAR-A0_1_3-a "False positive: This is an inline function used in multiple TUs"
502 friend constexpr auto operator!=(mapping const& lhs, mapping const& rhs) noexcept -> bool { return !(lhs == rhs); }
503 // parasoft-end-suppress AUTOSAR-A0_1_3-a
504 // parasoft-end-suppress AUTOSAR-A11_3_1-a
505 // parasoft-end-suppress AUTOSAR-A7_1_5-a
506 };
507};
508
509} // namespace linalg
510} // namespace base
511} // namespace arene
512
513#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_LINALG_LAYOUT_CONSTANT_DIAGONAL_HPP_
constexpr ebo_holder() noexcept(std::is_nothrow_default_constructible< T >::value)
Definition ebo_holder.hpp:57
constexpr auto get_value(extents_tag) const &noexcept -> value_type const &
Definition ebo_holder.hpp:89
constexpr auto extents() const noexcept -> ExtentsType const &
Obtain the extents of the layout.
Definition layout_constant_diagonal.hpp:473
static constexpr auto is_always_exhaustive() noexcept -> bool
Check if this is always an exhaustive layout.
Definition layout_constant_diagonal.hpp:456
constexpr auto is_exhaustive() const noexcept -> bool
Check if this layout is exhaustive.
Definition layout_constant_diagonal.hpp:338
constexpr mapping()=default
Construct the mapping with default-constructed extents and offsets.
mapping(mapping const &)=default
Default copy constructor.
friend constexpr auto operator==(mapping const &lhs, mapping const &rhs) noexcept -> bool
Equality comparison: two mappings are equal if they have the same offsets and extents.
Definition layout_constant_diagonal.hpp:488
constexpr mapping(extents_type const &source_extents) noexcept
Construct the mapping with the specified extents.
Definition layout_constant_diagonal.hpp:231
mapping(mapping &&)=default
Default move constructor.
friend constexpr auto operator!=(mapping const &lhs, mapping const &rhs) noexcept -> bool
Inequality comparison: two mappings are not equal if they have the different offsets or extents.
Definition layout_constant_diagonal.hpp:502
constexpr auto stride(rank_type) const noexcept -> index_type
Get the stride for the provided dimension. Provided for interface compatibility only.
Definition layout_constant_diagonal.hpp:435
layout_constant_diagonal layout_type
The layout mapping policy type for this mapping.
Definition layout_constant_diagonal.hpp:180
constexpr auto is_exhaustive() const noexcept -> bool
Check if this layout is exhaustive.
Definition layout_constant_diagonal.hpp:376
static constexpr auto is_always_strided() noexcept -> bool
Check if this is always a strided layout, which it is not.
Definition layout_constant_diagonal.hpp:429
auto operator=(mapping const &) -> mapping &=default
Default copy assignment operator.
constexpr mapping(extents_type const &source_extents, offsets_type const &offset_extents) noexcept
Construct the mapping with the specified extents and offsets.
Definition layout_constant_diagonal.hpp:238
static constexpr auto is_strided() noexcept -> bool
Check if this is a strided layout, which it is not.
Definition layout_constant_diagonal.hpp:426
typename extents_type::rank_type rank_type
The rank type for the extents.
Definition layout_constant_diagonal.hpp:178
ExtentsType extents_type
The type of the extents.
Definition layout_constant_diagonal.hpp:174
constexpr auto required_span_size() const noexcept -> index_type
The required span size for the underlying storage.
Definition layout_constant_diagonal.hpp:270
OffsetExtentsType offsets_type
The type of the offsets.
Definition layout_constant_diagonal.hpp:172
auto operator=(mapping &&) -> mapping &=default
Default move constructor.
typename extents_type::index_type index_type
The index type for the extents.
Definition layout_constant_diagonal.hpp:176
constexpr auto offsets() const noexcept -> OffsetExtentsType const &
Obtain the offsets of the layout.
Definition layout_constant_diagonal.hpp:477
static constexpr auto is_always_unique() noexcept -> bool
Check if this is always a unique layout.
Definition layout_constant_diagonal.hpp:447
constexpr auto operator()(Indices... indices) const noexcept -> index_type
Get the index from the underlying storage to use for the specified combination of indices.
Definition layout_constant_diagonal.hpp:467
constexpr auto is_unique() const noexcept -> bool
Check if there is exactly one index combination for each target element.
Definition layout_constant_diagonal.hpp:416
An mdspan layout mapping policy for a diagonal tensorlet.
Definition layout_constant_diagonal.hpp:141
A sum type which can hold either a value or an error. Similar to std::expected.
Definition result.hpp:104
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Definition add.hpp:20
Definition accumulate.hpp:37
constexpr std::integral_constant< std::size_t, Extent > span< T, Extent >::extent
Definition span.hpp:984
constexpr bool is_extents_v
Helper variable to check if a provided type is an instantiation of extents.
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
make_integer_sequence< size_t, Size > make_index_sequence
A helper alias template for make_integer_sequence<size_t, Size>
Definition integer_sequence.hpp:224
integer_sequence< size_t, Ints... > index_sequence
A helper alias template for integer_sequence<size_t, Ints>
Definition integer_sequence.hpp:218
::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