From dee59a7b0fd1bd9b08986614bc4de3b8000b626f Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Mon, 27 Sep 2021 18:48:17 -0500 Subject: [PATCH] Deprecate with_container_arithmetic's bcast_numpy_array arg Passing both 'bcast_numpy_array' and '_bcast_actx_array_types' was ill-defined. For example, in the case of an ArrayContext whose thawed array type is np.ndarray the specification would contradict between broadcasting the argument numpy_array to return an object array *OR* peforming the operation with every leaf array. Consider the example below, ( - 'Foo: ArrayContainer' whose arithmetic routines are generated by `with_container_arithmetic(bcast_numpy=True, _bcast_actx_array_types=True)` - 'actx: ArrayContextT' for whom `np.ndarray` is a valid thawed array type. ) Foo(DOFArray(actx, [38*actx.ones(3, np.float64)])) + np.array([3, 4, 5]) could be either of: - array([Foo(DOFArray([array([41, 41, 41])])), Foo(DOFArray([array([42, 42, 42])])), Foo(DOFArray([array([43, 43, 43])]))]), OR, - Foo(DOFArray(actx, array([41, 42, 43]))) --- arraycontext/container/arithmetic.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arraycontext/container/arithmetic.py b/arraycontext/container/arithmetic.py index df5b662a..c9975eb3 100644 --- a/arraycontext/container/arithmetic.py +++ b/arraycontext/container/arithmetic.py @@ -206,6 +206,15 @@ def _deserialize_init_arrays_code(cls, tmpl_instance_name, args): if rel_comparison is None: raise TypeError("rel_comparison must be specified") + if bcast_numpy_array: + from warnings import warn + warn("'bcast_numpy_array=True' is deprecated and will be unsupported" + " from December 2021", DeprecationWarning, stacklevel=2) + + if _bcast_actx_array_type: + raise ValueError("'bcast_numpy_array' and '_bcast_actx_array_type'" + " cannot be both set.") + if rel_comparison and eq_comparison is None: eq_comparison = True @@ -216,7 +225,7 @@ def _deserialize_init_arrays_code(cls, tmpl_instance_name, args): raise TypeError("bcast_obj_array must be set if bcast_numpy_array is") if _bcast_actx_array_type is None: - if _cls_has_array_context_attr: + if _cls_has_array_context_attr and (not bcast_numpy_array): _bcast_actx_array_type = bcast_number else: _bcast_actx_array_type = False