Skip to content
Snippets Groups Projects
Commit bac43204 authored by Benjamin Cumming's avatar Benjamin Cumming
Browse files

fix warnings about unsigned-singed comparisons in gcc 5.3

parent c5fb9530
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,8 @@ flags = [ ...@@ -45,6 +45,8 @@ flags = [
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1' '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1'
'-isystem', '-isystem',
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1/bits' '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1/bits'
'-I',
'src',
# '-I', # '-I',
# '/usr/include/c++/4.9.2', # '/usr/include/c++/4.9.2',
# '-isystem', # '-isystem',
......
...@@ -128,13 +128,13 @@ class tree { ...@@ -128,13 +128,13 @@ class tree {
return branch_index; return branch_index;
} }
int num_children() const { size_t num_children() const {
return children_.size(); return children_.size();
} }
int num_children(int b) const { size_t num_children(size_t b) const {
return child_index_[b+1] - child_index_[b]; return child_index_[b+1] - child_index_[b];
} }
int num_nodes() const { size_t num_nodes() const {
return child_index_.size() - 1; return child_index_.size() - 1;
} }
...@@ -149,7 +149,7 @@ class tree { ...@@ -149,7 +149,7 @@ class tree {
} }
/// return the list of all children of branch b /// return the list of all children of branch b
const index_view children(int b) const { const index_view children(size_t b) const {
return children_(child_index_[b], child_index_[b+1]); return children_(child_index_[b], child_index_[b+1]);
} }
...@@ -159,10 +159,10 @@ class tree { ...@@ -159,10 +159,10 @@ class tree {
} }
/// return the parent of branch b /// return the parent of branch b
int_type parent(int b) const { int_type parent(size_t b) const {
return parents_[b]; return parents_[b];
} }
int_type& parent(int b) { int_type& parent(size_t b) {
return parents_[b]; return parents_[b];
} }
...@@ -171,7 +171,7 @@ class tree { ...@@ -171,7 +171,7 @@ class tree {
return sizeof(int_type)*data_.size() + sizeof(tree); return sizeof(int_type)*data_.size() + sizeof(tree);
} }
index_type change_root(int b) { index_type change_root(size_t b) {
assert(b<num_nodes()); assert(b<num_nodes());
// no need to rebalance if the root node has been requested // no need to rebalance if the root node has been requested
...@@ -222,16 +222,16 @@ class tree { ...@@ -222,16 +222,16 @@ class tree {
auto nchild = nnode - 1; auto nchild = nnode - 1;
// data_ is partitioned as follows: // data_ is partitioned as follows:
// data_ = [children_[nchild], child_index_[nnode+1], parents_[nnode]] // data_ = [children_[nchild], child_index_[nnode+1], parents_[nnode]]
assert(data_.size() == nchild + (nnode+1) + nnode); assert(data_.size() == unsigned(nchild + (nnode+1) + nnode));
children_ = data_(0, nchild); children_ = data_(0, nchild);
child_index_ = data_(nchild, nchild+nnode+1); child_index_ = data_(nchild, nchild+nnode+1);
parents_ = data_(nchild+nnode+1, memory::end); parents_ = data_(nchild+nnode+1, memory::end);
// check that arrays have appropriate size // check that arrays have appropriate size
// this should be moved into a unit test // this should be moved into a unit test
assert(children_.size() == nchild); assert(children_.size() == unsigned(nchild));
assert(child_index_.size() == nnode+1); assert(child_index_.size() == unsigned(nnode+1));
assert(parents_.size() == nnode); assert(parents_.size() == unsigned(nnode));
} }
/// Renumber the sub-tree with old_node as its root with new_node as /// Renumber the sub-tree with old_node as its root with new_node as
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "gtest.h" #include "gtest.h"
#include "cell_tree.hpp" #include "../src/cell_tree.hpp"
#include "json/src/json.hpp" #include "json/src/json.hpp"
using json = nlohmann::json; using json = nlohmann::json;
...@@ -18,112 +18,112 @@ TEST(cell_tree, from_parent_index) { ...@@ -18,112 +18,112 @@ TEST(cell_tree, from_parent_index) {
{ {
std::vector<int> parent_index = {0}; std::vector<int> parent_index = {0};
cell_tree tree(parent_index); cell_tree tree(parent_index);
EXPECT_EQ(tree.num_segments(), 1); EXPECT_EQ(tree.num_segments(), 1u);
EXPECT_EQ(tree.num_children(0), 0); EXPECT_EQ(tree.num_children(0), 0u);
} }
// CASE 2 : empty parent_index // CASE 2 : empty parent_index
{ {
std::vector<int> parent_index; std::vector<int> parent_index;
cell_tree tree(parent_index); cell_tree tree(parent_index);
EXPECT_EQ(tree.num_segments(), 1); EXPECT_EQ(tree.num_segments(), 1u);
EXPECT_EQ(tree.num_children(0), 0); EXPECT_EQ(tree.num_children(0), 0u);
} }
// tree with two segments off the root node // tree with two segments off the root node
{ {
std::vector<int> parent_index = std::vector<int> parent_index =
{0, 0, 1, 2, 0, 4}; {0, 0, 1, 2, 0, 4};
cell_tree tree(parent_index); cell_tree tree(parent_index);
EXPECT_EQ(tree.num_segments(), 3); EXPECT_EQ(tree.num_segments(), 3u);
// the root has 2 children // the root has 2 children
EXPECT_EQ(tree.num_children(0), 2); EXPECT_EQ(tree.num_children(0), 2u);
// the children are leaves // the children are leaves
EXPECT_EQ(tree.num_children(1), 0); EXPECT_EQ(tree.num_children(1), 0u);
EXPECT_EQ(tree.num_children(2), 0); EXPECT_EQ(tree.num_children(2), 0u);
} }
{ {
// tree with three segments off the root node // tree with three segments off the root node
std::vector<int> parent_index = std::vector<int> parent_index =
{0, 0, 1, 2, 0, 4, 0, 6, 7, 8}; {0, 0, 1, 2, 0, 4, 0, 6, 7, 8};
cell_tree tree(parent_index); cell_tree tree(parent_index);
EXPECT_EQ(tree.num_segments(), 4); EXPECT_EQ(tree.num_segments(), 4u);
// the root has 3 children // the root has 3 children
EXPECT_EQ(tree.num_children(0), 3); EXPECT_EQ(tree.num_children(0), 3u);
// the children are leaves // the children are leaves
EXPECT_EQ(tree.num_children(1), 0); EXPECT_EQ(tree.num_children(1), 0u);
EXPECT_EQ(tree.num_children(2), 0); EXPECT_EQ(tree.num_children(2), 0u);
EXPECT_EQ(tree.num_children(3), 0); EXPECT_EQ(tree.num_children(3), 0u);
} }
{ {
// tree with three segments off the root node, and another 2 segments off of the third branch from the root node // tree with three segments off the root node, and another 2 segments off of the third branch from the root node
std::vector<int> parent_index = std::vector<int> parent_index =
{0, 0, 1, 2, 0, 4, 0, 6, 7, 8, 9, 8, 11, 12}; {0, 0, 1, 2, 0, 4, 0, 6, 7, 8, 9, 8, 11, 12};
cell_tree tree(parent_index); cell_tree tree(parent_index);
EXPECT_EQ(tree.num_segments(), 6); EXPECT_EQ(tree.num_segments(), 6u);
// the root has 3 children // the root has 3 children
EXPECT_EQ(tree.num_children(0), 3); EXPECT_EQ(tree.num_children(0), 3u);
// one of the chilren has 2 children ... // one of the chilren has 2 children ...
EXPECT_EQ(tree.num_children(3), 2); EXPECT_EQ(tree.num_children(3), 2u);
// the rest are leaves // the rest are leaves
EXPECT_EQ(tree.num_children(1), 0); EXPECT_EQ(tree.num_children(1), 0u);
EXPECT_EQ(tree.num_children(2), 0); EXPECT_EQ(tree.num_children(2), 0u);
EXPECT_EQ(tree.num_children(4), 0); EXPECT_EQ(tree.num_children(4), 0u);
EXPECT_EQ(tree.num_children(5), 0); EXPECT_EQ(tree.num_children(5), 0u);
} }
{ {
// //
// 0 // 0
// / // /
// 1 // 1
// / \ // / \.
// 2 3 // 2 3
std::vector<int> parent_index = {0,0,1,1}; std::vector<int> parent_index = {0,0,1,1};
cell_tree tree(parent_index); cell_tree tree(parent_index);
EXPECT_EQ(tree.num_segments(), 4); EXPECT_EQ(tree.num_segments(), 4u);
EXPECT_EQ(tree.num_children(0), 1); EXPECT_EQ(tree.num_children(0), 1u);
EXPECT_EQ(tree.num_children(1), 2); EXPECT_EQ(tree.num_children(1), 2u);
EXPECT_EQ(tree.num_children(2), 0); EXPECT_EQ(tree.num_children(2), 0u);
EXPECT_EQ(tree.num_children(3), 0); EXPECT_EQ(tree.num_children(3), 0u);
} }
{ {
// //
// 0 // 0
// / \ // / \.
// 1 2 // 1 2
// / \ // / \.
// 3 4 // 3 4
std::vector<int> parent_index = {0,0,0,1,1}; std::vector<int> parent_index = {0,0,0,1,1};
cell_tree tree(parent_index); cell_tree tree(parent_index);
EXPECT_EQ(tree.num_segments(), 5); EXPECT_EQ(tree.num_segments(), 5u);
EXPECT_EQ(tree.num_children(0), 2); EXPECT_EQ(tree.num_children(0), 2u);
EXPECT_EQ(tree.num_children(1), 2); EXPECT_EQ(tree.num_children(1), 2u);
EXPECT_EQ(tree.num_children(2), 0); EXPECT_EQ(tree.num_children(2), 0u);
EXPECT_EQ(tree.num_children(3), 0); EXPECT_EQ(tree.num_children(3), 0u);
EXPECT_EQ(tree.num_children(4), 0); EXPECT_EQ(tree.num_children(4), 0u);
} }
{ {
// 0 // 0
// / \ // / \.
// 1 2 // 1 2
// / \ // / \.
// 3 4 // 3 4
// / \ // / \.
// 5 6 // 5 6
std::vector<int> parent_index = {0,0,0,1,1,4,4}; std::vector<int> parent_index = {0,0,0,1,1,4,4};
cell_tree tree(parent_index); cell_tree tree(parent_index);
EXPECT_EQ(tree.num_segments(), 7); EXPECT_EQ(tree.num_segments(), 7u);
EXPECT_EQ(tree.num_children(0), 2); EXPECT_EQ(tree.num_children(0), 2u);
EXPECT_EQ(tree.num_children(1), 2); EXPECT_EQ(tree.num_children(1), 2u);
EXPECT_EQ(tree.num_children(2), 0); EXPECT_EQ(tree.num_children(2), 0u);
EXPECT_EQ(tree.num_children(3), 0); EXPECT_EQ(tree.num_children(3), 0u);
EXPECT_EQ(tree.num_children(4), 2); EXPECT_EQ(tree.num_children(4), 2u);
EXPECT_EQ(tree.num_children(5), 0); EXPECT_EQ(tree.num_children(5), 0u);
EXPECT_EQ(tree.num_children(6), 0); EXPECT_EQ(tree.num_children(6), 0u);
} }
} }
...@@ -141,32 +141,32 @@ TEST(tree, change_root) { ...@@ -141,32 +141,32 @@ TEST(tree, change_root) {
t.init_from_parent_index(parent_index); t.init_from_parent_index(parent_index);
t.change_root(1); t.change_root(1);
EXPECT_EQ(t.num_nodes(), 3); EXPECT_EQ(t.num_nodes(), 3u);
EXPECT_EQ(t.num_children(0), 1); EXPECT_EQ(t.num_children(0), 1u);
EXPECT_EQ(t.num_children(1), 1); EXPECT_EQ(t.num_children(1), 1u);
EXPECT_EQ(t.num_children(2), 0); EXPECT_EQ(t.num_children(2), 0u);
} }
{ {
// a cell with the following structure // a cell with the following structure
// make 1 the new root // make 1 the new root
// 0 0 // 0 0
// / \ /|\ // / \ /|\.
// 1 2 -> 1 2 3 // 1 2 -> 1 2 3
// / \ | // / \ |
// 3 4 4 // 3 4 4
std::vector<int> parent_index = {0,0,0,1,1}; std::vector<int> parent_index = {0,0,0,1,1};
tree t; tree t;
t.init_from_parent_index(parent_index); t.init_from_parent_index(parent_index);
t.change_root(1); t.change_root(1u);
EXPECT_EQ(t.num_nodes(), 5); EXPECT_EQ(t.num_nodes(), 5u);
EXPECT_EQ(t.num_children(0), 3); EXPECT_EQ(t.num_children(0), 3u);
EXPECT_EQ(t.num_children(1), 0); EXPECT_EQ(t.num_children(1), 0u);
EXPECT_EQ(t.num_children(2), 0); EXPECT_EQ(t.num_children(2), 0u);
EXPECT_EQ(t.num_children(3), 1); EXPECT_EQ(t.num_children(3), 1u);
EXPECT_EQ(t.num_children(4), 0); EXPECT_EQ(t.num_children(4), 0u);
} }
{ {
// a cell with the following structure // a cell with the following structure
...@@ -174,11 +174,11 @@ TEST(tree, change_root) { ...@@ -174,11 +174,11 @@ TEST(tree, change_root) {
// unlike earlier tests, this decreases the depth // unlike earlier tests, this decreases the depth
// of the tree // of the tree
// 0 0 // 0 0
// / \ /|\ // / \ /|\.
// 1 2 -> 1 2 5 // 1 2 -> 1 2 5
// / \ / \ \ // / \ / \ \.
// 3 4 3 4 6 // 3 4 3 4 6
// / \ // / \.
// 5 6 // 5 6
std::vector<int> parent_index = {0,0,0,1,1,4,4}; std::vector<int> parent_index = {0,0,0,1,1,4,4};
tree t; tree t;
...@@ -186,15 +186,15 @@ TEST(tree, change_root) { ...@@ -186,15 +186,15 @@ TEST(tree, change_root) {
t.change_root(1); t.change_root(1);
EXPECT_EQ(t.num_nodes(), 7); EXPECT_EQ(t.num_nodes(), 7u);
EXPECT_EQ(t.num_children(0), 3); EXPECT_EQ(t.num_children(0), 3u);
EXPECT_EQ(t.num_children(1), 0); EXPECT_EQ(t.num_children(1), 0u);
EXPECT_EQ(t.num_children(2), 2); EXPECT_EQ(t.num_children(2), 2u);
EXPECT_EQ(t.num_children(3), 0); EXPECT_EQ(t.num_children(3), 0u);
EXPECT_EQ(t.num_children(4), 0); EXPECT_EQ(t.num_children(4), 0u);
EXPECT_EQ(t.num_children(5), 1); EXPECT_EQ(t.num_children(5), 1u);
EXPECT_EQ(t.num_children(6), 0); EXPECT_EQ(t.num_children(6), 0u);
} }
} }
...@@ -203,11 +203,11 @@ TEST(cell_tree, balance) { ...@@ -203,11 +203,11 @@ TEST(cell_tree, balance) {
// a cell with the following structure // a cell with the following structure
// will balance around 1 // will balance around 1
// 0 0 // 0 0
// / \ /|\ // / \ /|\.
// 1 2 -> 1 2 5 // 1 2 -> 1 2 5
// / \ / \ \ // / \ / \ \.
// 3 4 3 4 6 // 3 4 3 4 6
// / \ // / \.
// 5 6 // 5 6
std::vector<int> parent_index = {0,0,0,1,1,4,4}; std::vector<int> parent_index = {0,0,0,1,1,4,4};
cell_tree t(parent_index); cell_tree t(parent_index);
...@@ -217,14 +217,14 @@ TEST(cell_tree, balance) { ...@@ -217,14 +217,14 @@ TEST(cell_tree, balance) {
// the soma (original root) has moved to 5 in the new tree // the soma (original root) has moved to 5 in the new tree
EXPECT_EQ(t.soma(), 5); EXPECT_EQ(t.soma(), 5);
EXPECT_EQ(t.num_segments(), 7); EXPECT_EQ(t.num_segments(), 7u);
EXPECT_EQ(t.num_children(0),3); EXPECT_EQ(t.num_children(0),3u);
EXPECT_EQ(t.num_children(1),0); EXPECT_EQ(t.num_children(1),0u);
EXPECT_EQ(t.num_children(2),2); EXPECT_EQ(t.num_children(2),2u);
EXPECT_EQ(t.num_children(3),0); EXPECT_EQ(t.num_children(3),0u);
EXPECT_EQ(t.num_children(4),0); EXPECT_EQ(t.num_children(4),0u);
EXPECT_EQ(t.num_children(5),1); EXPECT_EQ(t.num_children(5),1u);
EXPECT_EQ(t.num_children(6),0); EXPECT_EQ(t.num_children(6),0u);
EXPECT_EQ(t.parent(0),-1); EXPECT_EQ(t.parent(0),-1);
EXPECT_EQ(t.parent(1), 0); EXPECT_EQ(t.parent(1), 0);
EXPECT_EQ(t.parent(2), 0); EXPECT_EQ(t.parent(2), 0);
......
Subproject commit 79ad5236b219a7618a8cda8caad6cd3de1f9e122 Subproject commit a8dfadd460262ebbc1bc22b159efe9e33ad1d359
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment