diff --git a/psyneulink/core/components/functions/nonstateful/optimizationfunctions.py b/psyneulink/core/components/functions/nonstateful/optimizationfunctions.py index 649be335df..1a9d28cd9d 100644 --- a/psyneulink/core/components/functions/nonstateful/optimizationfunctions.py +++ b/psyneulink/core/components/functions/nonstateful/optimizationfunctions.py @@ -2132,8 +2132,7 @@ def _function(self, # Find the optimal value(s) optimal_value_count = 1 - value_sample_pairs = zip(all_values.flatten(), - [all_samples[:,i] for i in range(all_samples.shape[1])]) + value_sample_pairs = zip(all_values.ravel(), [all_samples[:,i] for i in range(all_samples.shape[1])]) optimal_value, optimal_sample = next(value_sample_pairs) # The algorithm below implements "Reservoir sampling"[0]. This diff --git a/psyneulink/core/components/functions/stateful/integratorfunctions.py b/psyneulink/core/components/functions/stateful/integratorfunctions.py index bcd614ef68..667d933151 100644 --- a/psyneulink/core/components/functions/stateful/integratorfunctions.py +++ b/psyneulink/core/components/functions/stateful/integratorfunctions.py @@ -3160,7 +3160,7 @@ def _function(self, previous_value = self.parameters.previous_value._get(context) try: - variable = variable.flatten() + variable = variable.ravel() drift = variable if len(variable) == dimension - 1 else np.full(dimension - 1, variable) except ValueError: diff --git a/psyneulink/core/compositions/parameterestimationcomposition.py b/psyneulink/core/compositions/parameterestimationcomposition.py index 6ed2dd2ad6..d255252510 100644 --- a/psyneulink/core/compositions/parameterestimationcomposition.py +++ b/psyneulink/core/compositions/parameterestimationcomposition.py @@ -609,7 +609,7 @@ def __init__( # If the include mask is 2D, make it 1D if likelihood_include_mask.ndim == 2: - likelihood_include_mask = likelihood_include_mask.flatten() + likelihood_include_mask = likelihood_include_mask.ravel() self.likelihood_include_mask = likelihood_include_mask diff --git a/psyneulink/core/globals/parameters.py b/psyneulink/core/globals/parameters.py index f79ce831aa..728ab63498 100644 --- a/psyneulink/core/globals/parameters.py +++ b/psyneulink/core/globals/parameters.py @@ -1744,7 +1744,7 @@ def _deliver_value(self, value, context=None): context=execution_id, value=ndArray( shape=list(value.shape), - data=list(value.flatten()) + data=list(value.ravel()) ) ) ) diff --git a/psyneulink/library/components/mechanisms/modulatory/learning/EMstoragemechanism.py b/psyneulink/library/components/mechanisms/modulatory/learning/EMstoragemechanism.py index f828ca9b68..c5de64554f 100644 --- a/psyneulink/library/components/mechanisms/modulatory/learning/EMstoragemechanism.py +++ b/psyneulink/library/components/mechanisms/modulatory/learning/EMstoragemechanism.py @@ -676,7 +676,7 @@ def _validate_params(self, request_set, target_set=None, context=None): for i, learning_signal in enumerate(learning_signals[:num_match_fields]): learning_signal_shape = learning_signal.parameters.matrix._get(context).shape if concatenate_queries: - memory_matrix_field_shape = np.array([np.concatenate(row, dtype=object).flatten() + memory_matrix_field_shape = np.array([np.concatenate(row, dtype=object).ravel() for row in memory_matrix[:,0:num_keys]]).T.shape else: memory_matrix_field_shape = np.array(memory_matrix[:,key_indices[i]].tolist()).T.shape diff --git a/tests/composition/test_autodiffcomposition.py b/tests/composition/test_autodiffcomposition.py index 4b8c5255d3..690f887cab 100644 --- a/tests/composition/test_autodiffcomposition.py +++ b/tests/composition/test_autodiffcomposition.py @@ -1300,9 +1300,7 @@ def test_xor_nested_train_then_no_train(self, num_epochs, learning_rate, # ----------------------------------------------------------------- - xor_autodiff = AutodiffComposition( - learning_rate=learning_rate, - ) + xor_autodiff = AutodiffComposition(learning_rate=learning_rate) xor_autodiff.add_node(xor_in) xor_autodiff.add_node(xor_hid) @@ -1319,15 +1317,20 @@ def test_xor_nested_train_then_no_train(self, num_epochs, learning_rate, parentComposition = pnl.Composition() parentComposition.add_node(xor_autodiff) - input = {xor_autodiff: input_dict} no_training_input = {xor_autodiff: no_training_input_dict} learning_context = Context() - xor_autodiff.learn(inputs=input_dict, execution_mode=autodiff_mode, epochs=num_epochs, context=learning_context, patience=patience, min_delta=min_delta) - result1 = np.array(xor_autodiff.learning_results).flatten() - np.testing.assert_allclose(result1, np.array(xor_targets).flatten(), atol=0.1) - result2 = parentComposition.run(inputs=no_training_input, execution_mode=autodiff_mode, context=learning_context) + xor_autodiff.learn(inputs=input_dict, + execution_mode=autodiff_mode, + epochs=num_epochs, + context=learning_context, + patience=patience, + min_delta=min_delta) + + result1 = np.array(xor_autodiff.learning_results).ravel() + np.testing.assert_allclose(result1, np.array(xor_targets).ravel(), atol=0.1) + result2 = parentComposition.run(inputs=no_training_input, execution_mode=autodiff_mode, context=learning_context) np.testing.assert_allclose(result2, [[0]], atol=0.1) @pytest.mark.parametrize( diff --git a/tests/composition/test_control.py b/tests/composition/test_control.py index b473953d9f..0395463758 100644 --- a/tests/composition/test_control.py +++ b/tests/composition/test_control.py @@ -2470,7 +2470,7 @@ def test_modulation_simple(self, cost, expected, exp_values, comp_mode): ret = comp.run(inputs={mech: [2]}, num_trials=1, execution_mode=comp_mode) np.testing.assert_allclose(ret, expected) if comp_mode == pnl.ExecutionMode.Python: - np.testing.assert_allclose(comp.controller.function.saved_values.flatten(), exp_values) + np.testing.assert_allclose(comp.controller.function.saved_values.ravel(), exp_values) @pytest.mark.benchmark @pytest.mark.control @@ -3360,7 +3360,7 @@ def comp_run(inputs, execution_mode): np.testing.assert_array_equal(results, result) if mode == pnl.ExecutionMode.Python: - np.testing.assert_array_equal(saved_values.flatten(), [0.75, 1.5, 2.25]) + np.testing.assert_array_equal(saved_values.ravel(), [0.75, 1.5, 2.25]) def test_model_based_ocm_with_buffer(self): diff --git a/tests/composition/test_emcomposition.py b/tests/composition/test_emcomposition.py index 9a6a2d7a74..8a8b8cd7c0 100644 --- a/tests/composition/test_emcomposition.py +++ b/tests/composition/test_emcomposition.py @@ -146,7 +146,7 @@ def test_structure(self, params.update({'softmax_gain': softmax_gain}) em = EMComposition(**params) - assert np.hstack(np.array(em.memory, dtype=object).flatten()).size < 30 + assert np.hstack(np.array(em.memory, dtype=object).ravel()).size < 30 # Validate basic structure assert len(em.memory) == memory_capacity diff --git a/tests/models/test_greedy_agent.py b/tests/models/test_greedy_agent.py index 5a94786a41..ccd873e0f7 100644 --- a/tests/models/test_greedy_agent.py +++ b/tests/models/test_greedy_agent.py @@ -230,7 +230,7 @@ def action_fn(variable): # FIXME: The results are 'close' for both Philox and MT, # because they're dominated by costs # FIX: Requires 1e-5 tolerance - np.testing.assert_allclose(np.asarray(ocm.function.saved_values).flatten(), + np.testing.assert_allclose(np.asarray(ocm.function.saved_values).ravel(), [-2.66258741, -22027.9970321, -22028.17515945, -44053.59867802, -22028.06045185, -44053.4048842, -44053.40736234, -66078.90687915], rtol=1e-5, atol=1e-5)