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

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
parent cfe5f4bf
No related branches found
No related tags found
No related merge requests found
Subproject commit b200bf6376a2dc30edea98fcc2375fc9be095135 Subproject commit ad8d926fd4a3e92cdcfb7b77c527550f859496d2
Subproject commit c8678e80660cd63b293ade80ece8eed2249c1b06 Subproject commit 6a9798d87f83246f36c999540d4a7810fb33d199
...@@ -254,7 +254,7 @@ std::vector<typename C::value_type> make_parent_index( ...@@ -254,7 +254,7 @@ std::vector<typename C::value_type> make_parent_index(
return {}; return {};
} }
EXPECTS(parent_index.size() == branch_index.back()); EXPECTS(parent_index.size()-branch_index.back() == 0);
EXPECTS(has_contiguous_compartments(parent_index)); EXPECTS(has_contiguous_compartments(parent_index));
EXPECTS(is_strictly_monotonic_increasing(branch_index)); EXPECTS(is_strictly_monotonic_increasing(branch_index));
......
...@@ -27,11 +27,12 @@ public: ...@@ -27,11 +27,12 @@ public:
using view_type = typename vector_type::view_type; using view_type = typename vector_type::view_type;
using index_type = memory::HostVector<size_type>; using index_type = memory::HostVector<size_type>;
using index_view = typename index_type::view_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 indexed_view_type = indexed_view<value_type, size_type>;
using ion_type = ion<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) 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> ...@@ -85,7 +86,7 @@ mechanism_ptr<typename M::value_type, typename M::size_type>
make_mechanism( make_mechanism(
typename M::view_type vec_v, typename M::view_type vec_v,
typename M::view_type vec_i, 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); return util::make_unique<M>(vec_v, vec_i, node_indices);
} }
......
...@@ -18,20 +18,21 @@ template <typename T, typename I> ...@@ -18,20 +18,21 @@ template <typename T, typename I>
struct catalogue { struct catalogue {
using view_type = typename mechanism<T, I>::view_type; using view_type = typename mechanism<T, I>::view_type;
using index_view = typename mechanism<T, I>::index_view; using index_view = typename mechanism<T, I>::index_view;
using const_index_view = typename mechanism<T, I>::const_index_view;
template <typename Indices> template <typename Indices>
static mechanism_ptr<T, I> make( static mechanism_ptr<T, I> make(
const std::string& name, const std::string& name,
view_type vec_v, view_type vec_v,
view_type vec_i, view_type vec_i,
Indices& node_indices) Indices const& node_indices)
{ {
auto entry = mech_map.find(name); auto entry = mech_map.find(name);
if (entry==mech_map.end()) { if (entry==mech_map.end()) {
throw std::out_of_range("no such mechanism"); 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); return entry->second(vec_v, vec_i, node_view);
} }
...@@ -40,11 +41,15 @@ struct catalogue { ...@@ -40,11 +41,15 @@ struct catalogue {
} }
private: 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; static const std::map<std::string, maker_type> mech_map;
template <template <typename, typename> class mech> 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); return make_mechanism<mech<T, I>>(vec_v, vec_i, node_indices);
} }
}; };
......
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