Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Add LevelProperty public attribute to all the levels #22

Merged
merged 9 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/xsparse/levels/compressed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ namespace xsparse
LevelProperties>;

public:
// Function to access the LevelProperties object
adam2392 marked this conversation as resolved.
Show resolved Hide resolved
constexpr LevelProperties LevelProperty() const
{
return LevelProperties{};
}

compressed(IK size)
: m_size(std::move(size))
, m_pos()
Expand Down
7 changes: 7 additions & 0 deletions include/xsparse/levels/dense.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace xsparse
static_assert(LevelProperties::is_full);
static_assert(!LevelProperties::is_branchless);
static_assert(LevelProperties::is_compact);
static_assert(LevelProperties::is_ordered);

public:
using LevelCapabilities
Expand All @@ -40,6 +41,12 @@ namespace xsparse
= util::base_traits<dense, std::tuple<LowerLevels...>, IK, PK, LevelProperties>;

public:
// Function to access the LevelProperties object
constexpr LevelProperties LevelProperty() const
{
return LevelProperties{};
}

dense(IK size)
: m_size(std::move(size))
{
Expand Down
6 changes: 6 additions & 0 deletions include/xsparse/levels/hashed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ namespace xsparse
return iteration_helper{ this->m_crd[pkm1] };
}

// Function to access the LevelProperties object
constexpr LevelProperties LevelProperty() const
{
return LevelProperties{};
}

hashed(IK size)
: m_size(std::move(size))
, m_crd()
Expand Down
6 changes: 6 additions & 0 deletions include/xsparse/levels/offset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ namespace xsparse
{
}

// Function to access the LevelProperties object
constexpr LevelProperties LevelProperty() const
{
return LevelProperties{};
}

inline std::pair<PK, PK> pos_bounds(typename BaseTraits::PKM1 pkm1) const noexcept
{
return { static_cast<PK>(pkm1), static_cast<PK>(pkm1 + 1) };
Expand Down
6 changes: 6 additions & 0 deletions include/xsparse/levels/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ namespace xsparse
{
}

// Function to access the LevelProperties object
constexpr LevelProperties LevelProperty() const
{
return LevelProperties{};
}

inline std::pair<IK, IK> coord_bounds(typename BaseTraits::I i) const noexcept
{
static_assert(std::tuple_size_v<decltype(i)> >= 1,
Expand Down
6 changes: 6 additions & 0 deletions include/xsparse/levels/singleton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ namespace xsparse
{
}

// Function to access the LevelProperties object
constexpr LevelProperties LevelProperty() const
{
return LevelProperties{};
}

inline std::pair<PK, PK> pos_bounds(typename BaseTraits::PKM1 pkm1) const noexcept
{
return { static_cast<PK>(pkm1), static_cast<PK>(pkm1 + 1) };
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include(../cmake/tools.cmake)

include(../cmake/CPM.cmake)

CPMAddPackage("gh:doctest/doctest@2.4.9")
CPMAddPackage("gh:doctest/doctest#v2.4.11")
CPMAddPackage("gh:TheLartians/Format.cmake@1.7.3")

if(TEST_INSTALLED_VERSION)
Expand Down
7 changes: 7 additions & 0 deletions test/source/compressed_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ TEST_CASE("Compressed-BaseCase")
++l;
}
CHECK(l == pos.back());

// Check basic strict properties of all compressed levels
// CHECK(s.LevelProperty().is_full);
// CHECK(s.LevelProperty().is_ordered);
// CHECK(s.LevelProperty().is_unique);
CHECK(!s.LevelProperty().is_branchless);
CHECK(s.LevelProperty().is_compact);
}

TEST_CASE("Compressed-CSR")
Expand Down
9 changes: 7 additions & 2 deletions test/source/dense_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ TEST_CASE("Dense-BaseCase")
++loop;
}
CHECK(loop == SIZE);

// Check basic strict properties of all dense levels
CHECK(d.LevelProperty().is_full);
adam2392 marked this conversation as resolved.
Show resolved Hide resolved
CHECK(!d.LevelProperty().is_branchless);
CHECK(d.LevelProperty().is_compact);
}

TEST_CASE("Dense-2D")
Expand All @@ -32,7 +37,7 @@ TEST_CASE("Dense-2D")
xsparse::levels::dense<std::tuple<>,
uintptr_t,
uintptr_t,
xsparse::level_properties<true, false, false, false, true>>
xsparse::level_properties<true, true, false, false, true>>
d1{ SIZE1 };
xsparse::levels::dense<std::tuple<decltype(d1)>, uintptr_t, uintptr_t> d2{ SIZE2 };

Expand Down Expand Up @@ -65,7 +70,7 @@ TEST_CASE("Dense-2D-Size")
xsparse::levels::dense<std::tuple<decltype(d1)>,
uintptr_t,
uintptr_t,
xsparse::level_properties<true, false, true, false, true>>
xsparse::level_properties<true, true, true, false, true>>
d2{ SIZE2 };

uintptr_t l1 = 0;
Expand Down
33 changes: 33 additions & 0 deletions test/source/hashed_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,39 @@
#include <unordered_map>
#include <set>

TEST_CASE("Hashed-BaseCase")
{
constexpr uintptr_t SIZE0 = 3;
constexpr uint8_t ZERO = 0;

std::unordered_map<uintptr_t, uintptr_t> const umap1{ { 5, 2 }, { 6, 1 }, { 4, 0 } };
std::vector<std::unordered_map<uintptr_t, uintptr_t>> const crd{ umap1 };

xsparse::levels::hashed<
std::tuple<>,
uintptr_t,
uintptr_t,
xsparse::util::container_traits<std::vector, std::set, std::unordered_map>,
xsparse::level_properties<false, false, false, false, false>>
h{ SIZE0, crd };

// check iterating through a hashed level
uintptr_t l2 = 0;
for (auto const [i2, p2] : h.iter_helper(ZERO))
{
CHECK(crd[0].at(i2) == p2);
++l2;
}
CHECK(l2 == crd[0].size());

// Check basic stric properties of all hashed levels
// CHECK(!h.LevelProperty().is_full);
CHECK(!h.LevelProperty().is_ordered);
// CHECK(!h.LevelProperty().is_unique);
CHECK(!h.LevelProperty().is_branchless);
CHECK(!h.LevelProperty().is_compact);
}

TEST_CASE("Dense-Hashed")
{
constexpr uintptr_t SIZE0 = 3;
Expand Down
15 changes: 15 additions & 0 deletions test/source/range_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <iostream>


TEST_CASE("Range-DIA")
{
constexpr uintptr_t SIZE = 4;
Expand Down Expand Up @@ -47,4 +48,18 @@ TEST_CASE("Range-DIA")
++l1;
}
CHECK(l1 == SIZE);

// Check basic stric properties of all range levels
CHECK(!r.LevelProperty().is_full);
// CHECK(r.LevelProperty().is_ordered);
// CHECK(r.LevelProperty().is_unique);
CHECK(!r.LevelProperty().is_branchless);
CHECK(!r.LevelProperty().is_compact);

// Check basic properties of all offset levels
CHECK(!o.LevelProperty().is_full);
// CHECK(o.LevelProperty().is_ordered);
// CHECK(o.LevelProperty().is_unique);
CHECK(o.LevelProperty().is_branchless);
CHECK(!o.LevelProperty().is_compact);
}
25 changes: 25 additions & 0 deletions test/source/singleton_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@
#include <xsparse/util/container_traits.hpp>
#include <xsparse/level_properties.hpp>


TEST_CASE("Singleton-BaseCase")
{
constexpr uintptr_t SIZE = 20;
constexpr uint8_t ZERO = 0;
std::vector<uintptr_t> const crd1{ 0, 1, 0, 1, 0, 3, 4 };

xsparse::levels::singleton<std::tuple<>, uintptr_t, uintptr_t> s{ SIZE, crd1 };

uintptr_t l2 = 0;
for (auto const [i2, p2] : s.iter_helper(std::make_tuple(), ZERO))
{
CHECK(l2 == p2);
CHECK(crd1[l2] == i2);
++l2;
}

// Check basic stric properties of all singleton levels
// CHECK(s.LevelProperty().is_full);
// CHECK(s.LevelProperty().is_ordered);
// CHECK(s.LevelProperty().is_unique);
CHECK(s.LevelProperty().is_branchless);
CHECK(s.LevelProperty().is_compact);
}

TEST_CASE("Singleton-COO")
{
constexpr uintptr_t SIZE = 100;
Expand Down