Expand reference on differences in zero-dimensional arrays
@@ -80,9 +80,12 @@ last element among elements referencing duplicate locations.
array([9998., 9999.])
-Reduction methods return zero-dimensional array
+Zero-dimensional array
-----------------------------------------------
+Reduction methods
+~~~~~~~~~~~~~~~~~
+
NumPy's reduction functions (e.g. :func:`numpy.sum`) return scalar values (e.g. :class:`numpy.float32`).
However CuPy counterparts return zero-dimensional :class:`cupy.ndarray` s.
That is because CuPy scalar values (e.g. :class:`cupy.float32`) are aliases of NumPy scalar values and are allocated in CPU memory.
@@ -95,6 +98,22 @@ If you want to use scalar values, cast the returned arrays explicitly.
True
+Type promotion
+~~~~~~~~~~~~~~
+
+CuPy automatically promotes dtypes of :class:`cupy.ndarray` s in a function with two or more operands, the result dtype is determined by the dtypes of the inputs.
+This is different from NumPy's rule on type promotion, when operands contain zero-dimensional arrays.
+Zero-dimensional :class:`numpy.ndarray` s are treated as if they were scalar values if they appear in operands of NumPy's function,
+This may affect the dtype of its output, depending on the values of the "scalar" inputs.
+
+ >>> (numpy.array(3, dtype=numpy.int32) * numpy.array([1., 2.], dtype=numpy.float32)).dtype
+ dtype('float32')
+ >>> (numpy.array(300000, dtype=numpy.int32) * numpy.array([1., 2.], dtype=numpy.float32)).dtype
+ dtype('float64')
+ >>> (cupy.array(3, dtype=numpy.int32) * cupy.array([1., 2.], dtype=numpy.float32)).dtype
+ dtype('float64')
+
+
Data types
----------
