Skip to content

Commit

Permalink
test_subscript_aggregation works!
Browse files Browse the repository at this point in the history
  • Loading branch information
julienmalard committed Sep 20, 2019
1 parent 35d9deb commit 591c7f2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
12 changes: 12 additions & 0 deletions pysd/py_backend/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ def initialize(self):
def ddt(self):
return 0 # todo: is this correct?

def update(self, state):
# this doesn't change once it's set up.
pass

def __call__(self):

time = self.time_func()
Expand Down Expand Up @@ -349,6 +353,10 @@ def initialize(self):
def ddt(self):
return 0

def update(self, state):
# this doesn't change once it's set up.
pass

def __call__(self, x):
if x > self.state['x'][-1]:
return self.state['x'][-1]
Expand Down Expand Up @@ -391,6 +399,10 @@ def initialize(self):
def ddt(self):
return 0

def update(self, state):
# this doesn't change once it's set up.
pass


class Macro(Stateful):
"""
Expand Down
8 changes: 5 additions & 3 deletions pysd/py_backend/vensim/vensim2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ def parse_units(units_str):
"game": "", # In the future, may have an actual `functions.game` pass through

# vector functions
"vmin": "functions.min",
"vmax": "functions.max",
"vmin": "functions.vmin",
"vmax": "functions.vmax",
"prod": "functions.prod",

}
Expand Down Expand Up @@ -804,6 +804,8 @@ def visit_expr(self, n, vc):
return s

def visit_in_oper_expr(self, n, vc):
# We have to pull out the internal operator because the Python "and" and "or" operator do not work with
# numpy arrays or xarray DataArrays. We will later replace it with the functions.and_ or functions.or_.
self.in_oper = vc[0]
return ''.join(filter(None, vc[1:])).strip()

Expand Down Expand Up @@ -873,7 +875,7 @@ def visit_subscript_list(self, n, vc):
else:
string = ' '
# Implements basic "!" subscript functionality in Vensim. Does NOT work for matrix diagonals in
# FUNC(variable[sub1!,sub1!]) functions, nor with
# FUNC(variable[sub1!,sub1!]) functions, nor with complex operations within the vector function
# But works quite well for simple axis specifications, such as "SUM(variable[axis1, axis2!])
axis = ['"%s"' % s.strip('!') for s in subs if s[-1] == '!']
if axis:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test_vensim_pathway.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def test_subscript_3d_arrays_widthwise(self):
output, canon = runner('test-models/tests/subscript_3d_arrays_widthwise/test_subscript_3d_arrays_widthwise.mdl')
assert_frames_close(output, canon, rtol=rtol)

@unittest.skip('in branch')
# @unittest.skip('in branch')
def test_subscript_aggregation(self):
from.test_utils import runner, assert_frames_close
output, canon = runner('test-models/tests/subscript_aggregation/test_subscript_aggregation.mdl')
Expand Down
2 changes: 1 addition & 1 deletion tests/test-models

0 comments on commit 591c7f2

Please sign in to comment.