Skip to content

Commit aed209b

Browse files
authored
rxd handles np.float64 and other numpy.generic types (#3808)
* unwrap numpy objects (preserves floats and ints) * added a test
1 parent d42eb9c commit aed209b

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

share/lib/python/neuron/rxd/rxdmath.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ def _semi_compile(self, region, instruction):
750750
try:
751751
items_append(item._semi_compile(region, instruction))
752752
except AttributeError:
753+
if isinstance(item, numpy.generic):
754+
item = item.item()
753755
items_append(f"{item!r}")
754756
counts_append(count)
755757
result = ""

test/rxd/test_state_reaction.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import numpy as np
23
from .testutils import compare_data, tol
34

45

@@ -37,3 +38,17 @@ def test_state_reaction2(neuron_instance):
3738
h.finitialize(-65)
3839
h.continuerun(1)
3940
assert sec(0.5).ca2i == sec(0.5).cai
41+
42+
43+
def test_numpy_rate(neuron_instance):
44+
"""Test a simple rxd.Rate involving a numpy value"""
45+
n, rxd, data, save_path = neuron_instance
46+
soma = n.Section("soma")
47+
soma.L = soma.diam = 10
48+
cyt = rxd.Region([soma], name="cyt", nrn_region="i")
49+
c = rxd.Species(cyt, name="c", charge=1, initial=0)
50+
r = rxd.Rate(c, np.float64(1))
51+
n.dt = 0.025
52+
n.finitialize(-65)
53+
n.fadvance()
54+
assert c.nodes[0].concentration == 0.025

0 commit comments

Comments
 (0)