From d984d3f8351ab8920b309353cf9cf7f9fcb97a10 Mon Sep 17 00:00:00 2001
From: bcumming <bcumming@cscs.ch>
Date: Thu, 14 Apr 2016 09:09:23 +0200
Subject: [PATCH] fix signed-unsigned comparisons

---
 src/algorithms.hpp    | 16 ++++++++++++----
 src/segment.hpp       |  2 +-
 src/tree.hpp          |  2 +-
 tests/test_matrix.cpp | 10 +++++-----
 tests/test_run.cpp    |  6 +++---
 tests/test_tree.cpp   | 22 +++++++++++-----------
 6 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/src/algorithms.hpp b/src/algorithms.hpp
index 250cade2..28610b08 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 a73dd921..5ed10d78 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 8a296cec..d517f7e4 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 ba6794f1..19e6702a 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 c4894299..db2a65c9 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 097895dd..9bb320d1 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};
-- 
GitLab