Skip to content

Commit

Permalink
Test function calls for ARTIFICIAL_CELLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Sep 3, 2024
1 parent 176f2e5 commit 7de2957
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
34 changes: 34 additions & 0 deletions test/usecases/function/artificial_functions.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
NEURON {
ARTIFICIAL_CELL art_functions
RANGE x
GLOBAL gbl
}

ASSIGNED {
gbl
v
x
}

FUNCTION x_plus_a(a) {
x_plus_a = x + a
}

FUNCTION identity(v) {
identity = v
}

INITIAL {
x = 1.0
gbl = 42.0
}

: A LINEAR block makes a MOD file not VECTORIZED.
STATE {
z
}

LINEAR lin {
~ z = 2
}

14 changes: 9 additions & 5 deletions test/usecases/function/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from neuron import h


def check_callable(get_instance):
def check_callable(get_instance, has_voltage=True):
for x, value in zip(coords, values):
get_instance(x).x = value

Expand All @@ -19,10 +19,11 @@ def check_callable(get_instance):
actual = get_instance(x).identity(expected)
assert actual == expected, f"{actual} == {expected}"

# Check `f` using `v`.
expected = -2.0
actual = get_instance(x).v_plus_a(40.0)
assert actual == expected, f"{actual} == {expected}"
if has_voltage:
# Check `f` using `v`.
expected = -2.0
actual = get_instance(x).v_plus_a(40.0)
assert actual == expected, f"{actual} == {expected}"


nseg = 5
Expand All @@ -38,7 +39,10 @@ def check_callable(get_instance):
point_processes = {x: h.point_functions(s(x)) for x in coords}
point_non_threadsafe = {x: h.point_non_threadsafe(s(x)) for x in coords}

art_cells = {x: h.art_functions() for x in coords}

check_callable(lambda x: s(x).functions)
check_callable(lambda x: s(x).non_threadsafe)
check_callable(lambda x: point_processes[x])
check_callable(lambda x: point_non_threadsafe[x])
check_callable(lambda x: art_cells[x], has_voltage=False)

0 comments on commit 7de2957

Please sign in to comment.