@@ -145,27 +145,31 @@ def check_binary(self, xp):
145145 y = y .astype (numpy .complex64 )
146146
147147 # NumPy returns an output array of another type than DPNP when input ones have diffrent types.
148- if self .name == 'multiply' and xp is cupy and dtype1 != dtype2 :
149- is_array_arg1 = not xp .isscalar (arg1 )
150- is_array_arg2 = not xp .isscalar (arg2 )
151-
152- is_int_float = lambda _x , _y : numpy .issubdtype (_x , numpy .integer ) and numpy .issubdtype (_y , numpy .floating )
153- is_same_type = lambda _x , _y , _type : numpy .issubdtype (_x , _type ) and numpy .issubdtype (_y , _type )
154-
155- if is_array_arg1 and is_array_arg2 :
156- # If both inputs are arrays where one is of floating type and another - integer,
157- # NumPy will return an output array of always "float64" type,
158- # while DPNP will return the array of a wider type from the input arrays.
159- if is_int_float (dtype1 , dtype2 ) or is_int_float (dtype2 , dtype1 ):
160- y = y .astype (numpy .float64 )
161- elif is_same_type (dtype1 , dtype2 , numpy .floating ) or is_same_type (dtype1 , dtype2 , numpy .integer ):
162- # If one input is an array and another - scalar,
163- # NumPy will return an output array of the same type as the inpupt array has,
164- # while DPNP will return the array of a wider type from the inputs (considering both array and scalar).
165- if is_array_arg1 and not is_array_arg2 :
166- y = y .astype (dtype1 )
167- elif is_array_arg2 and not is_array_arg1 :
168- y = y .astype (dtype2 )
148+ if self .name == 'multiply' and xp is cupy :
149+ if xp .isscalar (arg1 ) and xp .isscalar (arg2 ):
150+ # If both are scalars, the result will be a scalar, so needs to convert into numpy-scalar.
151+ y = numpy .asarray (y )
152+ elif dtype1 != dtype2 :
153+ is_array_arg1 = not xp .isscalar (arg1 )
154+ is_array_arg2 = not xp .isscalar (arg2 )
155+
156+ is_int_float = lambda _x , _y : numpy .issubdtype (_x , numpy .integer ) and numpy .issubdtype (_y , numpy .floating )
157+ is_same_type = lambda _x , _y , _type : numpy .issubdtype (_x , _type ) and numpy .issubdtype (_y , _type )
158+
159+ if is_array_arg1 and is_array_arg2 :
160+ # If both inputs are arrays where one is of floating type and another - integer,
161+ # NumPy will return an output array of always "float64" type,
162+ # while DPNP will return the array of a wider type from the input arrays.
163+ if is_int_float (dtype1 , dtype2 ) or is_int_float (dtype2 , dtype1 ):
164+ y = y .astype (numpy .float64 )
165+ elif is_same_type (dtype1 , dtype2 , numpy .floating ) or is_same_type (dtype1 , dtype2 , numpy .integer ):
166+ # If one input is an array and another - scalar,
167+ # NumPy will return an output array of the same type as the inpupt array has,
168+ # while DPNP will return the array of a wider type from the inputs (considering both array and scalar).
169+ if is_array_arg1 and not is_array_arg2 :
170+ y = y .astype (dtype1 )
171+ elif is_array_arg2 and not is_array_arg1 :
172+ y = y .astype (dtype2 )
169173
170174 # NumPy returns different values (nan/inf) on division by zero
171175 # depending on the architecture.
0 commit comments