Skip to content

Commit

Permalink
Change the default shape and strides of idx_map
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoemi09 authored and Wentzell committed Sep 23, 2024
1 parent d480d4a commit 00193a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 2 additions & 5 deletions c++/nda/layout/idx_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ namespace nda {
static_assert((StrideOrder != 0) or (Rank == 1), "Error in nda::idx_map: StrideOrder can only be zero for 1D arrays");

// Extents of all dimensions (the shape of the map).
std::array<long, Rank> len;
std::array<long, Rank> len{};

// Strides of all dimensions.
std::array<long, Rank> str;
std::array<long, Rank> str{};

public:
/// Encoded static extents.
Expand Down Expand Up @@ -319,9 +319,6 @@ namespace nda {
if constexpr (n_dynamic_extents == 0) {
for (int u = 0; u < Rank; ++u) len[u] = static_extents[u];
compute_strides_contiguous();
} else {
for (int u = 0; u < Rank; ++u)
len[u] = 0; // FIXME. Needed ? To have the proper invariant of the array : shape = (0,0,...) and pointer is null
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/c++/nda_layout_idx_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ std::array<long, sizeof...(Is)> make_array(Is... is) {
return {is...};
}

TEST(NDA, IdxMapDefaultConstructed) {
// default constructed 3D index map in C-order
idx_map<3, 0, C_stride_order<3>, layout_prop_e::none> idxm{};
EXPECT_EQ(idxm.rank(), 3);
EXPECT_EQ(idxm.size(), 0);
EXPECT_EQ(idxm.ce_size(), 0);
EXPECT_EQ(idxm.lengths(), make_array(0, 0, 0));
EXPECT_EQ(idxm.strides(), make_array(0, 0, 0));
EXPECT_EQ(idxm.stride_order, (std::array<int, 3>{0, 1, 2}));
EXPECT_TRUE(idxm.is_contiguous());
EXPECT_TRUE(idxm.is_strided_1d());
EXPECT_TRUE(idxm.has_positive_strides());
EXPECT_TRUE(idxm.is_stride_order_C());
EXPECT_TRUE(idxm.is_stride_order_valid());
}

TEST(NDA, IdxMapContiguousCOrder) {
// contiguous 2x3x4 index map in C-order
idx_map<3, 0, C_stride_order<3>, layout_prop_e::contiguous> idxm{{2, 3, 4}};
Expand Down

0 comments on commit 00193a1

Please sign in to comment.