-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement CONSTRUCTOR/DESTRUCTOR. (#1424)
- Loading branch information
Showing
6 changed files
with
129 additions
and
4 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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ set(NMODL_USECASE_DIRS | |
solve | ||
constant | ||
electrode_current | ||
constructor | ||
function | ||
procedure | ||
global | ||
|
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,17 @@ | ||
NEURON { | ||
ARTIFICIAL_CELL art_ctor | ||
GLOBAL ctor_calls, dtor_calls | ||
} | ||
|
||
ASSIGNED { | ||
ctor_calls | ||
dtor_calls | ||
} | ||
|
||
CONSTRUCTOR { | ||
ctor_calls = ctor_calls + 1 | ||
} | ||
|
||
DESTRUCTOR { | ||
dtor_calls = dtor_calls + 1 | ||
} |
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,17 @@ | ||
NEURON { | ||
POINT_PROCESS ctor | ||
GLOBAL ctor_calls, dtor_calls | ||
} | ||
|
||
ASSIGNED { | ||
ctor_calls | ||
dtor_calls | ||
} | ||
|
||
CONSTRUCTOR { | ||
ctor_calls = ctor_calls + 1 | ||
} | ||
|
||
DESTRUCTOR { | ||
dtor_calls = dtor_calls + 1 | ||
} |
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,36 @@ | ||
import gc | ||
|
||
from neuron import h, gui | ||
|
||
|
||
def allocate_props(n_instances, mech_name): | ||
s = h.Section() | ||
s.nseg = 1 | ||
|
||
for _ in range(n_instances): | ||
getattr(h, mech_name)(s(0.5)) | ||
|
||
|
||
def assert_equal(actual, expected): | ||
assert actual == expected, f"{actual} != {expected}" | ||
|
||
|
||
def check_ctor(n_instances, mech_name): | ||
allocate_props(n_instances, mech_name) | ||
gc.collect() | ||
|
||
assert_equal(getattr(h, f"ctor_calls_{mech_name}"), n_instances) | ||
assert_equal(getattr(h, f"dtor_calls_{mech_name}"), n_instances) | ||
|
||
|
||
def test_ctor(): | ||
check_ctor(12, "ctor") | ||
|
||
|
||
def test_art_ctor(): | ||
check_ctor(32, "art_ctor") | ||
|
||
|
||
if __name__ == "__main__": | ||
test_ctor() | ||
test_art_ctor() |