diff --git a/c++/nda/layout/idx_map.hpp b/c++/nda/layout/idx_map.hpp index 1e297b28..50d1b960 100644 --- a/c++/nda/layout/idx_map.hpp +++ b/c++/nda/layout/idx_map.hpp @@ -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 len; + std::array len{}; // Strides of all dimensions. - std::array str; + std::array str{}; public: /// Encoded static extents. @@ -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 } } diff --git a/test/c++/nda_layout_idx_map.cpp b/test/c++/nda_layout_idx_map.cpp index e36f6b6f..accc1e20 100644 --- a/test/c++/nda_layout_idx_map.cpp +++ b/test/c++/nda_layout_idx_map.cpp @@ -33,6 +33,22 @@ std::array 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{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}};