From fc77f48186afc134a4d493cda89698db2af26388 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Thu, 23 May 2024 20:48:27 -0400 Subject: [PATCH] llvm/execution: Do stricter checks when reshaping synced parameters Signed-off-by: Jan Vesely --- psyneulink/core/llvm/execution.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/psyneulink/core/llvm/execution.py b/psyneulink/core/llvm/execution.py index f3c6694ccf6..40889b48808 100644 --- a/psyneulink/core/llvm/execution.py +++ b/psyneulink/core/llvm/execution.py @@ -206,12 +206,16 @@ def _enumerate_recurse(elements): if "state" in ids: value = value[-1] - # Try to match the shape of the old value - if hasattr(pnl_value, 'shape'): - try: - value = value.reshape(pnl_value.shape) - except ValueError: - pass + # Reshape to match the shape of the old value. + # Do not try to reshape ragged arrays. + if getattr(pnl_value, 'dtype', object) != object and pnl_value.shape != value.shape: + + # Reshape to match numpy 0d arrays and "matrix" + # parameters that are flattened in compiled form + assert pnl_value.shape == () or pnl_param.name == "matrix", \ + "{}: {} vs. {}".format(pnl_param.name, pnl_value.shape, value.shape) + + value = value.reshape(pnl_value.shape) pnl_param.set(value, context=context, override=True, compilation_sync=True)