From 7433f922a1efac46066a9c09e9c8242a9da9a5b5 Mon Sep 17 00:00:00 2001 From: "Samyak K. G" Date: Mon, 12 Oct 2020 22:12:16 -0400 Subject: [PATCH 1/2] composition: Use input port default variable as reference --- psyneulink/core/compositions/composition.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/psyneulink/core/compositions/composition.py b/psyneulink/core/compositions/composition.py index bbb2dee3d99..4cd73d7ded8 100644 --- a/psyneulink/core/compositions/composition.py +++ b/psyneulink/core/compositions/composition.py @@ -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) @@ -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 @@ -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 From 1f7faf95f434eb5072831183f9184a6f969295a7 Mon Sep 17 00:00:00 2001 From: "Samyak K. G" Date: Thu, 15 Oct 2020 15:37:37 -0400 Subject: [PATCH 2/2] tests/composition: Add multi dimensionality test --- tests/composition/test_composition.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/composition/test_composition.py b/tests/composition/test_composition.py index b67a65b42c3..bd7533cd73a 100644 --- a/tests/composition/test_composition.py +++ b/tests/composition/test_composition.py @@ -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)