48 template <
int Rank, u
int64_t StaticExtents, u
int64_t Str
ideOrder, layout_prop_e LayoutProp>
56 struct rect_str_from_base;
59 template <
int Rank, u
int64_t StaticExtents, u
int64_t Str
ideOrder, layout_prop_e LayoutProp>
60 struct rect_str_from_base<idx_map<Rank, StaticExtents, StrideOrder, LayoutProp>> {
62 using type = rect_str<Rank, StaticExtents, StrideOrder, LayoutProp>;
78 template <
int Rank, u
int64_t StaticExtents, u
int64_t Str
ideOrder, layout_prop_e LayoutProp>
87 mutable std::shared_ptr<ind_t const> s_indices;
93 static std::array<long, Rank> make_shape_from_string_indices(
ind_t const &str_indices) {
94 if (str_indices.
size() != Rank)
95 NDA_RUNTIME_ERROR <<
"Error in rect_str::make_shape_from_string_indices: String indices do not have the correct rank";
96 std::array<long, Rank> sha;
97 for (
int i = 0; i < Rank; ++i) sha[i] = str_indices[i].
size();
113 auto ind =
ind_t(Rank);
114 for (
int i = 0; i < Rank; ++i) {
117 ind(i) = std::move(a);
119 s_indices = std::make_shared<ind_t>(std::move(ind));
125 template <
typename T>
129 template <
typename T>
153 rect_str(
base_t const &idxm,
ind_t const &str_indices) noexcept :
base_t{idxm}, s_indices{std::make_shared<ind_t>(std::move(str_indices))} {}
161 template <layout_prop_e LP>
163 :
base_t{rstr}, s_indices{std::make_shared<ind_t>(rstr.get_string_indices())} {}
172 template <u
int64_t SE, layout_prop_e LP>
195 :
base_t{make_shape_from_string_indices(str_indices)}, s_indices{std::make_shared<
ind_t>(std::move(str_indices))} {}
202 rect_str(std::array<long, base_t::n_dynamic_extents>
const &shape)
noexcept
220 template <
typename T>
221 auto peel_string(
int pos, T
const &arg)
const {
222 if constexpr (not std::is_constructible_v<std::string, T>)
228 auto const &idx = sind[pos];
229 auto it = std::find(idx.begin(), idx.end(), arg);
230 if (it == idx.end()) NDA_RUNTIME_ERROR <<
"Error in nda::rect_str: Key " << arg <<
" at position " << pos <<
" does not match an index";
231 return it - idx.begin();
236 template <
typename... Args,
size_t... Is>
237 [[nodiscard]] FORCEINLINE
long call_impl(std::index_sequence<Is...>, Args... args)
const {
252 template <
typename... Args>
254 return call_impl(std::make_index_sequence<
sizeof...(Args)>{}, args...);
259 template <
typename... Args,
auto... Is>
260 FORCEINLINE
decltype(
auto) slice_impl(std::index_sequence<Is...>, Args
const &...args)
const {
262 auto const [offset, idxm2] =
base_t::slice(peel_string(Is, args)...);
265 using new_rect_str_t =
typename detail::rect_str_from_base<std::decay_t<
decltype(idxm2)>>::type;
268 if (not s_indices)
return std::make_pair(offset, new_rect_str_t{idxm2});
273 auto add_string_indices = [p = 0, ¤t_ind, &ind2](
int n,
auto const &y)
mutable ->
void {
274 using U = std::decay_t<
decltype(y)>;
277 (add_string_indices(Is, args), ...);
279 return std::make_pair(offset, new_rect_str_t{idxm2, ind2});
294 template <
typename... Args>
295 auto slice(Args
const &...args)
const {
296 return slice_impl(std::make_index_sequence<
sizeof...(args)>{}, args...);
306 return base_t::operator==(rhs) and (!s_indices or !rhs.s_indices or (*s_indices == *(rhs.s_indices)));
331 template <u
int64_t Permutation>
337 using new_rect_str_t =
typename detail::rect_str_from_base<std::decay_t<
decltype(idxm2)>>::type;
340 if (not s_indices)
return new_rect_str_t{idxm2};
343 ind_t ind2(s_indices->size());
344 static constexpr std::array<int, Rank> permu =
decode<Rank>(Permutation);
345 for (
int u = 0; u < Rank; ++u) { ind2[permu[u]] = (*s_indices)[u]; }
346 return new_rect_str_t{idxm2, ind2};
359 struct C_stride_layout_str;
360 struct F_stride_layout_str;
434 template <u
int64_t StaticExtents, u
int64_t Str
ideOrder, layout_prop_e LayoutProp>
451 template <
int Rank, u
int64_t StaticExtents, u
int64_t Str
ideOrder, layout_prop_e LayoutProp>
452 struct layout_to_policy<
rect_str<Rank, StaticExtents, StrideOrder, LayoutProp>> {
459 using type = C_layout_str;
465 using type = C_stride_layout_str;
Provides the generic class for arrays.
Provides basic functions to create and manipulate arrays and views.
A generic multi-dimensional array.
long size() const noexcept
Get the total size of the view/array.
Layout that specifies how to map multi-dimensional indices to a linear/flat index.
__inline__ long operator()(Args const &...args) const noexcept(true)
Function call operator to map a given multi-dimensional index to a linear index.
long size() const noexcept
Get the total number of elements.
bool operator==(idx_map< R, SE, SO, LP > const &rhs) const
Equal-to operator for two nda::idx_map objects.
static constexpr int n_dynamic_extents
Number of dynamic dimensions/extents.
std::array< long, Rank > const & lengths() const noexcept
Get the extents of all dimensions.
auto slice(Args const &...args) const
Get a new nda::idx_map by taking a slice of the current one.
std::array< long, Rank > const & strides() const noexcept
Get the strides of all dimensions.
Layout that specifies how to map multi-dimensional indices including possible string indices to a lin...
__inline__ long operator()(Args const &...args) const
Function call operator to map a given multi-dimensional index to a linear index.
bool operator!=(rect_str const &rhs)
Not-equal-to operator for two nda::rect_str objects.
rect_str(std::array< long, Rank > const &shape) noexcept
Construct an nda::rect_str from a given shape and with contiguous strides.
rect_str(rect_str< Rank, StaticExtents, StrideOrder, LP > const &rstr) noexcept
Construct an nda::rect_str from another nda::rect_str with different layout properties.
rect_str & operator=(rect_str &&)=default
Default move assignment operator.
rect_str(nda::array< nda::array< std::string, 1 >, 1 > str_indices) noexcept(false)
Construct an nda::rect_str from given string indices and with contiguous strides.
rect_str(rect_str< Rank, SE, StrideOrder, LP > const &rstr) noexcept(false)
Construct an nda::rect_str from another nda::rect_str with different layout properties and static ext...
auto slice(Args const &...args) const
Get a new nda::rect_str by taking a slice of the current one.
rect_str & operator=(rect_str const &)=default
Default copy assignment operator.
static constexpr int argument_is_allowed_for_call_or_slice
Alias template to check if type T can be used to either access a specific element or a slice of eleme...
static constexpr int argument_is_allowed_for_call
Alias template to check if type T can be used to access a specific element.
rect_str(base_t const &idxm) noexcept
Construct an nda::rect_str from a given nda::idx_map.
bool operator==(rect_str const &rhs) const
Equal-to operator for two nda::rect_str objects.
rect_str(std::array< long, base_t::n_dynamic_extents > const &shape) noexcept
Construct an nda::rect_str from an array with its dynamic extents.
rect_str(rect_str const &)=default
Default copy constructor.
rect_str(rect_str &&)=default
Default move constructor.
rect_str(std::array< long, Rank > const &shape, std::array< long, Rank > const &strides) noexcept
Construct an nda::rect_str from a given shape and strides.
rect_str()=default
Default constructor.
auto const & get_string_indices() const
Get the string indices.
auto transpose() const
Create a new nda::rect_str by permuting the indices/dimensions with a given permutation.
rect_str(base_t const &idxm, ind_t const &str_indices) noexcept
Construct an nda::rect_str from a given nda::idx_map and string indices.
Provides various convenient aliases and helper functions for nda::basic_array and nda::basic_array_vi...
Provides a custom runtime error class and macros to assert conditions and throw exceptions.
basic_array< ValueType, Rank, Layout, 'A', ContainerPolicy > array
Alias template of an nda::basic_array with an 'A' algebra.
constexpr uint64_t C_stride_order
C/Row-major stride order.
layout_prop_e
Compile-time guarantees of the memory layout of an array/view.
constexpr std::array< int, N > decode(uint64_t binary_representation)
Decode a uint64_t into a std::array<int, N>.
std::string to_string(std::array< T, R > const &a)
Get a string representation of a std::array.
Provides a class that maps multi-dimensional indices to a linear index and vice versa.
Provides definitions of various layout policies.
Contiguous layout policy with C-order (row-major order) and possible string indices.
Strided (non-contiguous) layout policy with C-order (row-major order) and possible string indices.
Contiguous layout policy with Fortran-order (column-major order) and possible string indices.
Strided (non-contiguous) layout policy with Fortran-order (column-major order) and possible string in...
Generic layout policy with arbitrary order and possible string indices.
Provides type traits for the nda library.