Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu committed Dec 3, 2024
2 parents 7a55c37 + d24a901 commit 06f7a64
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 108 deletions.
14 changes: 8 additions & 6 deletions share/lib/python/neuron/rxd/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
_concentration_node = 0
_molecule_node = 1

_floor = numpy.floor


def _get_data():
return (_volumes, _surface_area, _diffs)
Expand Down Expand Up @@ -650,9 +652,9 @@ def satisfies(self, condition):
x, y, z = condition
mesh = self._r._mesh_grid
return (
int((x - mesh["xlo"]) / mesh["dx"]) == self._i
and int((y - mesh["ylo"]) / mesh["dy"]) == self._j
and int((z - mesh["zlo"]) / mesh["dz"]) == self._k
_floor((x - mesh["xlo"]) / mesh["dx"]) == self._i
and _floor((y - mesh["ylo"]) / mesh["dy"]) == self._j
and _floor((z - mesh["zlo"]) / mesh["dz"]) == self._k
)
# check for a position condition so as to provide a more useful error
checked_for_normalized_position = False
Expand Down Expand Up @@ -885,8 +887,8 @@ def satisfies(self, condition):
x, y, z = condition
r = self._regionref()
return (
int((x - r._xlo) / r._dx[0]) == self._i
and int((y - r._ylo) / r._dx[1]) == self._j
and int((z - r._zlo) / r._dx[2]) == self._k
_floor((x - r._xlo) / r._dx[0]) == self._i
and _floor((y - r._ylo) / r._dx[1]) == self._j
and _floor((z - r._zlo) / r._dx[2]) == self._k
)
raise RxDException(f"unrecognized node condition: {condition}")
201 changes: 102 additions & 99 deletions src/nrnoc/seclist.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <../../nrnconf.h>

#include <functional>

#define HOC_L_LIST 1
#include "section.h"
#include "neuron.h"
Expand All @@ -8,14 +11,35 @@
#include "code.h"
#include "classreg.h"

/* needs trailing '}' */
#define ITERATE_REMOVE(q1, q2, lst) \
for (q1 = (lst)->next; q1 != (lst); q1 = q2) { \
q2 = q1->next; \
if (q1->element.sec->prop == NULL) { \
hoc_l_delete(q1); \
continue; \
template <typename F>
bool seclist_iterate_remove_until(List* sl, F fun, const Section* sec) {
Item* q2 = nullptr;
for (Item* q1 = sl->next; q1 != sl; q1 = q2) {
q2 = q1->next;
if (q1->element.sec->prop == nullptr) {
hoc_l_delete(q1);
continue;
}
if (q1->element.sec == sec) {
fun(q1);
return true;
}
}
return false;
}

template <typename F>
void seclist_iterate_remove(List* sl, F fun) {
Item* q2 = nullptr;
for (Item* q1 = sl->next; q1 != sl; q1 = q2) {
q2 = q1->next;
if (q1->element.sec->prop == nullptr) {
hoc_l_delete(q1);
continue;
}
fun(q1->element.sec);
}
}

extern int hoc_return_type_code;
Section* (*nrnpy_o2sec_p_)(Object* o);
Expand Down Expand Up @@ -131,102 +155,83 @@ static double allroots(void* v) {
}

static double seclist_remove(void* v) {
Section *sec, *s;
Item *q, *q1;
List* sl;
int i;

sl = (List*) v;
i = 0;
List* sl = (List*) v;
int i = 0;
#if USE_PYTHON
if (!ifarg(1) || (*hoc_objgetarg(1))->ctemplate->sym == nrnpy_pyobj_sym_) {
#else
if (!ifarg(1)) {
#endif
sec = nrn_secarg(1);
ITERATE_REMOVE(q, q1, sl) /*{*/
if (sec == q->element.sec) {
hoc_l_delete(q);
section_unref(sec);
Section* sec = nrn_secarg(1);
if (seclist_iterate_remove_until(
sl,
[](Item* q) {
Section* s = q->element.sec;
hoc_l_delete(q);
section_unref(s);
},
sec)) {
return 1.;
}
hoc_warning(secname(sec), "not in this section list");
} else {
Object* o;
o = *hoc_objgetarg(1);
check_obj_type(o, "SectionList");
seclist_iterate_remove(sl, [](Section* s) { s->volatile_mark = 0; });
sl = (List*) o->u.this_pointer;
seclist_iterate_remove(sl, [](Section* s) { s->volatile_mark = 1; });
sl = (List*) v;
Item* q1;
for (Item* q = sl->next; q != sl; q = q1) {
q1 = q->next;
Section* s = hocSEC(q);
if (s->volatile_mark) {
hoc_l_delete(q);
section_unref(s);
++i;
}
}
}
hoc_warning(secname(sec), "not in this section list");
}
else {
Object* o;
o = *hoc_objgetarg(1);
check_obj_type(o, "SectionList");
ITERATE_REMOVE(q, q1, sl) /*{*/
s = hocSEC(q);
s->volatile_mark = 0;
}
sl = (List*) o->u.this_pointer;
ITERATE_REMOVE(q, q1, sl) /*{*/
s = hocSEC(q);
s->volatile_mark = 1;
}
sl = (List*) v;
i = 0;
for (q = sl->next; q != sl; q = q1) {
q1 = q->next;
s = hocSEC(q);
if (s->volatile_mark) {
hoc_l_delete(q);
section_unref(s);
++i;
}
}
}
return (double) i;
return (double) i;
}

static double unique(void* v) {
int i; /* number deleted */
Section* s;
Item *q, *q1;
Item* q1;
List* sl = (List*) v;
hoc_return_type_code = 1; /* integer */
ITERATE_REMOVE(q, q1, sl) /*{*/
s = hocSEC(q);
s->volatile_mark = 0;
}
i = 0;
for (q = sl->next; q != sl; q = q1) {
q1 = q->next;
s = hocSEC(q);
if (s->volatile_mark++) {
hoc_l_delete(q);
section_unref(s);
++i;
seclist_iterate_remove(sl, [](Section* s) { s->volatile_mark = 0; });
int i = 0; /* number deleted */
for (Item* q = sl->next; q != sl; q = q1) {
q1 = q->next;
Section* s = hocSEC(q);
if (s->volatile_mark++) {
hoc_l_delete(q);
section_unref(s);
++i;
}
}
}
return (double) i;
return (double) i;
}

static double contains(void* v) {
Section* s;
Item *q, *q1;
List* sl = (List*) v;
hoc_return_type_code = 2; /* boolean */
s = nrn_secarg(1);
ITERATE_REMOVE(q, q1, sl) /*{*/
if (hocSEC(q) == s) {
return 1.;
}
}
return (0.);
Section* s = nrn_secarg(1);
return seclist_iterate_remove_until(
sl, [](Item*) {}, s)
? 1.
: 0.;
}

static double printnames(void* v) {
Item *q, *q1;
List* sl = (List*) v;
ITERATE_REMOVE(q, q1, sl) /*{*/
if (q->element.sec->prop) {
Printf("%s\n", secname(q->element.sec));
}
}
return 1.;
seclist_iterate_remove(sl, [](Section* s) {
if (s->prop) {
Printf("%s\n", secname(s));
}
});
return 1.;
}

static Member_func members[] = {{"append", append},
Expand Down Expand Up @@ -307,33 +312,31 @@ void forall_sectionlist(void) {

void hoc_ifseclist(void) {
Inst* savepc = pc;
Item *q, *q1;
Section* sec = chk_access();
List* sl;
Object* ob;
Object** obp;

/* if arg is a string use forall_section */
if (hoc_stacktype() == STRING) {
hoc_ifsec();
return;
}
obp = hoc_objpop();
ob = *obp;
Object** obp = hoc_objpop();
Object* ob = *obp;
check(ob);
sl = (List*) (ob->u.this_pointer);
ITERATE_REMOVE(q, q1, sl) /*{*/
if (sec == q->element.sec) {
hoc_execute(relative(savepc));
if (!hoc_returning) {
pc = relative(savepc + 1);
}
hoc_tobj_unref(obp);
List* sl = (List*) (ob->u.this_pointer);
if (seclist_iterate_remove_until(
sl,
[&](Item*) {
hoc_execute(relative(savepc));
if (!hoc_returning) {
pc = relative(savepc + 1);
}
hoc_tobj_unref(obp);
},
sec)) {
return;
}
}
hoc_tobj_unref(obp);
if (!hoc_returning) {
pc = relative(savepc + 1);
}
hoc_tobj_unref(obp);
if (!hoc_returning) {
pc = relative(savepc + 1);
}
}
4 changes: 2 additions & 2 deletions src/nrnpython/inithoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ static int have_opt(const char* arg) {
static struct termios original_termios;

static void save_original_terminal_settings() {
if (tcgetattr(STDIN_FILENO, &original_termios) == -1) {
if (tcgetattr(STDIN_FILENO, &original_termios) == -1 && isatty(STDIN_FILENO)) {
std::cerr << "Error getting original terminal attributes\n";
}
}

static void restore_original_terminal_settings() {
if (tcsetattr(STDIN_FILENO, TCSANOW, &original_termios) == -1) {
if (tcsetattr(STDIN_FILENO, TCSANOW, &original_termios) == -1 && isatty(STDIN_FILENO)) {
std::cerr << "Error restoring terminal attributes\n";
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/api/hh_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int main(void) {
nrn_function_call(nrn_symbol("finitialize"), 1);
nrn_double_pop();

// continuerun(10)
// continuerun(10.5)
nrn_double_push(10.5);
nrn_function_call(nrn_symbol("continuerun"), 1);
nrn_double_pop();
Expand Down
7 changes: 7 additions & 0 deletions test/rxd/3d/test_node_selection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import weakref


def test_node_selection(neuron_instance):
"""Test selection of 3D nodes"""

Expand All @@ -16,4 +19,8 @@ def test_node_selection(neuron_instance):
assert nodes((5.2, 0.1, 0.3))[0].x3d == 5.125
assert nodes((5.2, 0.1, 0.3))[0].y3d == 0.125
assert nodes((5.2, 0.1, 0.3))[0].z3d == 0.375

nodes.append(rxd.node.Node3D(0, -1, 0, 0, cyt, 0, dend(0.5), weakref.ref(c)))

assert len(nodes((5, 0, 0))) == 1
assert nodes[-1] in nodes((nodes[-1].x3d, nodes[-1].y3d, nodes[-1].z3d))

0 comments on commit 06f7a64

Please sign in to comment.