There is no description of out keyword for accumulation functions and so the expected behavior might not be clear.
In Python array API spec there is no such keyword.
The code below shows different behavior between dpctl and numpy in case when dtype of out array mismatches type x array or default integer type (while numpy supports type casting for out array if necessary):
importnumpy, dpctl, dpctl.tensorasdpta=dpt.ones(10, dtype='i4')
out=dpt.ones_like(a, dtype='c8')
dpt.cumulative_sum(a, out=out) # expected default integer type != a.dtype---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
CellIn[7], line1---->1dpt.cumulative_sum(a, out=out).dtypeFile~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_accumulation.py:281, incumulative_sum(x, axis, dtype, include_initial, out)
220defcumulative_sum(
221x, /, *, axis=None, dtype=None, include_initial=False, out=None222 ):
223""" 224 cumulative_sum(x, /, *, axis=None, dtype=None, include_initial=False, 225 out=None) (...) 279 along. 280 """-->281return_accumulate_common(
282x,
283axis,
284dtype,
285include_initial,
286out,
287tai._cumsum_over_axis,
288tai._cumsum_final_axis_include_initial,
289tai._cumsum_dtype_supported,
290_default_accumulation_dtype,
291 )
File~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_accumulation.py:108, in_accumulate_common(x, axis, dtype, include_initial, out, _accumulate_fn, _accumulate_include_initial_fn, _dtype_supported, _default_accumulation_type_fn)
103raiseValueError(
104"The shape of input and output arrays are inconsistent. "105f"Expected output shape is {final_res_sh}, got {out_sh}"106 )
107ifres_dt!=out.dtype:
-->108raiseValueError(
109f"Output array of type {res_dt} is needed, "f"got {out.dtype}"110 )
111ifdpctl.utils.get_execution_queue((q, out.sycl_queue)) isNone:
112raiseExecutionPlacementError(
113"Input and output allocation queues are not compatible"114 )
ValueError: Outputarrayoftypeint64isneeded, gotcomplex64na=dpt.asnumpy(a)
nout=dpt.asnumpt(out)
numpy.cumsum(a, out=nout).dtype# Out: dtype('complex64')Thus the question arises whether dpctl (as opposed to numpy) was intended to have a strict requirement for data type of the out array.
There is no description of
outkeyword for accumulation functions and so the expected behavior might not be clear.In Python array API spec there is no such keyword.
The code below shows different behavior between
dpctland numpy in case when dtype ofoutarray mismatches typexarray or default integer type (while numpy supports type casting foroutarray if necessary):Thus the question arises whether
dpctl(as opposed to numpy) was intended to have a strict requirement for data type of theoutarray.