Skip to content

Commit

Permalink
Change Size -> size mem fn
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed Oct 29, 2023
1 parent 9a488f7 commit 97777b8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 65 deletions.
14 changes: 7 additions & 7 deletions include/vect16.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace HPCombi {

struct alignas(16) Vect16 {
static constexpr size_t Size() { return 16; }
static constexpr size_t size() { return 16; }
using array = decltype(Epu8)::array;
epu8 v;

Expand All @@ -46,23 +46,23 @@ struct alignas(16) Vect16 {
const uint8_t &operator[](uint64_t i) const { return as_array()[i]; }
uint8_t &operator[](uint64_t i) { return as_array()[i]; }

size_t first_diff(const Vect16 &u, size_t bound = Size()) const {
size_t first_diff(const Vect16 &u, size_t bound = size()) const {
return HPCombi::first_diff(v, u.v, bound);
}
size_t last_diff(const Vect16 &u, size_t bound = Size()) const {
size_t last_diff(const Vect16 &u, size_t bound = size()) const {
return HPCombi::last_diff(v, u.v, bound);
}

size_t first_zero(size_t bound = Size()) const {
size_t first_zero(size_t bound = size()) const {
return HPCombi::first_zero(v, bound);
}
size_t last_zero(size_t bound = Size()) const {
size_t last_zero(size_t bound = size()) const {
return HPCombi::last_zero(v, bound);
}
size_t first_non_zero(size_t bound = Size()) const {
size_t first_non_zero(size_t bound = size()) const {
return HPCombi::first_non_zero(v, bound);
}
size_t last_non_zero(size_t bound = Size()) const {
size_t last_non_zero(size_t bound = size()) const {
return HPCombi::last_non_zero(v, bound);
}

Expand Down
2 changes: 1 addition & 1 deletion include/vect_generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std::array<Expo, Size> sorted_vect(std::array<Expo, Size> v) {
/** A generic class for combinatorial integer vectors.
*/
template <size_t _Size, typename Expo = uint8_t> struct VectGeneric {
static constexpr size_t Size() { return _Size; }
static constexpr size_t size() { return _Size; }
using array = std::array<Expo, _Size>;
array v;

Expand Down
110 changes: 53 additions & 57 deletions tests/test_perm_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ template <class Perm_> struct Fixture1 {
const std::vector<VectType> Vlist;

// some tests assume that the size is at least 6
static_assert(VectType::Size() >= 6, "Minimum size for tests");
static_assert(VectType::size() >= 6, "Minimum size for tests");
};

} // namespace
Expand All @@ -61,8 +61,8 @@ template <class Perm_> struct Fixture1 {

TEMPLATE_TEST_CASE_METHOD(Fixture1, "sizeof", "[PermAll][000]", PermTypes) {
CHECK(sizeof(Fixture1<TestType>::zero) ==
Fixture1<TestType>::VectType::Size() *
sizeof(Fixture1<TestType>::zero[0]));
Fixture1<TestType>::VectType::size() *
sizeof(Fixture1<TestType>::zero[0]));
}

TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator==", "[PermAll][001]", PermTypes) {
Expand All @@ -72,10 +72,10 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator==", "[PermAll][001]", PermTypes) {
for (unsigned j = 0; j < Fixture1<TestType>::Plist.size(); j++) {
if (i == j) {
CHECK(Fixture1<TestType>::Plist[i] ==
Fixture1<TestType>::Plist[j]);
Fixture1<TestType>::Plist[j]);
} else {
CHECK(Fixture1<TestType>::Plist[i] !=
Fixture1<TestType>::Plist[j]);
Fixture1<TestType>::Plist[j]);
}
}
}
Expand All @@ -85,10 +85,10 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator[] const", "[PermAll][002]",
PermTypes) {
CHECK(Fixture1<TestType>::czero[0] == 0u);
CHECK(Fixture1<TestType>::czero[1] == 0u);
if (Fixture1<TestType>::czero.Size() > 12) {
if (Fixture1<TestType>::czero.size() > 12) {
CHECK(Fixture1<TestType>::czero[12] == 0u);
}
if (Fixture1<TestType>::czero.Size() > 15) {
if (Fixture1<TestType>::czero.size() > 15) {
CHECK(Fixture1<TestType>::czero[15] == 0u);
}
CHECK(Fixture1<TestType>::cV01[0] == 0u);
Expand All @@ -99,10 +99,10 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator[] const", "[PermAll][002]",
TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator[]", "[PermAll][003]", PermTypes) {
CHECK(Fixture1<TestType>::zero[0] == 0u);
CHECK(Fixture1<TestType>::zero[1] == 0u);
if (Fixture1<TestType>::czero.Size() > 12) {
if (Fixture1<TestType>::czero.size() > 12) {
CHECK(Fixture1<TestType>::zero[12] == 0u);
}
if (Fixture1<TestType>::czero.Size() > 15) {
if (Fixture1<TestType>::czero.size() > 15) {
CHECK(Fixture1<TestType>::zero[15] == 0u);
}
CHECK(Fixture1<TestType>::V01[0] == 0u);
Expand All @@ -113,10 +113,10 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator[]", "[PermAll][003]", PermTypes) {
Fixture1<TestType>::zero[0] = 3;
CHECK(Fixture1<TestType>::zero[0] == 3u);
CHECK(Fixture1<TestType>::zero[1] == 0u);
if (Fixture1<TestType>::czero.Size() > 12) {
if (Fixture1<TestType>::czero.size() > 12) {
CHECK(Fixture1<TestType>::zero[12] == 0u);
}
if (Fixture1<TestType>::czero.Size() > 15) {
if (Fixture1<TestType>::czero.size() > 15) {
CHECK(Fixture1<TestType>::zero[15] == 0u);
}
Fixture1<TestType>::PPa[2] = 0;
Expand All @@ -130,10 +130,10 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator<", "[AllPerm][004]", PermTypes) {
for (unsigned j = 0; j < Fixture1<TestType>::Plist.size(); j++) {
if (i < j) {
CHECK(Fixture1<TestType>::Plist[i] <
Fixture1<TestType>::Plist[j]);
Fixture1<TestType>::Plist[j]);
} else {
CHECK(!(Fixture1<TestType>::Plist[i] <
Fixture1<TestType>::Plist[j]));
Fixture1<TestType>::Plist[j]));
}
}
}
Expand All @@ -153,37 +153,33 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "less_partial", "[AllPerm][005]",
}

CHECK(Fixture1<TestType>::zero.less_partial(Fixture1<TestType>::V01, 1) ==
0);
0);
CHECK(Fixture1<TestType>::V01.less_partial(Fixture1<TestType>::zero, 1) ==
0);
0);
CHECK(Fixture1<TestType>::zero.less_partial(Fixture1<TestType>::V01, 2) <
0);
0);
CHECK(Fixture1<TestType>::V01.less_partial(Fixture1<TestType>::zero, 2) >
0);
0);

CHECK(Fixture1<TestType>::zero.less_partial(Fixture1<TestType>::V10, 1) <
0);
0);
CHECK(Fixture1<TestType>::zero.less_partial(Fixture1<TestType>::V10, 2) <
0);
0);
CHECK(Fixture1<TestType>::V10.less_partial(Fixture1<TestType>::zero, 1) >
0);
0);
CHECK(Fixture1<TestType>::V10.less_partial(Fixture1<TestType>::zero, 2) >
0);
0);

CHECK(Fixture1<TestType>::PPa.less_partial(Fixture1<TestType>::PPb, 1) ==
0);
0);
CHECK(Fixture1<TestType>::PPa.less_partial(Fixture1<TestType>::PPb, 2) ==
0);
0);
CHECK(Fixture1<TestType>::PPa.less_partial(Fixture1<TestType>::PPb, 3) ==
0);
CHECK(Fixture1<TestType>::PPa.less_partial(Fixture1<TestType>::PPb, 4) <
0);
CHECK(Fixture1<TestType>::PPa.less_partial(Fixture1<TestType>::PPb, 5) <
0);
CHECK(Fixture1<TestType>::PPb.less_partial(Fixture1<TestType>::PPa, 4) >
0);
CHECK(Fixture1<TestType>::PPb.less_partial(Fixture1<TestType>::PPa, 5) >
0);
0);
CHECK(Fixture1<TestType>::PPa.less_partial(Fixture1<TestType>::PPb, 4) < 0);
CHECK(Fixture1<TestType>::PPa.less_partial(Fixture1<TestType>::PPb, 5) < 0);
CHECK(Fixture1<TestType>::PPb.less_partial(Fixture1<TestType>::PPa, 4) > 0);
CHECK(Fixture1<TestType>::PPb.less_partial(Fixture1<TestType>::PPa, 5) > 0);
}

TEMPLATE_TEST_CASE_METHOD(Fixture1, "first_zero", "[AllPerm][006]", PermTypes) {
Expand All @@ -192,76 +188,76 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "first_zero", "[AllPerm][006]", PermTypes) {
CHECK(Fixture1<TestType>::PPa.first_zero() == 4u);
CHECK(Fixture1<TestType>::V10.first_zero() == 1u);
CHECK(Fixture1<TestType>::V1.first_zero() ==
Fixture1<TestType>::VectType::Size());
Fixture1<TestType>::VectType::size());
CHECK(Fixture1<TestType>::V10.first_zero(1) ==
Fixture1<TestType>::VectType::Size());
Fixture1<TestType>::VectType::size());
CHECK(Fixture1<TestType>::PPa.first_zero(5) == 4u);
CHECK(Fixture1<TestType>::PPa.first_zero(3) ==
Fixture1<TestType>::VectType::Size());
Fixture1<TestType>::VectType::size());
}

TEMPLATE_TEST_CASE_METHOD(Fixture1, "last_zero", "[AllPerm][007]", PermTypes) {
CHECK(Fixture1<TestType>::zero.last_zero() ==
Fixture1<TestType>::VectType::Size() - 1);
Fixture1<TestType>::VectType::size() - 1);
CHECK(Fixture1<TestType>::V01.last_zero() ==
Fixture1<TestType>::VectType::Size() - 1);
Fixture1<TestType>::VectType::size() - 1);
CHECK(Fixture1<TestType>::PPa.last_zero() == 4u);
CHECK(Fixture1<TestType>::V1.last_zero() ==
Fixture1<TestType>::VectType::Size());
Fixture1<TestType>::VectType::size());
CHECK(Fixture1<TestType>::V01.last_zero(1) == 0u);
CHECK(Fixture1<TestType>::V10.last_zero(1) ==
Fixture1<TestType>::VectType::Size());
Fixture1<TestType>::VectType::size());
CHECK(Fixture1<TestType>::PPa.last_zero(5) == 4u);
CHECK(Fixture1<TestType>::PPa.last_zero(3) ==
Fixture1<TestType>::VectType::Size());
Fixture1<TestType>::VectType::size());
}

TEMPLATE_TEST_CASE_METHOD(Fixture1, "first_non_zero", "[AllPerm][008]",
PermTypes) {
CHECK(Fixture1<TestType>::zero.first_non_zero() ==
Fixture1<TestType>::VectType::Size());
Fixture1<TestType>::VectType::size());
CHECK(Fixture1<TestType>::V01.first_non_zero() == 1u);
CHECK(Fixture1<TestType>::PPa.first_non_zero() == 0u);
CHECK(Fixture1<TestType>::V01.first_non_zero() == 1u);
CHECK(Fixture1<TestType>::V01.first_non_zero(1) ==
Fixture1<TestType>::VectType::Size());
Fixture1<TestType>::VectType::size());
CHECK(Fixture1<TestType>::PPa.first_non_zero(5) == 0u);
CHECK(Fixture1<TestType>::PPa.first_non_zero(3) == 0u);
}

TEMPLATE_TEST_CASE_METHOD(Fixture1, "last_non_zero", "[AllPerm][009]",
PermTypes) {
CHECK(Fixture1<TestType>::zero.last_non_zero() ==
Fixture1<TestType>::VectType::Size());
Fixture1<TestType>::VectType::size());
CHECK(Fixture1<TestType>::V01.last_non_zero() == 1u);
CHECK(Fixture1<TestType>::PPa.last_non_zero() ==
Fixture1<TestType>::VectType::Size() - 1);
Fixture1<TestType>::VectType::size() - 1);
CHECK(Fixture1<TestType>::V01.last_non_zero() == 1u);
CHECK(Fixture1<TestType>::V01.last_non_zero(1) ==
Fixture1<TestType>::VectType::Size());
Fixture1<TestType>::VectType::size());
CHECK(Fixture1<TestType>::PPa.last_non_zero(5) == 3u);
CHECK(Fixture1<TestType>::PPa.last_non_zero(3) == 2u);
}

TEMPLATE_TEST_CASE_METHOD(Fixture1, "permuted", "[AllPerm][010]", PermTypes) {
CHECK(Fixture1<TestType>::zero.permuted(Fixture1<TestType>::zero) ==
Fixture1<TestType>::zero);
Fixture1<TestType>::zero);
CHECK(Fixture1<TestType>::V01.permuted(Fixture1<TestType>::V01) ==
Fixture1<TestType>::V01);
Fixture1<TestType>::V01);
CHECK(Fixture1<TestType>::V10.permuted(Fixture1<TestType>::V10) ==
typename Fixture1<TestType>::VectType({0, 1}, 1));
typename Fixture1<TestType>::VectType({0, 1}, 1));
CHECK(Fixture1<TestType>::V10.permuted(Fixture1<TestType>::V01) ==
typename Fixture1<TestType>::VectType({1, 0}, 1));
typename Fixture1<TestType>::VectType({1, 0}, 1));
CHECK(Fixture1<TestType>::V01.permuted(Fixture1<TestType>::V10) ==
Fixture1<TestType>::V10);
Fixture1<TestType>::V10);
}

TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator_insert", "[AllPerm][011]",
PermTypes) {
std::ostringstream out, out2;
out << Fixture1<TestType>::zero;
out2 << "{ 0";
for (size_t i = 1; i < Fixture1<TestType>::VectType::Size(); i++)
for (size_t i = 1; i < Fixture1<TestType>::VectType::size(); i++)
out2 << ", 0";
out2 << "}";
CHECK(out.str() == out2.str());
Expand All @@ -270,7 +266,7 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator_insert", "[AllPerm][011]",
out2.str("");
out << Fixture1<TestType>::V01;
out2 << "{ 0, 1";
for (size_t i = 2; i < Fixture1<TestType>::VectType::Size(); i++)
for (size_t i = 2; i < Fixture1<TestType>::VectType::size(); i++)
out2 << ", 0";
out2 << "}";
CHECK(out.str() == out2.str());
Expand All @@ -279,7 +275,7 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "operator_insert", "[AllPerm][011]",
out2.str("");
out << Fixture1<TestType>::PPa;
out2 << "{ 1, 2, 3, 4, 0";
for (size_t i = 5; i < Fixture1<TestType>::VectType::Size(); i++)
for (size_t i = 5; i < Fixture1<TestType>::VectType::size(); i++)
out2 << "," << std::setw(2) << i;
out2 << "}";
CHECK(out.str() == out2.str());
Expand All @@ -292,8 +288,8 @@ TEMPLATE_TEST_CASE_METHOD(Fixture1, "is_permutation", "[AllPerm][012]",
CHECK(!Fixture1<TestType>::PPb.is_permutation());
CHECK(Fixture1<TestType>::RandPerm.is_permutation());
CHECK(!typename Fixture1<TestType>::VectType(
{3, 1, 0, 9, 3, 10, 2, 11, 6, 7, 4, 8})
.is_permutation());
{3, 1, 0, 9, 3, 10, 2, 11, 6, 7, 4, 8})
.is_permutation());
CHECK(Fixture1<TestType>::PPa.is_permutation(16));
CHECK(!Fixture1<TestType>::RandPerm.is_permutation(4));
CHECK(Fixture1<TestType>::PPa.is_permutation(5));
Expand Down Expand Up @@ -346,7 +342,7 @@ TEMPLATE_TEST_CASE_METHOD(Fixture2, "std::hash", "[AllPerm][014]", PermTypes) {

TEMPLATE_TEST_CASE_METHOD(Fixture2, "mult_coxeter", "[AllPerm][015]",
PermTypes) {
const size_t n = TestType::Size() - 1;
const size_t n = TestType::size() - 1;

for (uint64_t i = 0; i < n; i++) {
auto si = TestType::elementary_transposition(i);
Expand All @@ -369,7 +365,7 @@ TEMPLATE_TEST_CASE_METHOD(Fixture2, "mult", "[AllPerm][016]", PermTypes) {
CHECK(x * Fixture2<TestType>::id == x);
}
CHECK(Fixture2<TestType>::RandPerm * Fixture2<TestType>::RandPerm ==
TestType({5, 1, 3, 2, 8, 0, 9, 11, 6, 10, 7, 4}));
TestType({5, 1, 3, 2, 8, 0, 9, 11, 6, 10, 7, 4}));

for (auto x : Fixture2<TestType>::Plist) {
for (auto y : Fixture2<TestType>::Plist) {
Expand Down

0 comments on commit 97777b8

Please sign in to comment.