Skip to content

Commit

Permalink
Merge branch 'master' into cornu/add_eigen
Browse files Browse the repository at this point in the history
  • Loading branch information
alkino authored Sep 18, 2023
2 parents 9c1d070 + adec045 commit 88bc143
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/neuron-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

name: ${{ matrix.os }} - ${{ matrix.config.build_mode }} (${{ matrix.config.cmake_option }}${{ matrix.config.config_options }}${{ matrix.config.matrix_eval }}${{ matrix.config.sanitizer }})

timeout-minutes: 45
timeout-minutes: 75

env:
INSTALL_DIR: install
Expand Down
2 changes: 1 addition & 1 deletion external/coding-conventions
10 changes: 7 additions & 3 deletions src/neuron/container/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,13 @@ struct handle_interface: handle_base<Identifier> {
}

friend std::ostream& operator<<(std::ostream& os, handle_interface const& handle) {
return os << "Node{" << handle.id() << '/' << handle.underlying_storage().size()
<< " v=" << handle.v() << " area=" << handle.area() << " a=" << handle.a()
<< " b=" << handle.b() << " d=" << handle.d() << '}';
if (handle.id()) {
return os << "Node{" << handle.id() << '/' << handle.underlying_storage().size()
<< " v=" << handle.v() << " area=" << handle.area() << " a=" << handle.a()
<< " b=" << handle.b() << " d=" << handle.d() << '}';
} else {
os << "Node{null}";
}
}

Check warning on line 254 in src/neuron/container/node.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04 - cmake (-DNRN_ENABLE_CORENEURON=ON -DNRN_ENABLE_INTERVIEWS=OFF -DNMODL_SANITIZERS=undefinedundefined)

non-void function does not return a value in all control paths [-Wreturn-type]

Check warning on line 254 in src/neuron/container/node.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04 - cmake (-DNRN_ENABLE_CORENEURON=ON -DNRN_ENABLE_INTERVIEWS=OFF -DNMODL_SANITIZERS=undefinedundefined)

non-void function does not return a value in all control paths [-Wreturn-type]

Check warning on line 254 in src/neuron/container/node.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04 - cmake (-DNRN_ENABLE_CORENEURON=ON -DNRN_ENABLE_INTERVIEWS=OFF -DNMODL_SANITIZERS=undefinedundefined)

non-void function does not return a value in all control paths [-Wreturn-type]

Check warning on line 254 in src/neuron/container/node.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04 - cmake (-DNRN_ENABLE_CORENEURON=ON -DNRN_ENABLE_INTERVIEWS=OFF -DNMODL_SANITIZERS=undefinedundefined)

non-void function does not return a value in all control paths [-Wreturn-type]

Check warning on line 254 in src/neuron/container/node.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04 - cmake (-DNRN_ENABLE_CORENEURON=ON -DNRN_ENABLE_INTERVIEWS=OFF -DNMODL_SANITIZERS=undefinedundefined)

non-void function does not return a value in all control paths [-Wreturn-type]

Check warning on line 254 in src/neuron/container/node.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04 - cmake (-DNRN_ENABLE_CORENEURON=ON -DNRN_ENABLE_INTERVIEWS=OFF -DNMODL_SANITIZERS=undefinedundefined)

non-void function does not return a value in all control paths [-Wreturn-type]

Check warning on line 254 in src/neuron/container/node.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04 - cmake (-DNRN_ENABLE_CORENEURON=ON -DNRN_ENABLE_INTERVIEWS=OFF -DNMODL_SANITIZERS=undefinedundefined)

non-void function does not return a value in all control paths [-Wreturn-type]

Check warning on line 254 in src/neuron/container/node.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04 - cmake (-DNRN_ENABLE_CORENEURON=ON -DNRN_ENABLE_INTERVIEWS=OFF -DNMODL_SANITIZERS=undefinedundefined)

non-void function does not return a value in all control paths [-Wreturn-type]
};
} // namespace neuron::container::Node
7 changes: 0 additions & 7 deletions src/neuron/container/non_owning_soa_identifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ struct non_owning_identifier_without_container {
return !m_ptr;
}

/**
* @brief Get the underlying pointer value.
*/
[[nodiscard]] std::size_t* get_raw_pointer() const {
return m_ptr;
}

friend std::ostream& operator<<(std::ostream& os,
non_owning_identifier_without_container const& id) {
if (!id.m_ptr) {
Expand Down
10 changes: 10 additions & 0 deletions src/neuron/container/soa_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,16 @@ struct soa {
return result;
}

void shrink_to_fit() {
if (m_frozen_count) {
throw_error("shrink() called on a frozen structure");
}
for_each_vector<detail::may_cause_reallocation::Yes>(
[](auto const& tag, auto& vec, int field_index, int array_dim) {
vec.shrink_to_fit();
});
}

private:
/**
* @brief Remove the @f$i^{\text{th}}@f$ row from the container.
Expand Down
7 changes: 7 additions & 0 deletions src/neuron/model_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ struct Model {
[[nodiscard]] std::unique_ptr<container::utils::storage_info> find_container_info(
void const* cont) const;

void shrink_to_fit() {
m_node_data.shrink_to_fit();
apply_to_mechanisms([](auto& mech_data) { mech_data.shrink_to_fit(); });

m_identifier_ptrs_for_deferred_deletion.shrink_to_fit();
}

private:
container::Mechanism::storage& mechanism_data_impl(int type) const {
if (0 <= type && type >= m_mech_data.size()) {
Expand Down
2 changes: 2 additions & 0 deletions src/nrniv/cxprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "hocdec.h" // Datum
#include "section.h" // Section
#include "structpool.h" // Pool
#include "../neuron/model_data.hpp"

#include <memory>
#include <vector>
Expand Down Expand Up @@ -111,6 +112,7 @@ void nrn_poolshrink(int shrink) {
pdatum.reset();
}
}
neuron::model().shrink_to_fit();
} else {
Printf("poolshrink --- type name (dbluse, size) (datumuse, size)\n");
for (auto i = 0; i < datumpools().size(); ++i) {
Expand Down
4 changes: 1 addition & 3 deletions src/nrnpython/nrnpy_nrn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2223,8 +2223,7 @@ static int rv_setitem(PyObject* self, Py_ssize_t ix, PyObject* value) {
return -1;
}
int err;
// Bug that ix is not passed as the last argument?
auto const d = nrnpy_rangepointer(sec, r->sym_, r->pymech_->pyseg_->x_, &err, 0 /* idx */);
auto const d = nrnpy_rangepointer(sec, r->sym_, r->pymech_->pyseg_->x_, &err, ix);
if (!d) {
rv_noexist(sec, r->sym_->name, r->pymech_->pyseg_->x_, err);
return -1;
Expand All @@ -2244,7 +2243,6 @@ static int rv_setitem(PyObject* self, Py_ssize_t ix, PyObject* value) {
neuron::container::data_handle<double>{neuron::container::do_not_search, &x},
0);
} else {
assert(ix == 0); // d += ix;
if (!PyArg_Parse(value, "d", static_cast<double const*>(d))) {
PyErr_SetString(PyExc_ValueError, "bad value");
return -1;
Expand Down
27 changes: 27 additions & 0 deletions test/hoctests/vardimtests/test2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,30 @@
h("""objref oarray[4][4]""")
# cannot reach line we want because of earlier array check
expect_err("h.oarray[2] = []")


# test assignment/evaluation of mod file array variable from python
s = h.Section()
s.nseg = 3
s.insert("atst")
for seg in s:
ar = seg.atst.arrayrng
assert len(ar) == 4
for i in range(len(ar)):
ar[i] = i + seg.x
seg.arrayrng_atst[i] = ar[i]
for seg in s:
ar = seg.atst.arrayrng
for i in range(len(ar)):
assert ar[i] == i + seg.x
assert seg.arrayrng_atst[i] == i + seg.x

ar = s.arrayrng_atst
assert len(ar) == 4
for i in range(len(ar)):
ar[i] = i
for i in range(len(ar)):
assert ar[i] == float(i)

expect_err("print(ar[10])")
expect_err("ar[10] = 1")
5 changes: 5 additions & 0 deletions test/unit_tests/container/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ std::tuple<std::vector<::Node>, std::vector<double>> get_nodes_and_reference_vol
} // namespace neuron::test

TEST_CASE("SOA-backed Node structure", "[Neuron][data_structures][node]") {
REQUIRE(neuron::model().node_data().size() == 0);
GIVEN("A default-constructed node") {
::Node node{};
THEN("Check its SOA-backed members have their default values") {
Expand Down Expand Up @@ -443,9 +444,12 @@ TEST_CASE("SOA-backed Node structure", "[Neuron][data_structures][node]") {
}
}
}
REQUIRE(neuron::model().node_data().size() == 0);
}

TEST_CASE("Fast membrane current storage", "[Neuron][data_structures][node][fast_imem]") {
REQUIRE(neuron::model().node_data().size() == 0);

auto const set_fast_imem = [](bool new_value) {
nrn_use_fast_imem = new_value;
nrn_fast_imem_alloc();
Expand All @@ -467,6 +471,7 @@ TEST_CASE("Fast membrane current storage", "[Neuron][data_structures][node][fast
GIVEN("fast_imem calculation is disabled") {
set_fast_imem(false);
WHEN("A node is default-constructed") {
REQUIRE(neuron::model().node_data().size() == 0);
::Node node{};
check_throws(node);
auto handle = node.sav_rhs_handle();
Expand Down

0 comments on commit 88bc143

Please sign in to comment.