-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In NOCMODL functions that only use global data can be called without an instance.
- Loading branch information
Showing
5 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
NEURON { | ||
SUFFIX global | ||
GLOBAL gbl | ||
} | ||
|
||
ASSIGNED { | ||
gbl | ||
} | ||
|
||
FUNCTION get_gbl() { | ||
get_gbl = gbl | ||
} | ||
|
||
PROCEDURE set_gbl(value) { | ||
gbl = value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
NEURON { | ||
SUFFIX parameter | ||
} | ||
|
||
PARAMETER { | ||
gbl = 42.0 | ||
} | ||
|
||
FUNCTION get_gbl() { | ||
get_gbl = gbl | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from neuron import h, gui | ||
|
||
|
||
def make_accessors(mech_name, read_only): | ||
get = getattr(h, f"get_gbl_{mech_name}") | ||
|
||
if read_only: | ||
return get, None | ||
|
||
set = getattr(h, f"set_gbl_{mech_name}") | ||
return get, set | ||
|
||
|
||
def check_write_read_cycle(mech_name, read_only=False): | ||
get, set = make_accessors(mech_name, read_only) | ||
|
||
if read_only: | ||
expected = 42.0 | ||
else: | ||
expected = 278.045 | ||
set(expected) | ||
|
||
actual = get() | ||
assert ( | ||
actual == expected | ||
), f"{actual = }, {expected = }, delta = {actual - expected}" | ||
|
||
|
||
def test_top_local(): | ||
check_write_read_cycle("top_local") | ||
|
||
|
||
def test_global(): | ||
check_write_read_cycle("global") | ||
|
||
|
||
def test_parameter(): | ||
check_write_read_cycle("parameter", True) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_top_local() | ||
test_global() | ||
test_parameter() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters