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

Feat/multidim inputs #1784

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions psyneulink/core/compositions/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4419,8 +4419,8 @@ def _create_CIM_ports(self, context=None):
if input_port not in set(self.input_CIM_ports.keys()):
# instantiate the input port on the input CIM to correspond to the node's input port
interface_input_port = InputPort(owner=self.input_CIM,
variable=input_port.defaults.value,
reference_value=input_port.defaults.value,
variable=input_port.defaults.variable,
reference_value=input_port.defaults.variable,
name= INPUT_CIM_NAME + "_" + node.name + "_" + input_port.name,
context=context)

Expand Down Expand Up @@ -7661,7 +7661,7 @@ def _validate_single_input(self, node, input):
"""
# Validate that a single input is properly formatted for a node.
_input = []
node_variable = [input_port.defaults.value for input_port in node.input_ports if not input_port.internal_only]
node_variable = [self.input_CIM_ports[input_port][0].defaults.variable for input_port in node.input_ports if not input_port.internal_only]
match_type = self._input_matches_variable(input, node_variable)
if match_type == 'homogeneous':
# np.atleast_2d will catch any single-input ports specified without an outer list
Expand Down Expand Up @@ -7708,8 +7708,7 @@ def _validate_input_shapes(self, inputs):
if True in [i is None for i in node_input]:
incompatible_stimulus = stimulus[node_input.index(None)]
node_name = node.name
node_variable = [input_port.defaults.value for input_port in node.input_ports
if not input_port.internal_only]
node_variable = [self.input_CIM_ports[input_port][0].defaults.variable for input_port in node.input_ports if not input_port.internal_only]
err_msg = f"Input stimulus ({incompatible_stimulus}) for {node_name} is incompatible with " \
f"its external_input_values ({node_variable})."
# 8/3/17 CW: I admit the error message implementation here is very hacky; but it's at least not a hack
Expand Down
23 changes: 23 additions & 0 deletions tests/composition/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7306,3 +7306,26 @@ def store_inputs():
)

assert np.allclose(check_inputs, [[[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]]])

@pytest.mark.parametrize("shape",[
(2, 2),
(2, 2, 2),
(3, 3, 3, 3),
(3, 3, 3, 3, 3),
])
def test_multidim(self, shape):
a = pnl.ProcessingMechanism(name='a', function=pnl.Linear(slope=4), default_variable=np.ones(shape=shape))
b = pnl.ProcessingMechanism(name='b', function=pnl.Linear(slope=4), default_variable=np.ones(shape=shape))
proj = pnl.MappingProjection(sender=a, receiver=b)
comp = pnl.Composition()
comp.add_node(a)
comp.add_node(b)
comp.add_projection(proj)
input_list = {a: [np.ones(shape=shape)]}

res = comp.run(
inputs=input_list,
)
res = np.array(res)
assert res.shape == shape
assert np.allclose(res, np.ones(shape=shape) * 4)