diff --git a/arbor/CMakeLists.txt b/arbor/CMakeLists.txt index 29f5f32e6a..7bae188dd6 100644 --- a/arbor/CMakeLists.txt +++ b/arbor/CMakeLists.txt @@ -20,10 +20,7 @@ set(arbor_sources fvm_layout.cpp fvm_lowered_cell_impl.cpp hardware/memory.cpp - hardware/power.cpp iexpr.cpp - io/locked_ostream.cpp - io/serialize_hex.cpp label_resolution.cpp lif_cell_group.cpp cable_cell_group.cpp @@ -51,7 +48,6 @@ set(arbor_sources profile/clock.cpp profile/memory_meter.cpp profile/meter_manager.cpp - profile/power_meter.cpp profile/profiler.cpp schedule.cpp spike_event_io.cpp diff --git a/arbor/backends/gpu/fvm.hpp b/arbor/backends/gpu/fvm.hpp index eaac5ab2bb..37023c4f40 100644 --- a/arbor/backends/gpu/fvm.hpp +++ b/arbor/backends/gpu/fvm.hpp @@ -1,16 +1,11 @@ #pragma once -#include #include #include #include #include "memory/memory.hpp" -#include "util/rangeutil.hpp" - -#include "backends/event.hpp" - #include "backends/gpu/gpu_store_types.hpp" #include "backends/gpu/shared_state.hpp" @@ -20,7 +15,6 @@ namespace arb { namespace gpu { struct backend { - static bool is_supported() { return true; } static std::string name() { return "gpu"; } using value_type = arb_value_type; diff --git a/arbor/backends/multicore/fvm.hpp b/arbor/backends/multicore/fvm.hpp index be787cbcc4..a845a52bf2 100644 --- a/arbor/backends/multicore/fvm.hpp +++ b/arbor/backends/multicore/fvm.hpp @@ -16,7 +16,6 @@ namespace arb { namespace multicore { struct backend { - static bool is_supported() { return true; } static std::string name() { return "cpu"; } using value_type = arb_value_type; diff --git a/arbor/hardware/power.cpp b/arbor/hardware/power.cpp deleted file mode 100644 index 7ca8df68ff..0000000000 --- a/arbor/hardware/power.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include - -#include "power.hpp" - -// Currently only supporting Cray PM counters. - -#define CRAY_PM_COUNTER_ENERGY "/sys/cray/pm_counters/energy" - -namespace arb { -namespace hw { - -bool has_energy_measurement() { - return static_cast(std::ifstream(CRAY_PM_COUNTER_ENERGY)); -} - -energy_size_type energy() { - energy_size_type result = energy_size_type(-1); - - std::ifstream fid(CRAY_PM_COUNTER_ENERGY); - if (fid) { - fid >> result; - } - - return result; -} - -} // namespace hw -} // namespace arb - diff --git a/arbor/hardware/power.hpp b/arbor/hardware/power.hpp deleted file mode 100644 index 003a30798b..0000000000 --- a/arbor/hardware/power.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include - -namespace arb { -namespace hw { - -// Test for support on configured architecture: -bool has_energy_measurement(); - -// Energy in Joules (J) -using energy_size_type = std::uint64_t; - -// Returns energy_size_type(-1) if unable to read energy -energy_size_type energy(); - -} // namespace hw -} // namespace arb diff --git a/arbor/io/locked_ostream.cpp b/arbor/io/locked_ostream.cpp deleted file mode 100644 index 1aa8552170..0000000000 --- a/arbor/io/locked_ostream.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include -#include - -#include "locked_ostream.hpp" - -namespace arb { -namespace io { - -using tbl_type = std::unordered_map>; - -static tbl_type& g_mex_tbl() { - static tbl_type tbl; - return tbl; -} - -static std::mutex& g_mex_tbl_mex() { - static std::mutex mex; - return mex; -} - -static std::shared_ptr register_sbuf(std::streambuf* b) { - if (b) { - std::lock_guard lock(g_mex_tbl_mex()); - - auto& wptr = g_mex_tbl()[b]; - auto mex = wptr.lock(); - if (!mex) { - mex = std::shared_ptr(new std::mutex); - wptr = mex; - } - return mex; - } - else { - return std::shared_ptr(); - } -} - -static void deregister_sbuf(std::streambuf* b) { - if (b) { - std::lock_guard lock(g_mex_tbl_mex()); - - auto i = g_mex_tbl().find(b); - if (i!=g_mex_tbl().end() && !(i->second.use_count())) { - g_mex_tbl().erase(i); - } - } -} - -locked_ostream::locked_ostream(std::streambuf *b): - std::ostream(b), - mex(register_sbuf(b)) -{} - - -locked_ostream::locked_ostream(locked_ostream&& other): - std::ostream(std::move(other)), - mex(std::move(other.mex)) -{ - set_rdbuf(other.rdbuf()); - other.set_rdbuf(nullptr); -} - -locked_ostream::~locked_ostream() { - mex.reset(); - deregister_sbuf(rdbuf()); -} - -std::unique_lock locked_ostream::guard() { - return std::unique_lock(*mex); -} - -} // namespace io -} // namespace arb diff --git a/arbor/io/locked_ostream.hpp b/arbor/io/locked_ostream.hpp deleted file mode 100644 index 20ecfc74a6..0000000000 --- a/arbor/io/locked_ostream.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -// Lockable ostream over a provided streambuf. - -#include -#include -#include - -namespace arb { -namespace io { - -struct locked_ostream: std::ostream { - locked_ostream(std::streambuf *b); - locked_ostream(locked_ostream&& other); - - ~locked_ostream(); - - std::unique_lock guard(); - -private: - std::shared_ptr mex; -}; - -} // namespace io -} // namespace arb diff --git a/arbor/io/save_ios.hpp b/arbor/io/save_ios.hpp deleted file mode 100644 index adfcda2475..0000000000 --- a/arbor/io/save_ios.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -// RAII save-and-restore ios formatting flags. - -#include - -namespace arb { -namespace io { - -struct save_ios_flags { - std::ios_base& ios; - std::ios_base::fmtflags flags; - - save_ios_flags(std::ios_base& ios): - ios(ios), flags(ios.flags()) {} - - save_ios_flags(const save_ios_flags&) = delete; - - ~save_ios_flags() { ios.flags(flags); } -}; - - -} // namespace io -} // namespace arb diff --git a/arbor/io/serialize_hex.cpp b/arbor/io/serialize_hex.cpp deleted file mode 100644 index 522f8401a6..0000000000 --- a/arbor/io/serialize_hex.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Adaptor for hexadecimal output to a std::ostream. - -#include -#include - -// Required for endianness macros: -#include - -#include "io/serialize_hex.hpp" - -namespace arb { -namespace io { - -namespace impl { - - enum class endian { - little = __ORDER_LITTLE_ENDIAN__, - big = __ORDER_BIG_ENDIAN__, - native = __BYTE_ORDER__ - }; - - std::ostream& operator<<(std::ostream& out, const hex_inline_wrap& h) { - using std::ptrdiff_t; - - constexpr bool little = endian::native==endian::little; - ptrdiff_t width = h.width; - const unsigned char* from = h.from; - const unsigned char* end = h.from+h.size; - std::string buf; - - auto emit = [&buf](unsigned char c) { - const char* digit = "0123456789abcdef"; - buf += digit[(c>>4)&0xf]; - buf += digit[c&0xf]; - }; - - constexpr unsigned bufsz = 512; - unsigned bufmargin = 4*width+1; - - buf.reserve(bufsz); - while (end-from>width) { - if (buf.size()+bufmargin>=bufsz) { - out << buf; - buf.clear(); - } - for (ptrdiff_t i = 0; i - -namespace arb { -namespace io { - -namespace impl { - // Wrapper for emitting values on an ostream as a sequence of hex digits. - struct hex_inline_wrap { - const unsigned char* from; - std::size_t size; - unsigned width; - }; - - std::ostream& operator<<(std::ostream&, const hex_inline_wrap&); -} // namespace impl - -// Inline hexadecimal adaptor: group output in `width` bytes. - -template -impl::hex_inline_wrap hex_inline(const T& obj, unsigned width = 4) { - return impl::hex_inline_wrap{reinterpret_cast(&obj), sizeof obj, width}; -} - -// Inline hexadecimal adaptor: print `n` bytes of data from `ptr`, grouping output in `width` bytes. - -template -impl::hex_inline_wrap hex_inline_n(const T* ptr, std::size_t n, unsigned width = 4) { - return impl::hex_inline_wrap{reinterpret_cast(ptr), n, width}; -} - -} // namespace io -} // namespace arb - diff --git a/arbor/io/trace.hpp b/arbor/io/trace.hpp deleted file mode 100644 index 5b50b7d60a..0000000000 --- a/arbor/io/trace.hpp +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once - -// Internal TRACE macros and formatters for debugging during -// development. - -#include -#include - -// Required for endianness macros: -#include - -#include "io/locked_ostream.hpp" -#include "io/sepval.hpp" -#include "io/serialize_hex.hpp" - - -// TRACE(expr1 [, expr2 ...]) -// -// Emit current source location to std::cerr, followed by the -// literal expressions expr1, ..., and then the values of those expressions. -// -// TRACE output is to std::cerr is serialized. - -#define TRACE(...) arb::impl::debug_emit_trace(__FILE__, __LINE__, #__VA_ARGS__, ##__VA_ARGS__) - - -// DEBUG << ...; -// -// Emit arguments to std::cerr followed by a newline. -// DEBUG output to std::cerr is serialized. - -#define DEBUG arb::impl::emit_nl_locked(std::cerr.rdbuf()) - - -namespace arb { - -namespace impl { - inline void debug_emit_csv(std::ostream&) {} - - template - void debug_emit_csv(std::ostream& out, const Head& head, const Tail&... tail) { - out << head; - if (sizeof...(tail)) { - out << ", "; - } - debug_emit_csv(out, tail...); - } - - inline void debug_emit_trace_leader(std::ostream& out, const char* file, int line, const char* vars) { - out << file << ':' << line << ": " << vars << ": "; - } - - struct emit_nl_locked: public io::locked_ostream { - emit_nl_locked(std::streambuf* buf): - io::locked_ostream(buf), - lock_(this->guard()) - {} - - ~emit_nl_locked() { - if (rdbuf()) { - (*this) << std::endl; - } - } - - private: - std::unique_lock lock_; - }; - - template - void debug_emit_trace(const char* file, int line, const char* varlist, const Args&... args) { - impl::emit_nl_locked out(std::cerr.rdbuf()); - - out.precision(17); - impl::debug_emit_trace_leader(out, file, line, varlist); - impl::debug_emit_csv(out, args...); - } -} // namespace impl - -} // namespace arb diff --git a/arbor/matrix.hpp b/arbor/matrix.hpp deleted file mode 100644 index 3b69db5048..0000000000 --- a/arbor/matrix.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include - -#include - -#include -#include - -#include - -namespace arb { - -/// Hines matrix -/// Make the back end state implementation optional to allow for -/// testing different implementations in the same code. -template -class matrix { -public: - using backend = Backend; - using array = typename backend::array; - using iarray = typename backend::iarray; - using const_view = const array&; - using state = State; // backend specific storage for matrix state - - matrix() = default; - - matrix(const std::vector& pi, - const std::vector& ci, - const std::vector& cv_capacitance, - const std::vector& face_conductance, - const std::vector& cv_area, - const std::vector& cell_to_intdom): - num_cells_{ci.size() - 1}, - state_(pi, ci, cv_capacitance, face_conductance, cv_area, cell_to_intdom) - { - arb_assert(cell_index()[num_cells()] == arb_index_type(parent_index().size())); - } - - /// the dimension of the matrix (i.e. the number of rows or colums) - std::size_t size() const { return state_.size(); } - /// the number of cell matrices that have been packed together - std::size_t num_cells() const { return num_cells_; } - /// the vector holding the parent index - const iarray& parent_index() const { return state_.parent_index; } - /// the partition of the parent index over the cells - const iarray& cell_index() const { return state_.cell_cv_divs; } - /// Solve the linear system into a given solution storage. - void solve(array& to) { state_.solve(to); } - /// Assemble the matrix for given dt - void assemble(const_view& dt, const_view& U, const_view& I, const_view& g) { state_.assemble(dt, U, I, g); } - -private: - std::size_t num_cells_ = 0; - -public: - // Provide via public interface to make testing much easier. If you modify - // this directly without knowing what you are doing, you get what you - // deserve. - state state_; -}; - -} // namespace arb diff --git a/arbor/merge_events.cpp b/arbor/merge_events.cpp index 9dd71ef488..ccfcd7cd38 100644 --- a/arbor/merge_events.cpp +++ b/arbor/merge_events.cpp @@ -1,11 +1,9 @@ -#include #include #include #include #include -#include "io/trace.hpp" #include "merge_events.hpp" #include "util/tourney_tree.hpp" diff --git a/arbor/profile/meter_manager.cpp b/arbor/profile/meter_manager.cpp index 3a805dde5f..3d8ca3360a 100644 --- a/arbor/profile/meter_manager.cpp +++ b/arbor/profile/meter_manager.cpp @@ -4,7 +4,6 @@ #include #include "memory_meter.hpp" -#include "power_meter.hpp" #include "execution_context.hpp" #include "util/hostname.hpp" @@ -49,9 +48,6 @@ meter_manager::meter_manager() { if (auto m = make_gpu_memory_meter()) { meters_.push_back(std::move(m)); } - if (auto m = make_power_meter()) { - meters_.push_back(std::move(m)); - } }; void meter_manager::start(context ctx) { diff --git a/arbor/profile/power_meter.cpp b/arbor/profile/power_meter.cpp deleted file mode 100644 index aa5adf02de..0000000000 --- a/arbor/profile/power_meter.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include - -#include - -#include "hardware/power.hpp" - -namespace arb { -namespace profile { - -class power_meter: public meter { - std::vector readings_; - -public: - std::string name() override { - return "energy"; - } - - std::string units() override { - return "J"; - } - - std::vector measurements() override { - std::vector diffs; - - for (auto i=1ul; i - -namespace arb { -namespace profile { - -meter_ptr make_power_meter(); - -} // namespace profile -} // namespace arb diff --git a/arbor/util/cycle.hpp b/arbor/util/cycle.hpp deleted file mode 100644 index 905c59e0d3..0000000000 --- a/arbor/util/cycle.hpp +++ /dev/null @@ -1,213 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "util/iterutil.hpp" -#include "util/range.hpp" - -namespace arb { -namespace util { - -template -class cyclic_iterator : public iterator_adaptor, I> { - using base = iterator_adaptor, I>; - friend class iterator_adaptor, I>; - - I begin_; - I inner_; - S end_; - typename base::difference_type off_; // offset from begin - - const I& inner() const { - return inner_; - } - - I& inner() { - return inner_; - } - -public: - using value_type = typename base::value_type; - using difference_type = typename base::difference_type; - - cyclic_iterator() = default; - - template - cyclic_iterator(Iter&& iter, Sentinel&& sentinel) - : begin_(std::forward(iter)), - inner_(std::forward(iter)), - end_(std::forward(sentinel)), - off_(0) - { } - - cyclic_iterator(const cyclic_iterator& other) - : begin_(other.begin_), - inner_(other.inner_), - end_(other.end_), - off_(other.off_) - { } - - cyclic_iterator(cyclic_iterator&& other) - : begin_(std::move(other.begin_)), - inner_(std::move(other.inner_)), - end_(std::move(other.end_)), - off_(other.off_) - { } - - - cyclic_iterator& operator=(const cyclic_iterator& other) { - if (this != &other) { - inner_ = other.inner_; - begin_ = other.begin_; - end_ = other.end_; - off_ = other.off_; - } - - return *this; - } - - cyclic_iterator& operator=(cyclic_iterator&& other) { - if (this != &other) { - inner_ = std::move(other.inner_); - begin_ = std::move(other.begin_); - end_ = std::move(other.end_); - off_ = other.off_; - } - - return *this; - } - - // forward and input iterator requirements - value_type operator*() const { - return *inner_; - } - - value_type operator[](difference_type n) const { - return *(*this + n); - } - - cyclic_iterator& operator++() { - if (++inner_ == end_) { - // wrap around - inner_ = begin_; - } - - ++off_; - return *this; - } - - cyclic_iterator operator++(int) { - cyclic_iterator iter(*this); - ++(*this); - return iter; - } - - cyclic_iterator& operator--() { - if (inner_ == begin_) { - // wrap around; use upto() to handle efficiently the move to the end - // in case inner_ is a bidirectional iterator - inner_ = upto(inner_, end_); - } - else { - --inner_; - } - - --off_; - return *this; - } - - cyclic_iterator operator--(int) { - cyclic_iterator iter(*this); - --(*this); - return iter; - } - - cyclic_iterator& operator+=(difference_type n) { - // wrap distance - auto size = util::distance(begin_, end_); - - // calculate distance from begin - auto pos = (off_ += n); - if (pos < 0) { - auto mod = -pos % size; - pos = mod ? size - mod : 0; - } - else { - pos = pos % size; - } - - inner_ = std::next(begin_, pos); - return *this; - } - - cyclic_iterator& operator-=(difference_type n) { - return this->operator+=(-n); - } - - bool operator==(const cyclic_iterator& other) const { - return begin_ == other.begin_ && off_ == other.off_; - } - - bool operator!=(const cyclic_iterator& other) const { - return !(*this == other); - } - - cyclic_iterator operator-(difference_type n) const { - cyclic_iterator c(*this); - return c -= n; - } - - difference_type operator-(const cyclic_iterator& other) const { - return off_ - other.off_; - } - - bool operator<(const cyclic_iterator& other) const { - return off_ < other.off_; - } - - // expose inner iterator for testing against a sentinel - template - bool operator==(const Sentinel& s) const { - return inner_ == s; - } - - template - bool operator!=(const Sentinel& s) const { - return !(inner_ == s); - } -}; - -template -cyclic_iterator make_cyclic_iterator(const I& iter, const S& sentinel) { - return cyclic_iterator(iter, sentinel); -} - - -template -auto cyclic_view(Seq&& s) { - using std::begin; - using std::end; - - auto b = begin(s); - auto e = end(s); - - if constexpr (is_regular_sequence_v) { - return make_range(make_cyclic_iterator(b, e), make_cyclic_iterator(e, e)); - } - else { - return make_range(make_cyclic_iterator(b, e), e); - } -} - -// Handle initializer lists -template -auto cyclic_view(const std::initializer_list& list) { - return make_range( - make_cyclic_iterator(list.begin(), list.end()), - make_cyclic_iterator(list.end(), list.end())); -} - -} // namespace util -} // namespace arb diff --git a/arbor/util/meta.hpp b/arbor/util/meta.hpp index d9f30584fd..ed0055f088 100644 --- a/arbor/util/meta.hpp +++ b/arbor/util/meta.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/arbor/util/nop.hpp b/arbor/util/nop.hpp deleted file mode 100644 index 4f3fdd3ddb..0000000000 --- a/arbor/util/nop.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -/* - * Provide object that implicitly converts to - * a std::function object that does nothing but return a - * default-constructed type or void. - */ - -#include - -namespace arb { -namespace util { - -struct nop_function_t { - template - operator std::function() const { - return [](Args...) { return R{}; }; - } - - template - operator std::function() const { - return [](Args...) { }; - } - - // keep clang happy: see CWG issue #253, - // http://open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#253 - constexpr nop_function_t() {} -}; - -static constexpr nop_function_t nop_function; - -} // namespace util -} // namespace arb diff --git a/arbor/util/rangeutil.hpp b/arbor/util/rangeutil.hpp index 312bd55877..2feb981678 100644 --- a/arbor/util/rangeutil.hpp +++ b/arbor/util/rangeutil.hpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -19,18 +18,6 @@ namespace arb { namespace util { -// Present a single item as a range - -template -range singleton_view(T& item) { - return {&item, &item+1}; -} - -template -range singleton_view(const T& item) { - return {&item, &item+1}; -} - // Non-owning views and subviews template diff --git a/modcc/identifier.hpp b/modcc/identifier.hpp index a2ce9fbbc3..08a3f40fdb 100644 --- a/modcc/identifier.hpp +++ b/modcc/identifier.hpp @@ -62,10 +62,6 @@ enum class sourceKind { no_source }; -inline std::string yesno(bool val) { - return std::string(val ? "yes" : "no"); -}; - //////////////////////////////////////////// // to_string functions convert types // to strings for printing diagnostics diff --git a/modcc/printer/printerutil.hpp b/modcc/printer/printerutil.hpp index 7fc8cfa34c..8033fc10a5 100644 --- a/modcc/printer/printerutil.hpp +++ b/modcc/printer/printerutil.hpp @@ -23,14 +23,6 @@ inline const char* arb_header_prefix() { return prefix; } -// TODO: this function will be obsoleted once arbor private/public headers are -// properly split. - -inline const char* arb_private_header_prefix() { - static const char* prefix = ""; - return prefix; -} - struct namespace_declaration_open { const std::vector& ids; namespace_declaration_open(const std::vector& ids): ids(ids) {} @@ -163,16 +155,3 @@ struct ARB_LIBMODCC_API indexed_variable_info { }; ARB_LIBMODCC_API indexed_variable_info decode_indexed_variable(IndexedVariable* sym); - -template -size_t emit_array(std::ostream& out, const C& vars) { - auto n = 0ul; - io::separator sep("", ", "); - out << "{ "; - for (const auto& var: vars) { - out << sep << var; - ++n; - } - out << " }"; - return n; -} diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index fc3f79e896..43dd3560a6 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -68,7 +68,6 @@ set(unit_sources test_cv_geom.cpp test_cv_layout.cpp test_cv_policy.cpp - test_cycle.cpp test_domain_decomposition.cpp test_dry_run_context.cpp test_event_delivery.cpp @@ -96,7 +95,6 @@ set(unit_sources test_matrix.cpp test_mcable_map.cpp test_cable_cell_group.cpp - test_mechanisms.cpp test_mech_temp_diam.cpp test_mechcat.cpp test_mechinfo.cpp diff --git a/test/unit/test_cycle.cpp b/test/unit/test_cycle.cpp deleted file mode 100644 index ad0b58c1ae..0000000000 --- a/test/unit/test_cycle.cpp +++ /dev/null @@ -1,225 +0,0 @@ -#include - -#include -#include -#include - -#include "common.hpp" -#include -#include - -using namespace arb; - -TEST(cycle_iterator, construct) { - std::vector values = { 4, 2, 3 }; - auto cycle_iter = util::make_cyclic_iterator(values.cbegin(), values.cend()); - - { - // copy constructor - auto cycle_iter_copy(cycle_iter); - EXPECT_EQ(cycle_iter, cycle_iter_copy); - } - - { - // copy assignment - auto cycle_iter_copy = cycle_iter; - EXPECT_EQ(cycle_iter, cycle_iter_copy); - } - - { - // move constructor - auto cycle_iter_copy( - util::make_cyclic_iterator(values.cbegin(), values.cend()) - ); - EXPECT_EQ(cycle_iter, cycle_iter_copy); - } -} - - -TEST(cycle_iterator, increment) { - std::vector values = { 4, 2, 3 }; - - { - // test operator++ - auto cycle_iter = util::make_cyclic_iterator(values.cbegin(), - values.cend()); - auto cycle_iter_copy = cycle_iter; - - auto values_size = values.size(); - for (auto i = 0u; i < 2*values_size; ++i) { - EXPECT_EQ(values[i % values_size], *cycle_iter); - EXPECT_EQ(values[i % values_size], *cycle_iter_copy++); - ++cycle_iter; - } - } - - { - // test operator[] - auto cycle_iter = util::make_cyclic_iterator(values.cbegin(), - values.cend()); - - for (auto i = 0u; i < values.size(); ++i) { - EXPECT_EQ(values[i], cycle_iter[values.size() + i]); - } - } - - { - auto cycle_iter = util::make_cyclic_iterator(values.cbegin(), - values.cend()); - EXPECT_NE(cycle_iter + 1, cycle_iter + 10); - } -} - -TEST(cycle_iterator, decrement) { - std::vector values = { 4, 2, 3 }; - - { - // test operator-- - auto cycle_iter = util::make_cyclic_iterator(values.cbegin(), - values.cend()); - auto cycle_iter_copy = cycle_iter; - - auto values_size = values.size(); - for (auto i = 0u; i < 2*values_size; ++i) { - --cycle_iter; - cycle_iter_copy--; - auto val = values[values_size - i%values_size - 1]; - EXPECT_EQ(val, *cycle_iter); - EXPECT_EQ(val, *cycle_iter_copy); - } - } - - { - // test operator[] - auto cycle_iter = util::make_cyclic_iterator(values.cbegin(), - values.cend()); - int values_size = values.size(); - for (int i = 0; i < 2*values_size; ++i) { - auto pos = i % values_size; - pos = pos ? values_size - pos : 0; - EXPECT_EQ(values[pos], cycle_iter[-i]); - } - } - - { - auto cycle_iter = util::make_cyclic_iterator(values.cbegin(), - values.cend()); - EXPECT_NE(cycle_iter - 2, cycle_iter - 5); - EXPECT_NE(cycle_iter + 1, cycle_iter - 5); - } -} - -TEST(cycle_iterator, carray) { - int values[] = { 4, 2, 3 }; - auto cycle_iter = util::make_cyclic_iterator(std::cbegin(values), - std::cend(values)); - auto values_size = std::size(values); - for (auto i = 0u; i < 2*values_size; ++i) { - EXPECT_EQ(values[i % values_size], *cycle_iter++); - } -} - -TEST(cycle_iterator, sentinel) { - using testing::null_terminated; - - auto msg = "hello"; - auto cycle_iter = util::make_cyclic_iterator(msg, null_terminated); - - auto msg_len = std::string(msg).size(); - for (auto i = 0u; i < 2*msg_len; ++i) { - EXPECT_EQ(msg[i % msg_len], *cycle_iter++); - } -} - - -TEST(cycle, cyclic_view) { - std::vector values = { 4, 2, 3 }; - std::vector values_new; - - std::copy_n(util::cyclic_view(values).cbegin(), 10, - std::back_inserter(values_new)); - - EXPECT_EQ(10u, values_new.size()); - - auto i = 0; - for (auto const& v : values_new) { - EXPECT_EQ(values[i++ % values.size()], v); - } -} - -TEST(cycle, cyclic_view_initlist) { - std::vector values; - - std::copy_n(util::cyclic_view({2., 3., 4.}).cbegin(), 10, - std::back_inserter(values)); - - EXPECT_EQ(10u, values.size()); - - auto i = 0; - for (auto const& v : values) { - EXPECT_EQ(2 + i++ % 3, v); - } -} - -TEST(cycle_iterator, difference) { - int values[] = { 4, 2, 3 }; - - auto cycle = util::cyclic_view(values); - auto c1 = cycle.begin(); - - auto c2 = c1; - EXPECT_EQ(0, c2-c1); - - ++c2; - EXPECT_EQ(1, c2-c1); - - ++c1; - EXPECT_EQ(0, c2-c1); - - c2 += 6; - EXPECT_EQ(6, c2-c1); - - c1 += 2; - EXPECT_EQ(4, c2-c1); - - --c2; - EXPECT_EQ(3, c2-c1); - - c1 -= 3; - EXPECT_EQ(6, c2-c1); -} - -TEST(cycle_iterator, order) { - int values[] = { 4, 2, 3 }; - - auto cycle = util::cyclic_view(values); - auto c1 = cycle.begin(); - auto c2 = c1; - - EXPECT_FALSE(c1 < c2); - EXPECT_FALSE(c2 < c1); - EXPECT_TRUE(c1 <= c2); - EXPECT_TRUE(c1 >= c2); - - c2 += std::size(values); - - EXPECT_TRUE(c1 < c2); - EXPECT_FALSE(c2 < c1); - EXPECT_TRUE(c1 <= c2); - EXPECT_FALSE(c1 >= c2); -} - -TEST(cycle, cyclic_view_sentinel) { - const char *msg = "hello"; - auto cycle = util::cyclic_view( - util::make_range(msg, testing::null_terminated) - ); - - std::string msg_new; - auto msg_new_size = 2*std::string(msg).size(); - for (auto i = 0u; i < msg_new_size; ++i) { - msg_new += cycle[i]; - } - - EXPECT_EQ("hellohello", msg_new); -} diff --git a/test/unit/test_mechanisms.cpp b/test/unit/test_mechanisms.cpp deleted file mode 100644 index 3cbf46bb4a..0000000000 --- a/test/unit/test_mechanisms.cpp +++ /dev/null @@ -1,244 +0,0 @@ -#include - -// TODO: Amend for new mechanism architecture -#if 0 - -// Prototype mechanisms in tests -#include "mech_proto/expsyn_cpu.hpp" -#include "mech_proto/exp2syn_cpu.hpp" -#include "mech_proto/hh_cpu.hpp" -#include "mech_proto/pas_cpu.hpp" -#include "mech_proto/test_kin1_cpu.hpp" -#include "mech_proto/test_kinlva_cpu.hpp" -#include "mech_proto/test_ca_cpu.hpp" - -// modcc generated mechanisms -#include "mechanisms/multicore/expsyn_cpu.hpp" -#include "mechanisms/multicore/exp2syn_cpu.hpp" -#include "mechanisms/multicore/hh_cpu.hpp" -#include "mechanisms/multicore/pas_cpu.hpp" -#include "mechanisms/multicore/test_kin1_cpu.hpp" -#include "mechanisms/multicore/test_kinlva_cpu.hpp" -#include "mechanisms/multicore/test_ca_cpu.hpp" - -#include -#include -#include -#include -#include -#include -#include - -TEST(mechanisms, helpers) { - using namespace arb; - using size_type = multicore::backend::size_type; - using value_type = multicore::backend::value_type; - - // verify that the hh and pas channels are available - EXPECT_TRUE(multicore::backend::has_mechanism("hh")); - EXPECT_TRUE(multicore::backend::has_mechanism("pas")); - - std::vector parent_index = {0,0,1,2,3,4,0,6,7,8}; - auto node_index = std::vector{0,6,7,8,9}; - auto weights = std::vector(node_index.size(), 1.0); - auto n = node_index.size(); - - // one cell - size_type ncell = 1; - std::vector cell_index(n, 0u); - - multicore::backend::array vec_i(n, 0.); - multicore::backend::array vec_v(n, 0.); - multicore::backend::array vec_t(ncell, 0.); - multicore::backend::array vec_t_to(ncell, 0.); - multicore::backend::array vec_dt(n, 0.); - - auto mech = multicore::backend::make_mechanism("hh", 0, - memory::make_view(cell_index), vec_t, vec_t_to, vec_dt, - vec_v, vec_i, weights, node_index); - - EXPECT_EQ(mech->name(), "hh"); - EXPECT_EQ(mech->size(), 5u); - - // check that an out_of_range exception is thrown if an invalid mechanism is requested - ASSERT_THROW( - multicore::backend::make_mechanism("dachshund", 0, - memory::make_view(cell_index), vec_t, vec_t_to, vec_dt, - vec_v, vec_i, weights, node_index), - std::out_of_range - ); -} - -// Setup and update mechanism -template -void mech_update(T* mech, unsigned num_iters) { - - using namespace arb; - std::map> ions; - - mech->set_params(); - mech->init(); - for (auto ion_kind : ion_kinds()) { - auto ion_indexes = util::make_copy>( - mech->node_index_ - ); - - // Create and fill in the ion - ion ion = ion_indexes; - - memory::fill(ion.current(), 5.); - memory::fill(ion.reversal_potential(), 100.); - memory::fill(ion.internal_concentration(), 10.); - memory::fill(ion.external_concentration(), 140.); - ions[ion_kind] = ion; - - if (mech->uses_ion(ion_kind).uses) { - mech->set_ion(ion_kind, ions[ion_kind], ion_indexes); - } - } - - for (auto i=0u; inode_index_.size(); ++i) { - mech->net_receive(i, 1.); - } - - for (auto i=0u; iupdate_current(); - mech->update_state(); - } -} - -template -void array_init(T& array, const Seq& seq) { - auto seq_iter = seq.cbegin(); - for (auto& e : array) { - e = *seq_iter++; - } -} - -template -struct mechanism_info { - using mechanism_type = S; - using proto_mechanism_type = T; - static constexpr bool index_aliasing = alias; -}; - -template -class mechanisms : public ::testing::Test { }; - -TYPED_TEST_CASE_P(mechanisms); - -TYPED_TEST_P(mechanisms, update) { - using mechanism_type = typename TypeParam::mechanism_type; - using proto_mechanism_type = typename TypeParam::proto_mechanism_type; - - // Type checking - EXPECT_TRUE((std::is_same::value)); - EXPECT_TRUE((std::is_same::value)); - EXPECT_TRUE((std::is_same::value)); - - int num_cell = 1; - int num_syn = 32; - int num_comp = num_syn; - - typename mechanism_type::iarray node_index(num_syn); - typename mechanism_type::array voltage(num_comp, -65.0); - typename mechanism_type::array current(num_comp, 1.0); - - typename mechanism_type::array weights(num_syn, 1.0); - - typename mechanism_type::iarray cell_index(num_comp, 0); - typename mechanism_type::array time(num_cell, 2.); - typename mechanism_type::array time_to(num_cell, 2.1); - typename mechanism_type::array dt(num_comp, 2.1-2.); - - array_init(voltage, arb::util::cyclic_view({ -65.0, -61.0, -63.0 })); - array_init(current, arb::util::cyclic_view({ 1.0, 0.9, 1.1 })); - array_init(weights, arb::util::cyclic_view({ 1.0 })); - - // Initialise indexes - std::vector index_freq; - if (TypeParam::index_aliasing) { - index_freq.assign({ 4, 2, 3 }); - } - else { - index_freq.assign({ 1 }); - } - - auto freq_begin = arb::util::cyclic_view(index_freq).cbegin(); - auto freq = freq_begin; - auto index = node_index.begin(); - while (index != node_index.end()) { - for (auto i = 0; i < *freq && index != node_index.end(); ++i) { - *index++ = freq - freq_begin; - } - ++freq; - } - - // Copy indexes, voltage and current to use for the prototype mechanism - typename mechanism_type::iarray node_index_copy(node_index); - typename mechanism_type::array voltage_copy(voltage); - typename mechanism_type::array current_copy(current); - typename mechanism_type::array weights_copy(weights); - - // Create mechanisms - auto mech = arb::make_mechanism( - 0, cell_index, time, time_to, dt, - voltage, current, std::move(weights), std::move(node_index) - ); - - auto mech_proto = arb::make_mechanism( - 0, cell_index, time, time_to, dt, - voltage_copy, current_copy, - std::move(weights_copy), std::move(node_index_copy) - ); - - mech_update(dynamic_cast(mech.get()), 10); - mech_update(dynamic_cast(mech_proto.get()), 10); - - auto citer = current_copy.begin(); - for (auto const& c: current) { - EXPECT_NEAR(*citer++, c, 1e-6); - } -} - -REGISTER_TYPED_TEST_CASE_P(mechanisms, update); - -using mechanism_types = ::testing::Types< - mechanism_info< - arb::multicore::mechanism_hh, - arb::multicore::mechanism_hh_proto - >, - mechanism_info< - arb::multicore::mechanism_pas, - arb::multicore::mechanism_pas_proto - >, - mechanism_info< - arb::multicore::mechanism_expsyn, - arb::multicore::mechanism_expsyn_proto, - true - >, - mechanism_info< - arb::multicore::mechanism_exp2syn, - arb::multicore::mechanism_exp2syn_proto, - true - >, - mechanism_info< - arb::multicore::mechanism_test_kin1, - arb::multicore::mechanism_test_kin1_proto - >, - mechanism_info< - arb::multicore::mechanism_test_kinlva, - arb::multicore::mechanism_test_kinlva_proto - >, - mechanism_info< - arb::multicore::mechanism_test_ca, - arb::multicore::mechanism_test_ca_proto - > ->; - -INSTANTIATE_TYPED_TEST_CASE_P(mechanism_types, mechanisms, mechanism_types); - -#endif // 0