def test_python_func(self): def myFunction(variable, param1, param2): return sum(variable[0]) + 2 myMech = ProcessingMechanism(function=myFunction, size=4, name='myMech') # assert 'param1' in myMech.parameter_ports.names # <- FIX reinstate when problem with function params is fixed # assert 'param2' in myMech.parameter_ports.names # <- FIX reinstate when problem with function params is fixed val = myMech.execute(input=[-1, 2, 3, 4]) assert np.allclose(val, [[10]])
def test_user_def_func(self): def myFunction(variable, param1, param2): return variable * 2 + 3 U = UserDefinedFunction(custom_function=myFunction, default_variable=[[0, 0]], param2=0) myMech = ProcessingMechanism(function=U, size=2, name='myMech') # assert 'param1' in myMech.parameter_ports.names # <- FIX reinstate when problem with function params is fixed assert 'param2' in myMech.parameter_ports.names val = myMech.execute([1, 3]) assert np.allclose(val, [[5, 9]])
def test_udf_with_pnl_func(self): L = Logistic(gain=2) def myFunction(variable, params, context): return L(variable) + 2 U = UserDefinedFunction(custom_function=myFunction, default_variable=[[0, 0, 0]]) myMech = ProcessingMechanism(function=myFunction, size=3, name='myMech') val1 = myMech.execute(input=[1, 2, 3]) val2 = U.execute(variable=[[1, 2, 3]]) assert np.allclose(val1, val2) assert np.allclose(val1, L([1, 2, 3]) + 2)