Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntegratorMechanism: correct broken size argument #3046

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ def _handle_default_variable(self, default_variable=None, size=None, input_ports
variable_shape[-1] = function_variable.shape[-1]
# self.parameters.variable.default_value = np.zeros(tuple(variable_shape))
variable = np.zeros(tuple(variable_shape))
else:
variable = default_variable
else:
variable = default_variable

# IMPLEMENTATON NOTE:
# Don't worry about case in which length of function's variable is 1 and Mechanism's is > 1
Expand Down
22 changes: 13 additions & 9 deletions tests/components/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,23 @@ def __init__(self, default_variable=None, **kwargs):
super().__init__(default_variable=default_variable, **kwargs)

@pytest.mark.parametrize(
'cls_',
'cls_', [pnl.ProcessingMechanism, pnl.TransferMechanism, pnl.IntegratorMechanism]
)
@pytest.mark.parametrize(
'size, expected_variable',
[
pnl.ProcessingMechanism,
pytest.param(
pnl.IntegratorMechanism,
marks=pytest.mark.xfail(reason='size currently unsupported at all on IntegratorMechanism')
)
(1, [[0]]),
(2, [[0, 0]]),
(3, [[0, 0, 0]]),
((1, 1), [[0], [0]]),
((2, 2), [[0, 0], [0, 0]]),
((3, 3), [[0, 0, 0], [0, 0, 0]]),
]
)
@pytest.mark.parametrize('params_dict_entry', [NotImplemented, 'params'])
def test_size(self, cls_, params_dict_entry):
c = cls_(**nest_dictionary({'size': 5}, params_dict_entry))
assert len(c.defaults.variable[-1]) == 5
def test_size(self, cls_, params_dict_entry, size, expected_variable):
c = cls_(**nest_dictionary({'size': size}, params_dict_entry))
np.testing.assert_array_equal(c.defaults.variable, expected_variable)

@pytest.mark.parametrize(
'cls_, function_params, expected_values',
Expand Down
Loading