Skip to content

Commit cd27217

Browse files
committed
To v0.3.1
1 parent 730bf2a commit cd27217

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/modelspec/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.3.0"
1+
__version__ = "0.3.1"
22

33
from .base_types import Base, define, has, field, fields, optional, instance_of, in_
44

src/modelspec/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from random import Random
1313
from typing import Union
1414

15-
verbose = False
15+
verbose = True
1616

1717

1818
def load_json(filename: str):
@@ -320,6 +320,10 @@ def evaluate(
320320
if rng:
321321
expr = expr.replace("random()", "rng.random()")
322322
parameters["rng"] = rng
323+
elif "random()" in expr:
324+
raise Exception(
325+
"The expression [%s] contains a random() call, but a random number generator (rng) must be supplied to the evaluate() call when this expression string is to be evaluated"
326+
)
323327

324328
if type(expr) == str and "math." in expr:
325329
parameters["math"] = math

tests/test_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ def test_evaluate(self):
6060
assert AtimesB[0, 0] == 1
6161
assert AtimesB.shape == (2, 2)
6262

63+
assert evaluate("math.sin(1)", verbose=True) == 0.8414709848078965
64+
assert evaluate("math.exp(1)+1", verbose=True) == 3.718281828459045
65+
66+
params = {"v": -0.070, "v_offset": -0.050, "MVOLT": 0.001}
67+
68+
assert (
69+
evaluate(
70+
"math.exp((13 - (v / MVOLT) + v_offset) / 4.0)", params, verbose=True
71+
)
72+
== 1014335951.1351416
73+
)
74+
75+
params = {"x": 1}
76+
params = {"x": np.array([1, 2])}
77+
ee = evaluate("numpy.exp(x)+x", params, verbose=True)
78+
assert ee[0] == 3.718281828459045
79+
6380
def test_val_info_tuple(self):
6481
print(_val_info((1, 2)))
6582
print(_val_info((("test", 1), 2)))

0 commit comments

Comments
 (0)