diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index ea97fe481c903d1e5319bf4a9e0174069c75ddc5..0157edd8b889d01de253f8545b06cbf91b9b8416 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -45,6 +45,8 @@ flags = [ '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1' '-isystem', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1/bits' + '-I', + 'src', # '-I', # '/usr/include/c++/4.9.2', # '-isystem', diff --git a/src/tree.hpp b/src/tree.hpp index 04f8ccd4d35b207a5567906d3eb84c47058340c2..6b53aa6f329490a3c431817445f9b2be4dda25b1 100644 --- a/src/tree.hpp +++ b/src/tree.hpp @@ -128,13 +128,13 @@ class tree { return branch_index; } - int num_children() const { + size_t num_children() const { 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]; } - int num_nodes() const { + size_t num_nodes() const { return child_index_.size() - 1; } @@ -149,7 +149,7 @@ class tree { } /// 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]); } @@ -159,10 +159,10 @@ class tree { } /// return the parent of branch b - int_type parent(int b) const { + int_type parent(size_t b) const { return parents_[b]; } - int_type& parent(int b) { + int_type& parent(size_t b) { return parents_[b]; } @@ -171,7 +171,7 @@ class 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()); // no need to rebalance if the root node has been requested @@ -222,16 +222,16 @@ class tree { auto nchild = nnode - 1; // data_ is partitioned as follows: // 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); child_index_ = data_(nchild, nchild+nnode+1); parents_ = data_(nchild+nnode+1, memory::end); // check that arrays have appropriate size // this should be moved into a unit test - assert(children_.size() == nchild); - assert(child_index_.size() == nnode+1); - assert(parents_.size() == nnode); + assert(children_.size() == unsigned(nchild)); + assert(child_index_.size() == unsigned(nnode+1)); + assert(parents_.size() == unsigned(nnode)); } /// Renumber the sub-tree with old_node as its root with new_node as diff --git a/tests/test_tree.cpp b/tests/test_tree.cpp index 3bd26796147d8d906fd88ae9b57c8708ef61e2e7..a0bd0742cdcf6041b80847bd1c5fd2b064a44d52 100644 --- a/tests/test_tree.cpp +++ b/tests/test_tree.cpp @@ -5,7 +5,7 @@ #include "gtest.h" -#include "cell_tree.hpp" +#include "../src/cell_tree.hpp" #include "json/src/json.hpp" using json = nlohmann::json; @@ -18,112 +18,112 @@ TEST(cell_tree, from_parent_index) { { std::vector<int> parent_index = {0}; cell_tree tree(parent_index); - EXPECT_EQ(tree.num_segments(), 1); - EXPECT_EQ(tree.num_children(0), 0); + EXPECT_EQ(tree.num_segments(), 1u); + EXPECT_EQ(tree.num_children(0), 0u); } // CASE 2 : empty parent_index { std::vector<int> parent_index; cell_tree tree(parent_index); - EXPECT_EQ(tree.num_segments(), 1); - EXPECT_EQ(tree.num_children(0), 0); + EXPECT_EQ(tree.num_segments(), 1u); + EXPECT_EQ(tree.num_children(0), 0u); } // tree with two segments off the root node { std::vector<int> parent_index = {0, 0, 1, 2, 0, 4}; cell_tree tree(parent_index); - EXPECT_EQ(tree.num_segments(), 3); + EXPECT_EQ(tree.num_segments(), 3u); // the root has 2 children - EXPECT_EQ(tree.num_children(0), 2); + EXPECT_EQ(tree.num_children(0), 2u); // the children are leaves - EXPECT_EQ(tree.num_children(1), 0); - EXPECT_EQ(tree.num_children(2), 0); + EXPECT_EQ(tree.num_children(1), 0u); + EXPECT_EQ(tree.num_children(2), 0u); } { // tree with three segments off the root node std::vector<int> parent_index = {0, 0, 1, 2, 0, 4, 0, 6, 7, 8}; cell_tree tree(parent_index); - EXPECT_EQ(tree.num_segments(), 4); + EXPECT_EQ(tree.num_segments(), 4u); // the root has 3 children - EXPECT_EQ(tree.num_children(0), 3); + EXPECT_EQ(tree.num_children(0), 3u); // the children are leaves - EXPECT_EQ(tree.num_children(1), 0); - EXPECT_EQ(tree.num_children(2), 0); - EXPECT_EQ(tree.num_children(3), 0); + EXPECT_EQ(tree.num_children(1), 0u); + EXPECT_EQ(tree.num_children(2), 0u); + 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 std::vector<int> parent_index = {0, 0, 1, 2, 0, 4, 0, 6, 7, 8, 9, 8, 11, 12}; cell_tree tree(parent_index); - EXPECT_EQ(tree.num_segments(), 6); + EXPECT_EQ(tree.num_segments(), 6u); // 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 ... - EXPECT_EQ(tree.num_children(3), 2); + EXPECT_EQ(tree.num_children(3), 2u); // the rest are leaves - EXPECT_EQ(tree.num_children(1), 0); - EXPECT_EQ(tree.num_children(2), 0); - EXPECT_EQ(tree.num_children(4), 0); - EXPECT_EQ(tree.num_children(5), 0); + EXPECT_EQ(tree.num_children(1), 0u); + EXPECT_EQ(tree.num_children(2), 0u); + EXPECT_EQ(tree.num_children(4), 0u); + EXPECT_EQ(tree.num_children(5), 0u); } { // // 0 // / // 1 - // / \ + // / \. // 2 3 std::vector<int> parent_index = {0,0,1,1}; 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(1), 2); - EXPECT_EQ(tree.num_children(2), 0); - EXPECT_EQ(tree.num_children(3), 0); + EXPECT_EQ(tree.num_children(0), 1u); + EXPECT_EQ(tree.num_children(1), 2u); + EXPECT_EQ(tree.num_children(2), 0u); + EXPECT_EQ(tree.num_children(3), 0u); } { // // 0 - // / \ + // / \. // 1 2 - // / \ + // / \. // 3 4 std::vector<int> parent_index = {0,0,0,1,1}; 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(1), 2); - EXPECT_EQ(tree.num_children(2), 0); - EXPECT_EQ(tree.num_children(3), 0); - EXPECT_EQ(tree.num_children(4), 0); + EXPECT_EQ(tree.num_children(0), 2u); + EXPECT_EQ(tree.num_children(1), 2u); + EXPECT_EQ(tree.num_children(2), 0u); + EXPECT_EQ(tree.num_children(3), 0u); + EXPECT_EQ(tree.num_children(4), 0u); } { // 0 - // / \ + // / \. // 1 2 - // / \ + // / \. // 3 4 - // / \ + // / \. // 5 6 std::vector<int> parent_index = {0,0,0,1,1,4,4}; 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(1), 2); - EXPECT_EQ(tree.num_children(2), 0); - EXPECT_EQ(tree.num_children(3), 0); - EXPECT_EQ(tree.num_children(4), 2); - EXPECT_EQ(tree.num_children(5), 0); - EXPECT_EQ(tree.num_children(6), 0); + EXPECT_EQ(tree.num_children(0), 2u); + EXPECT_EQ(tree.num_children(1), 2u); + EXPECT_EQ(tree.num_children(2), 0u); + EXPECT_EQ(tree.num_children(3), 0u); + EXPECT_EQ(tree.num_children(4), 2u); + EXPECT_EQ(tree.num_children(5), 0u); + EXPECT_EQ(tree.num_children(6), 0u); } } @@ -141,32 +141,32 @@ TEST(tree, change_root) { t.init_from_parent_index(parent_index); 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(1), 1); - EXPECT_EQ(t.num_children(2), 0); + EXPECT_EQ(t.num_children(0), 1u); + EXPECT_EQ(t.num_children(1), 1u); + EXPECT_EQ(t.num_children(2), 0u); } { // a cell with the following structure // make 1 the new root // 0 0 - // / \ /|\ + // / \ /|\. // 1 2 -> 1 2 3 // / \ | // 3 4 4 std::vector<int> parent_index = {0,0,0,1,1}; tree t; 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(1), 0); - EXPECT_EQ(t.num_children(2), 0); - EXPECT_EQ(t.num_children(3), 1); - EXPECT_EQ(t.num_children(4), 0); + EXPECT_EQ(t.num_children(0), 3u); + EXPECT_EQ(t.num_children(1), 0u); + EXPECT_EQ(t.num_children(2), 0u); + EXPECT_EQ(t.num_children(3), 1u); + EXPECT_EQ(t.num_children(4), 0u); } { // a cell with the following structure @@ -174,11 +174,11 @@ TEST(tree, change_root) { // unlike earlier tests, this decreases the depth // of the tree // 0 0 - // / \ /|\ + // / \ /|\. // 1 2 -> 1 2 5 - // / \ / \ \ + // / \ / \ \. // 3 4 3 4 6 - // / \ + // / \. // 5 6 std::vector<int> parent_index = {0,0,0,1,1,4,4}; tree t; @@ -186,15 +186,15 @@ TEST(tree, change_root) { 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(1), 0); - EXPECT_EQ(t.num_children(2), 2); - EXPECT_EQ(t.num_children(3), 0); - EXPECT_EQ(t.num_children(4), 0); - EXPECT_EQ(t.num_children(5), 1); - EXPECT_EQ(t.num_children(6), 0); + EXPECT_EQ(t.num_children(0), 3u); + EXPECT_EQ(t.num_children(1), 0u); + EXPECT_EQ(t.num_children(2), 2u); + EXPECT_EQ(t.num_children(3), 0u); + EXPECT_EQ(t.num_children(4), 0u); + EXPECT_EQ(t.num_children(5), 1u); + EXPECT_EQ(t.num_children(6), 0u); } } @@ -203,11 +203,11 @@ TEST(cell_tree, balance) { // a cell with the following structure // will balance around 1 // 0 0 - // / \ /|\ + // / \ /|\. // 1 2 -> 1 2 5 - // / \ / \ \ + // / \ / \ \. // 3 4 3 4 6 - // / \ + // / \. // 5 6 std::vector<int> parent_index = {0,0,0,1,1,4,4}; cell_tree t(parent_index); @@ -217,14 +217,14 @@ TEST(cell_tree, balance) { // the soma (original root) has moved to 5 in the new tree EXPECT_EQ(t.soma(), 5); - EXPECT_EQ(t.num_segments(), 7); - EXPECT_EQ(t.num_children(0),3); - EXPECT_EQ(t.num_children(1),0); - EXPECT_EQ(t.num_children(2),2); - EXPECT_EQ(t.num_children(3),0); - EXPECT_EQ(t.num_children(4),0); - EXPECT_EQ(t.num_children(5),1); - EXPECT_EQ(t.num_children(6),0); + EXPECT_EQ(t.num_segments(), 7u); + EXPECT_EQ(t.num_children(0),3u); + EXPECT_EQ(t.num_children(1),0u); + EXPECT_EQ(t.num_children(2),2u); + EXPECT_EQ(t.num_children(3),0u); + EXPECT_EQ(t.num_children(4),0u); + EXPECT_EQ(t.num_children(5),1u); + EXPECT_EQ(t.num_children(6),0u); EXPECT_EQ(t.parent(0),-1); EXPECT_EQ(t.parent(1), 0); EXPECT_EQ(t.parent(2), 0); diff --git a/vector b/vector index 79ad5236b219a7618a8cda8caad6cd3de1f9e122..a8dfadd460262ebbc1bc22b159efe9e33ad1d359 160000 --- a/vector +++ b/vector @@ -1 +1 @@ -Subproject commit 79ad5236b219a7618a8cda8caad6cd3de1f9e122 +Subproject commit a8dfadd460262ebbc1bc22b159efe9e33ad1d359