Skip to content

Commit cd81e92

Browse files
committed
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])))
1 parent 9314073 commit cd81e92

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

arraycontext/container/arithmetic.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ def _deserialize_init_arrays_code(cls, tmpl_instance_name, args):
206206
if rel_comparison is None:
207207
raise TypeError("rel_comparison must be specified")
208208

209+
if bcast_numpy_array:
210+
from warnings import warn
211+
warn("'bcast_numpy_array=True' is deprecated and will be unsupported"
212+
" from December, 2021", DeprecationWarning, stacklevel=2)
213+
214+
if _bcast_actx_array_type:
215+
raise ValueError("'bcast_numpy_array' and '_bcast_actx_array_type'"
216+
" cannot be both set.")
217+
209218
if rel_comparison and eq_comparison is None:
210219
eq_comparison = True
211220

@@ -216,7 +225,7 @@ def _deserialize_init_arrays_code(cls, tmpl_instance_name, args):
216225
raise TypeError("bcast_obj_array must be set if bcast_numpy_array is")
217226

218227
if _bcast_actx_array_type is None:
219-
if _cls_has_array_context_attr:
228+
if _cls_has_array_context_attr and (not bcast_numpy_array):
220229
_bcast_actx_array_type = bcast_number
221230
else:
222231
_bcast_actx_array_type = False

0 commit comments

Comments
 (0)