diff --git a/arbor/tree.cpp b/arbor/tree.cpp index 3ae342dff0..1407303575 100644 --- a/arbor/tree.cpp +++ b/arbor/tree.cpp @@ -29,7 +29,7 @@ tree::tree(std::vector parent_index) { parents_[0] = no_parent; // compute offsets into children_ array - arb::util::make_partition(child_index_, child_count(parents_)); + util::make_partition(child_index_, child_count(parents_)); std::vector pos(parents_.size(), 0); for (auto i = 1u; i < parents_.size(); ++i) { @@ -199,11 +199,9 @@ tree::iarray tree::select_new_root(int_type root) { } // maps new indices to old indices - iarray indices (num_nodes); - // fill array with indices - for (auto i: make_span(num_nodes)) { - indices[i] = i; - } + iarray indices(num_nodes); + std::iota(indices.begin(), indices.end(), 0); + // perform sort by depth index to get the permutation std::sort(indices.begin(), indices.end(), [&](auto i, auto j){ if (reduced_depth[i] != reduced_depth[j]) { @@ -214,16 +212,12 @@ tree::iarray tree::select_new_root(int_type root) { } return depth[i] < depth[j]; }); - // maps old indices to new indices - iarray indices_inv (num_nodes); - // fill array with indices - for (auto i: make_span(num_nodes)) { - indices_inv[i] = i; - } - // perform sort - std::sort(indices_inv.begin(), indices_inv.end(), [&](auto i, auto j){ - return indices[i] < indices[j]; - }); + + // inverse permutation + iarray indices_inv(num_nodes, 0); + std::iota(indices_inv.begin(), indices_inv.end(), 0); + std::sort(indices_inv.begin(), indices_inv.end(), + [&](auto i, auto j){ return indices[i] < indices[j]; }); // translate the parent vetor to new indices for (auto i: make_span(num_nodes)) { @@ -241,7 +235,7 @@ tree::iarray tree::select_new_root(int_type root) { // recompute the children array memory::copy(new_parents, parents_); - arb::util::make_partition(child_index_, child_count(parents_)); + util::make_partition(child_index_, child_count(parents_)); std::vector pos(parents_.size(), 0); for (auto i = 1u; i < parents_.size(); ++i) { diff --git a/arbor/tree.hpp b/arbor/tree.hpp index 137598318a..75b6fb2f8f 100644 --- a/arbor/tree.hpp +++ b/arbor/tree.hpp @@ -2,16 +2,12 @@ #include #include -#include -#include #include #include #include -#include "memory/memory.hpp" #include "util/rangeutil.hpp" -#include "util/span.hpp" namespace arb { diff --git a/arbor/util/meta.hpp b/arbor/util/meta.hpp index d9f30584fd..ed0055f088 100644 --- a/arbor/util/meta.hpp +++ b/arbor/util/meta.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/arbor/util/range.hpp b/arbor/util/range.hpp index 3a7257b7c1..13f80b095e 100644 --- a/arbor/util/range.hpp +++ b/arbor/util/range.hpp @@ -158,10 +158,9 @@ template auto canonical_view(Seq&& s) { using std::begin; using std::end; - - return make_range( - make_sentinel_iterator(begin(s), end(s)), - make_sentinel_end(begin(s), end(s))); + auto b = begin(s); + auto e = end(s); + return make_range(make_sentinel_iterator(b, e), make_sentinel_end(b, e)); } // Strictly evaluate end point in sentinel-terminated range and present as a range over @@ -170,8 +169,6 @@ auto canonical_view(Seq&& s) { template auto strict_view(Seq&& s) { using std::begin; - using std::end; - auto b = begin(s); auto e = end(s); return make_range(b, b==e? b: std::next(util::upto(b, e))); diff --git a/arbor/util/rangeutil.hpp b/arbor/util/rangeutil.hpp index 312bd55877..045ea79d7d 100644 --- a/arbor/util/rangeutil.hpp +++ b/arbor/util/rangeutil.hpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include diff --git a/test/unit-distributed/test_distributed_for_each.cpp b/test/unit-distributed/test_distributed_for_each.cpp index 5c545e8c53..b9ca83b228 100644 --- a/test/unit-distributed/test_distributed_for_each.cpp +++ b/test/unit-distributed/test_distributed_for_each.cpp @@ -40,10 +40,9 @@ TEST(distributed_for_each, one_zero) { for (int i = 0; i < rank; ++i) { data.push_back(rank); } auto sample = [&](const util::range& range) { - const auto origin_rank = range.empty() ? 0 : range.front(); - + std::size_t origin_rank = range.empty() ? 0 : range.front(); EXPECT_EQ(origin_rank, range.size()); - for (const auto& value: range) { EXPECT_EQ(value, origin_rank); } + for (std::size_t value: range) { EXPECT_EQ(value, origin_rank); } ++call_count; }; @@ -71,14 +70,14 @@ TEST(distributed_for_each, multiple) { auto sample = [&](const util::range& range_1, const util::range& range_2, const util::range*>& range_3) { - const auto origin_rank = range_1.empty() ? 0 : range_1.front(); + std::size_t origin_rank = range_1.empty() ? 0 : range_1.front(); EXPECT_EQ(origin_rank + 1, range_1.size()); EXPECT_EQ(range_2.size(), 2 * range_1.size()); EXPECT_EQ(range_3.size(), 3 * range_1.size()); - for (const auto& value: range_1) { EXPECT_EQ(value, origin_rank); } - for (const auto& value: range_2) { EXPECT_EQ(value, double(origin_rank)); } - for (const auto& value: range_3) { EXPECT_EQ(value, std::complex(origin_rank)); } + for (std::size_t value: range_1) { EXPECT_EQ(value, origin_rank); } + for (auto value: range_2) { EXPECT_EQ(value, double(origin_rank)); } + for (auto value: range_3) { EXPECT_EQ(value, std::complex(origin_rank)); } ++call_count; }; diff --git a/test/unit-distributed/test_network_generation.cpp b/test/unit-distributed/test_network_generation.cpp index f7e3b55fe3..1a6e094742 100644 --- a/test/unit-distributed/test_network_generation.cpp +++ b/test/unit-distributed/test_network_generation.cpp @@ -125,8 +125,8 @@ TEST(network_generation, all) { } for (const auto& group: decomp.groups()) { - const auto num_dest = group.kind == cell_kind::spike_source ? 0 : 1; - for (const auto gid: group.gids) { + std::size_t num_dest = group.kind == cell_kind::spike_source ? 0 : 1; + for (std::size_t gid: group.gids) { EXPECT_EQ(connections_by_dest[gid].size(), num_cells * num_dest); } } @@ -141,7 +141,7 @@ TEST(network_generation, cable_only) { const auto weight = 2.0; const auto delay = 3.0; - const auto num_cells = 3 * num_ranks; + const std::size_t num_cells = 3 * num_ranks; auto rec = network_test_recipe(num_cells, selection, weight, delay); @@ -161,7 +161,7 @@ TEST(network_generation, cable_only) { for (const auto gid: group.gids) { // Only one third is a cable cell EXPECT_EQ(connections_by_dest[gid].size(), - group.kind == cell_kind::cable ? num_cells / 3 : 0); + group.kind == cell_kind::cable ? num_cells / 3 : 0); } } } diff --git a/test/unit/common.hpp b/test/unit/common.hpp index e02b9df20a..23a08da975 100644 --- a/test/unit/common.hpp +++ b/test/unit/common.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include diff --git a/test/unit/test_range.cpp b/test/unit/test_range.cpp index 02e889fc0c..de86ef7ecd 100644 --- a/test/unit/test_range.cpp +++ b/test/unit/test_range.cpp @@ -14,7 +14,6 @@ #include "util/meta.hpp" #include "util/range.hpp" #include "util/rangeutil.hpp" -#include "util/sentinel.hpp" #include "util/transform.hpp" #include "common.hpp" @@ -442,41 +441,34 @@ struct foo { }; TEST(range, sort) { - char cstr[] = "howdy"; - - auto cstr_range = util::make_range(std::begin(cstr), null_terminated); - - // Alas, no forward_iterator sort yet, so make a strict (non-sentinel) - // range to sort on below - - // simple sort - util::sort(util::strict_view(cstr_range)); - EXPECT_EQ("dhowy"s, cstr); - - // reverse sort by transform c to -c - util::sort_by(util::strict_view(cstr_range), [](char c) { return -c; }); - EXPECT_EQ("ywohd"s, cstr); - - // stable sort: move capitals to front, numbers to back - auto rank = [](char c) { - return std::isupper(c)? 0: std::isdigit(c)? 2: 1; - }; - - char mixed[] = "t5hH4E3erLL2e1O"; - auto mixed_range = util::make_range(std::begin(mixed), null_terminated); - - util::stable_sort_by(util::strict_view(mixed_range), rank); - EXPECT_EQ("HELLOthere54321"s, mixed); - - - // sort with user-provided less comparison function - - std::vector X = {{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}}; - - util::sort(X, [](const foo& l, const foo& r) {return l.y{{5, 0}, {4, 1}, {3, 2}, {2, 3}, {1, 4}, {0, 5}})); - util::sort(X, [](const foo& l, const foo& r) {return l.x{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}})); + { + // simple sort + char cstr[] = "howdy"; + util::sort(util::range_n(cstr, 5)); + EXPECT_EQ("dhowy"s, cstr); + } + { + // reverse sort by transform c to -c + char cstr[] = "howdy"; + util::sort_by(util::range_n(cstr, 5), + [](char c) { return -c; }); + EXPECT_EQ("ywohd"s, cstr); + } + { + // stable sort: move capitals to front, numbers to back + char mixed[] = "t5hH4E3erLL2e1O"; + util::stable_sort_by(util::strict_view(util::make_range(std::begin(mixed), null_terminated)), + [](char c) { return std::isupper(c)? 0: std::isdigit(c)? 2: 1; }); + EXPECT_EQ("HELLOthere54321"s, mixed); + } + { + // sort with user-provided less comparison function + std::vector X = {{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}}; + util::sort(X, [](const foo& l, const foo& r) {return l.y{{5, 0}, {4, 1}, {3, 2}, {2, 3}, {1, 4}, {0, 5}})); + util::sort(X, [](const foo& l, const foo& r) {return l.x{{0, 5}, {1, 4}, {2, 3}, {3, 2}, {4, 1}, {5, 0}})); + } } TEST(range, sum) { diff --git a/test/unit/test_simd.cpp b/test/unit/test_simd.cpp index d3a572b327..b6e1b1addf 100644 --- a/test/unit/test_simd.cpp +++ b/test/unit/test_simd.cpp @@ -359,13 +359,13 @@ TYPED_TEST_P(simd_value, comparison) { for (unsigned i = 0; ib;