diff --git a/src/algorithms.hpp b/src/algorithms.hpp index 250cade2905ffe8aa45a9554dab196412d574aff..28610b08f08651e4dc44ba592f9435d7f276c4ee 100644 --- a/src/algorithms.hpp +++ b/src/algorithms.hpp @@ -35,6 +35,11 @@ namespace algorithms{ template <typename C> C make_index(C const& c) { + static_assert( + std::is_integral<typename C::value_type>::value, + "make_index only applies to integral types" + ); + C out(c.size()+1); out[0] = 0; std::partial_sum(c.begin(), c.end(), out.begin()+1); @@ -76,8 +81,11 @@ namespace algorithms{ std::is_integral<typename C::value_type>::value, "is_minimal_degree only applies to integral types" ); - for(auto i=0; i<c.size(); ++i) { - if(i<c[i]) { + + using value_type = typename C::value_type; + auto i = value_type(0); + for(auto v : c) { + if(i++<v) { return false; } } @@ -91,8 +99,8 @@ namespace algorithms{ std::is_integral<typename C::value_type>::value, "is_positive only applies to integral types" ); - for(auto i=0; i<c.size(); ++i) { - if(c[i]<1) { + for(auto v : c) { + if(v<1) { return false; } } diff --git a/src/segment.hpp b/src/segment.hpp index a73dd9219cba674f90fb03d4e11ea44e0ab29dfd..5ed10d78407df0b9848a354959146ca14510113f 100644 --- a/src/segment.hpp +++ b/src/segment.hpp @@ -253,7 +253,7 @@ class cable_segment : public segment value_type r2, value_type len ) - : cable_segment{k, {r1, r2}, {len}} + : cable_segment{k, std::vector<value_type>{r1, r2}, std::vector<value_type>{len}} { } // constructor that lets the user describe the cable as a diff --git a/src/tree.hpp b/src/tree.hpp index 8a296cece8c44f750b2a6798780449231e7cf878..d517f7e4570fc9278bab22ff974a3baaa964ea50 100644 --- a/src/tree.hpp +++ b/src/tree.hpp @@ -372,7 +372,7 @@ std::vector<int> make_parent_index(tree const& t, C const& counts) auto num_compartments = index.back(); std::vector<int> parent_index(num_compartments); auto pos = 0; - for(auto i : range(0, t.num_nodes())) { + for(int i : range(0, t.num_nodes())) { // get the parent of this segment // taking care for the case where the root node has -1 as its parent auto parent = t.parent(i); diff --git a/tests/test_matrix.cpp b/tests/test_matrix.cpp index ba6794f1bd4ab095cc542bee340bb8a4e5ff15cc..19e6702ac975ea09b01e72d2b9677ebc30368d21 100644 --- a/tests/test_matrix.cpp +++ b/tests/test_matrix.cpp @@ -17,7 +17,7 @@ TEST(matrix, construct_from_parent_only) matrix_type m{p}; EXPECT_EQ(m.num_cells(), 1); EXPECT_EQ(m.size(), 3); - EXPECT_EQ(p.size(), 3); + EXPECT_EQ(p.size(), 3u); auto mp = m.p(); EXPECT_EQ(mp[0], 0); @@ -32,7 +32,7 @@ TEST(matrix, construct_from_parent_only) matrix_type m{std::move(p)}; EXPECT_EQ(m.num_cells(), 1); EXPECT_EQ(m.size(), 3); - EXPECT_EQ(p.size(), 3); + EXPECT_EQ(p.size(), 3u); EXPECT_EQ(m.size(), 3); auto mp = m.p(); @@ -49,7 +49,7 @@ TEST(matrix, construct_from_parent_only) matrix_type m{p}; EXPECT_EQ(m.num_cells(), 1); EXPECT_EQ(m.size(), 3); - EXPECT_EQ(p.size(), 3); + EXPECT_EQ(p.size(), 3u); auto mp = m.p(); EXPECT_EQ(mp[0], 0); @@ -64,7 +64,7 @@ TEST(matrix, construct_from_parent_only) matrix_type m{std::move(p)}; EXPECT_EQ(m.num_cells(), 1); EXPECT_EQ(m.size(), 3); - EXPECT_EQ(p.size(), 0); // 0 implies moved from + EXPECT_EQ(p.size(), 0u); // 0 implies moved from auto mp = m.p(); EXPECT_EQ(mp[0], 0); @@ -98,7 +98,7 @@ TEST(matrix, solve) std::iota(p.begin()+1, p.end(), 0); matrix_type m{p}; - EXPECT_EQ(m.size(), n); + EXPECT_EQ(m.size(), (int)n); EXPECT_EQ(m.num_cells(), 1); m.d()(memory::all) = 2; diff --git a/tests/test_run.cpp b/tests/test_run.cpp index c489429926c39d8ff424f46bb3d6e24dc2a4b591..db2a65c9ced187552baadeb377ca94c913e3f64e 100644 --- a/tests/test_run.cpp +++ b/tests/test_run.cpp @@ -54,16 +54,16 @@ TEST(run, parameters) // add_parameter() returns a bool that indicates whether // it was able to successfull add the parameter EXPECT_EQ(list.add_parameter(std::move(p)), true); - EXPECT_EQ(list.num_parameters(), 1u); + EXPECT_EQ(list.num_parameters(), 1); // test in place construction of a parameter EXPECT_EQ(list.add_parameter({"b", -3.0}), true); - EXPECT_EQ(list.num_parameters(), 2u); + EXPECT_EQ(list.num_parameters(), 2); // check that adding a parameter that already exists returns false // and does not increase the number of parameters EXPECT_EQ(list.add_parameter({"b", -3.0}), false); - EXPECT_EQ(list.num_parameters(), 2u); + EXPECT_EQ(list.num_parameters(), 2); auto &parms = list.parameters(); EXPECT_EQ(parms[0].name, "a"); diff --git a/tests/test_tree.cpp b/tests/test_tree.cpp index 097895dd7cb962ba8cdd3db1bcea09b461285112..9bb320d1e4cf5f1b0e8b1f5e320384f32935d728 100644 --- a/tests/test_tree.cpp +++ b/tests/test_tree.cpp @@ -267,10 +267,10 @@ TEST(tree, make_parent_index) std::vector<int> counts = {5}; nest::mc::tree t(parent_index); auto new_parent_index = make_parent_index(t, counts); - EXPECT_EQ(new_parent_index.size(), counts[0]); + EXPECT_EQ(new_parent_index.size(), (unsigned)counts[0]); EXPECT_EQ(new_parent_index[0], 0); - for(auto i=1; i<new_parent_index.size(); ++i) { - EXPECT_EQ(new_parent_index[i], i-1); + for(auto i=1u; i<new_parent_index.size(); ++i) { + EXPECT_EQ((unsigned)new_parent_index[i], i-1); } } // some trees with single compartment per segment @@ -281,13 +281,13 @@ TEST(tree, make_parent_index) // 1 std::vector<int>{0,0}, // 0 - // / \ + // / \. // 1 2 std::vector<int>{0,0,0}, // 0 - // / \ + // / \. // 1 4 - // / \ |\ + // / \ |\. // 2 3 5 6 std::vector<int>{0,0,0,1,1,2,2} }; @@ -301,15 +301,15 @@ TEST(tree, make_parent_index) // a tree with multiple compartments per segment // // 0 - // / \ + // / \. // 1 8 - // / \ + // / \. // 2 9 - // / + // /. // 3 - // / \ + // / \. // 4 6 - // / \ + // / \. // 5 7 { std::vector<int> parent_index = {0,0,1,2,3,4,3,6,0,8};