From a89f41bc9888d071228f0effc5cc58dfe4c9ed2d Mon Sep 17 00:00:00 2001 From: bcumming <bcumming@cscs.ch> Date: Tue, 6 Sep 2016 12:30:10 +0200 Subject: [PATCH] Small optimization of mechanism initialization * move from index_view to const_index_view for mechaninism inintialization. This allows us to pass more generic container types to the constructor while avoiding redundant copies * NOTE: required update of * external/vector * external/modparser * fixed signed-vs-unsigned comparison warning in algorithims.hpp --- external/modparser | 2 +- external/vector | 2 +- src/algorithms.hpp | 2 +- src/mechanism.hpp | 5 +++-- src/mechanism_catalogue.hpp | 13 +++++++++---- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/external/modparser b/external/modparser index b200bf63..ad8d926f 160000 --- a/external/modparser +++ b/external/modparser @@ -1 +1 @@ -Subproject commit b200bf6376a2dc30edea98fcc2375fc9be095135 +Subproject commit ad8d926fd4a3e92cdcfb7b77c527550f859496d2 diff --git a/external/vector b/external/vector index c8678e80..6a9798d8 160000 --- a/external/vector +++ b/external/vector @@ -1 +1 @@ -Subproject commit c8678e80660cd63b293ade80ece8eed2249c1b06 +Subproject commit 6a9798d87f83246f36c999540d4a7810fb33d199 diff --git a/src/algorithms.hpp b/src/algorithms.hpp index f626fa98..7be1406a 100644 --- a/src/algorithms.hpp +++ b/src/algorithms.hpp @@ -254,7 +254,7 @@ std::vector<typename C::value_type> make_parent_index( return {}; } - EXPECTS(parent_index.size() == branch_index.back()); + EXPECTS(parent_index.size()-branch_index.back() == 0); EXPECTS(has_contiguous_compartments(parent_index)); EXPECTS(is_strictly_monotonic_increasing(branch_index)); diff --git a/src/mechanism.hpp b/src/mechanism.hpp index ce978660..d826b299 100644 --- a/src/mechanism.hpp +++ b/src/mechanism.hpp @@ -27,11 +27,12 @@ public: using view_type = typename vector_type::view_type; using index_type = memory::HostVector<size_type>; using index_view = typename index_type::view_type; + using const_index_view = typename index_type::const_view_type; using indexed_view_type = indexed_view<value_type, size_type>; using ion_type = ion<value_type, size_type>; - mechanism(view_type vec_v, view_type vec_i, index_view node_index): + mechanism(view_type vec_v, view_type vec_i, const_index_view node_index): vec_v_(vec_v), vec_i_(vec_i), node_index_(node_index), vec_area_(nullptr, 0) {} @@ -85,7 +86,7 @@ mechanism_ptr<typename M::value_type, typename M::size_type> make_mechanism( typename M::view_type vec_v, typename M::view_type vec_i, - typename M::index_view node_indices + typename M::const_index_view node_indices ) { return util::make_unique<M>(vec_v, vec_i, node_indices); } diff --git a/src/mechanism_catalogue.hpp b/src/mechanism_catalogue.hpp index 7fb2927c..5e79cd9f 100644 --- a/src/mechanism_catalogue.hpp +++ b/src/mechanism_catalogue.hpp @@ -18,20 +18,21 @@ template <typename T, typename I> struct catalogue { using view_type = typename mechanism<T, I>::view_type; using index_view = typename mechanism<T, I>::index_view; + using const_index_view = typename mechanism<T, I>::const_index_view; template <typename Indices> static mechanism_ptr<T, I> make( const std::string& name, view_type vec_v, view_type vec_i, - Indices& node_indices) + Indices const& node_indices) { auto entry = mech_map.find(name); if (entry==mech_map.end()) { throw std::out_of_range("no such mechanism"); } - auto node_view = index_view{node_indices}; + const_index_view node_view(node_indices); return entry->second(vec_v, vec_i, node_view); } @@ -40,11 +41,15 @@ struct catalogue { } private: - using maker_type = mechanism_ptr<T, I> (*)(view_type, view_type, index_view); + using maker_type = mechanism_ptr<T, I> (*)(view_type, view_type, const_index_view); static const std::map<std::string, maker_type> mech_map; template <template <typename, typename> class mech> - static mechanism_ptr<T, I> maker(view_type vec_v, view_type vec_i, index_view node_indices) { + static mechanism_ptr<T, I> maker( + view_type vec_v, + view_type vec_i, + const_index_view node_indices) + { return make_mechanism<mech<T, I>>(vec_v, vec_i, node_indices); } }; -- GitLab