Skip to content

Commit 4b9a5cd

Browse files
authored
dpnp.power() doesn't work properly with a scalar (#1323)
* dpnp.power() doesn't work properly with a scalar * skip tests with 0 value of complex128 on CPU * State support of :class: in descriptions
1 parent 1897cf4 commit 4b9a5cd

12 files changed

+247
-134
lines changed

dpnp/backend/include/dpnp_gen_2arg_3type_tbl.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ MACRO_2ARG_3TYPES_OP(dpnp_multiply_c,
176176
MACRO_UNPACK_TYPES(float, double, std::complex<float>, std::complex<double>))
177177

178178
MACRO_2ARG_3TYPES_OP(dpnp_power_c,
179-
sycl::pow((double)input1_elem, (double)input2_elem),
180-
nullptr,
181-
std::false_type,
179+
static_cast<_DataType_output>(std::pow(input1_elem, input2_elem)),
180+
sycl::pow(x1, x2),
181+
MACRO_UNPACK_TYPES(float, double),
182182
oneapi::mkl::vm::pow,
183-
MACRO_UNPACK_TYPES(float, double))
183+
MACRO_UNPACK_TYPES(float, double, std::complex<float>, std::complex<double>))
184184

185185
MACRO_2ARG_3TYPES_OP(dpnp_subtract_c,
186186
input1_elem - input2_elem,

dpnp/backend/kernels/dpnp_krnl_elemwise.cpp

+16-43
Original file line numberDiff line numberDiff line change
@@ -1247,28 +1247,34 @@ static void func_map_elemwise_2arg_3type_core(func_map_t& fmap)
12471247
func_type_map_t::find_type<FT1>,
12481248
func_type_map_t::find_type<FTs>>}),
12491249
...);
1250+
((fmap[DPNPFuncName::DPNP_FN_DIVIDE_EXT][FT1][FTs] =
1251+
{get_divide_res_type<FT1, FTs>(),
1252+
(void*)dpnp_divide_c_ext<func_type_map_t::find_type<get_divide_res_type<FT1, FTs>()>,
1253+
func_type_map_t::find_type<FT1>,
1254+
func_type_map_t::find_type<FTs>>,
1255+
get_divide_res_type<FT1, FTs, std::false_type>(),
1256+
(void*)dpnp_divide_c_ext<func_type_map_t::find_type<get_divide_res_type<FT1, FTs, std::false_type>()>,
1257+
func_type_map_t::find_type<FT1>,
1258+
func_type_map_t::find_type<FTs>>}),
1259+
...);
12501260
((fmap[DPNPFuncName::DPNP_FN_MULTIPLY_EXT][FT1][FTs] =
12511261
{populate_func_types<FT1, FTs>(),
12521262
(void*)dpnp_multiply_c_ext<func_type_map_t::find_type<populate_func_types<FT1, FTs>()>,
12531263
func_type_map_t::find_type<FT1>,
12541264
func_type_map_t::find_type<FTs>>}),
12551265
...);
1266+
((fmap[DPNPFuncName::DPNP_FN_POWER_EXT][FT1][FTs] =
1267+
{populate_func_types<FT1, FTs>(),
1268+
(void*)dpnp_power_c_ext<func_type_map_t::find_type<populate_func_types<FT1, FTs>()>,
1269+
func_type_map_t::find_type<FT1>,
1270+
func_type_map_t::find_type<FTs>>}),
1271+
...);
12561272
((fmap[DPNPFuncName::DPNP_FN_SUBTRACT_EXT][FT1][FTs] =
12571273
{populate_func_types<FT1, FTs>(),
12581274
(void*)dpnp_subtract_c_ext<func_type_map_t::find_type<populate_func_types<FT1, FTs>()>,
12591275
func_type_map_t::find_type<FT1>,
12601276
func_type_map_t::find_type<FTs>>}),
12611277
...);
1262-
((fmap[DPNPFuncName::DPNP_FN_DIVIDE_EXT][FT1][FTs] =
1263-
{get_divide_res_type<FT1, FTs>(),
1264-
(void*)dpnp_divide_c_ext<func_type_map_t::find_type<get_divide_res_type<FT1, FTs>()>,
1265-
func_type_map_t::find_type<FT1>,
1266-
func_type_map_t::find_type<FTs>>,
1267-
get_divide_res_type<FT1, FTs, std::false_type>(),
1268-
(void*)dpnp_divide_c_ext<func_type_map_t::find_type<get_divide_res_type<FT1, FTs, std::false_type>()>,
1269-
func_type_map_t::find_type<FT1>,
1270-
func_type_map_t::find_type<FTs>>}),
1271-
...);
12721278
}
12731279

12741280
template <DPNPFuncType... FTs>
@@ -1855,39 +1861,6 @@ static void func_map_init_elemwise_2arg_3type(func_map_t& fmap)
18551861
fmap[DPNPFuncName::DPNP_FN_POWER][eft_DBL][eft_DBL] = {eft_DBL,
18561862
(void*)dpnp_power_c_default<double, double, double>};
18571863

1858-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_INT][eft_INT] = {eft_INT,
1859-
(void*)dpnp_power_c_ext<int32_t, int32_t, int32_t>};
1860-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_INT][eft_LNG] = {eft_LNG,
1861-
(void*)dpnp_power_c_ext<int64_t, int32_t, int64_t>};
1862-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_INT][eft_FLT] = {eft_DBL,
1863-
(void*)dpnp_power_c_ext<double, int32_t, float>};
1864-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_INT][eft_DBL] = {eft_DBL,
1865-
(void*)dpnp_power_c_ext<double, int32_t, double>};
1866-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_LNG][eft_INT] = {eft_LNG,
1867-
(void*)dpnp_power_c_ext<int64_t, int64_t, int32_t>};
1868-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_LNG][eft_LNG] = {eft_LNG,
1869-
(void*)dpnp_power_c_ext<int64_t, int64_t, int64_t>};
1870-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_LNG][eft_FLT] = {eft_DBL,
1871-
(void*)dpnp_power_c_ext<double, int64_t, float>};
1872-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_LNG][eft_DBL] = {eft_DBL,
1873-
(void*)dpnp_power_c_ext<double, int64_t, double>};
1874-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_FLT][eft_INT] = {eft_DBL,
1875-
(void*)dpnp_power_c_ext<double, float, int32_t>};
1876-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_FLT][eft_LNG] = {eft_DBL,
1877-
(void*)dpnp_power_c_ext<double, float, int64_t>};
1878-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_FLT][eft_FLT] = {eft_FLT,
1879-
(void*)dpnp_power_c_ext<float, float, float>};
1880-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_FLT][eft_DBL] = {eft_DBL,
1881-
(void*)dpnp_power_c_ext<double, float, double>};
1882-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_DBL][eft_INT] = {eft_DBL,
1883-
(void*)dpnp_power_c_ext<double, double, int32_t>};
1884-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_DBL][eft_LNG] = {eft_DBL,
1885-
(void*)dpnp_power_c_ext<double, double, int64_t>};
1886-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_DBL][eft_FLT] = {eft_DBL,
1887-
(void*)dpnp_power_c_ext<double, double, float>};
1888-
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_DBL][eft_DBL] = {eft_DBL,
1889-
(void*)dpnp_power_c_ext<double, double, double>};
1890-
18911864
fmap[DPNPFuncName::DPNP_FN_SUBTRACT][eft_INT][eft_INT] = {
18921865
eft_INT, (void*)dpnp_subtract_c_default<int32_t, int32_t, int32_t>};
18931866
fmap[DPNPFuncName::DPNP_FN_SUBTRACT][eft_INT][eft_LNG] = {

dpnp/dpnp_array.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ def __int__(self):
211211

212212
# '__invert__',
213213
# '__ior__',
214-
# '__ipow__',
214+
215+
def __ipow__(self, other):
216+
dpnp.power(self, other, out=self)
217+
return self
218+
215219
# '__irshift__',
216220
# '__isub__',
217221
# '__iter__',
@@ -279,7 +283,10 @@ def __rmul__(self, other):
279283
return dpnp.multiply(other, self)
280284

281285
# '__ror__',
282-
# '__rpow__',
286+
287+
def __rpow__(self, other):
288+
return dpnp.power(other, self)
289+
283290
# '__rrshift__',
284291
# '__rshift__',
285292

dpnp/dpnp_iface_logic.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ def equal(x1,
253253
254254
Limitations
255255
-----------
256-
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
257-
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
256+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
257+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
258258
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
259259
Otherwise the function will be executed sequentially on CPU.
260260
Input array data types are limited by supported DPNP :ref:`Data types`,
@@ -323,8 +323,8 @@ def greater(x1,
323323
324324
Limitations
325325
-----------
326-
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
327-
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
326+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
327+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
328328
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
329329
Otherwise the function will be executed sequentially on CPU.
330330
Input array data types are limited by supported DPNP :ref:`Data types`,
@@ -393,8 +393,8 @@ def greater_equal(x1,
393393
394394
Limitations
395395
-----------
396-
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
397-
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
396+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
397+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
398398
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
399399
Otherwise the function will be executed sequentially on CPU.
400400
Input array data types are limited by supported DPNP :ref:`Data types`,
@@ -638,8 +638,8 @@ def less(x1,
638638
639639
Limitations
640640
-----------
641-
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
642-
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
641+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
642+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
643643
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
644644
Otherwise the function will be executed sequentially on CPU.
645645
Input array data types are limited by supported DPNP :ref:`Data types`,
@@ -708,8 +708,8 @@ def less_equal(x1,
708708
709709
Limitations
710710
-----------
711-
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
712-
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
711+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
712+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
713713
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
714714
Otherwise the function will be executed sequentially on CPU.
715715
Input array data types are limited by supported DPNP :ref:`Data types`,
@@ -778,8 +778,8 @@ def logical_and(x1,
778778
779779
Limitations
780780
-----------
781-
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
782-
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
781+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
782+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
783783
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
784784
Otherwise the function will be executed sequentially on CPU.
785785
Input array data types are limited by supported DPNP :ref:`Data types`,
@@ -847,7 +847,7 @@ def logical_not(x,
847847
848848
Limitations
849849
-----------
850-
Parameters `x` is only supported as :class:`dpnp.ndarray`.
850+
Parameters `x` is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
851851
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
852852
Otherwise the function will be executed sequentially on CPU.
853853
Input array data type is limited by supported DPNP :ref:`Data types`,
@@ -904,8 +904,8 @@ def logical_or(x1,
904904
905905
Limitations
906906
-----------
907-
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
908-
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
907+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
908+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
909909
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
910910
Otherwise the function will be executed sequentially on CPU.
911911
Input array data types are limited by supported DPNP :ref:`Data types`,
@@ -973,8 +973,8 @@ def logical_xor(x1,
973973
974974
Limitations
975975
-----------
976-
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
977-
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
976+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
977+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
978978
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
979979
Otherwise the function will be executed sequentially on CPU.
980980
Input array data types are limited by supported DPNP :ref:`Data types`,
@@ -1042,8 +1042,8 @@ def not_equal(x1,
10421042
10431043
Limitations
10441044
-----------
1045-
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
1046-
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
1045+
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
1046+
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
10471047
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
10481048
Otherwise the function will be executed sequentially on CPU.
10491049
Input array data types are limited by supported DPNP :ref:`Data types`,

0 commit comments

Comments
 (0)