Skip to content

dpnp.power() doesn't work properly with a scalar #1323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dpnp/backend/include/dpnp_gen_2arg_3type_tbl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ MACRO_2ARG_3TYPES_OP(dpnp_multiply_c,
MACRO_UNPACK_TYPES(float, double, std::complex<float>, std::complex<double>))

MACRO_2ARG_3TYPES_OP(dpnp_power_c,
sycl::pow((double)input1_elem, (double)input2_elem),
nullptr,
std::false_type,
static_cast<_DataType_output>(std::pow(input1_elem, input2_elem)),
sycl::pow(x1, x2),
MACRO_UNPACK_TYPES(float, double),
oneapi::mkl::vm::pow,
MACRO_UNPACK_TYPES(float, double))
MACRO_UNPACK_TYPES(float, double, std::complex<float>, std::complex<double>))

MACRO_2ARG_3TYPES_OP(dpnp_subtract_c,
input1_elem - input2_elem,
Expand Down
59 changes: 16 additions & 43 deletions dpnp/backend/kernels/dpnp_krnl_elemwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,28 +1247,34 @@ static void func_map_elemwise_2arg_3type_core(func_map_t& fmap)
func_type_map_t::find_type<FT1>,
func_type_map_t::find_type<FTs>>}),
...);
((fmap[DPNPFuncName::DPNP_FN_DIVIDE_EXT][FT1][FTs] =
{get_divide_res_type<FT1, FTs>(),
(void*)dpnp_divide_c_ext<func_type_map_t::find_type<get_divide_res_type<FT1, FTs>()>,
func_type_map_t::find_type<FT1>,
func_type_map_t::find_type<FTs>>,
get_divide_res_type<FT1, FTs, std::false_type>(),
(void*)dpnp_divide_c_ext<func_type_map_t::find_type<get_divide_res_type<FT1, FTs, std::false_type>()>,
func_type_map_t::find_type<FT1>,
func_type_map_t::find_type<FTs>>}),
...);
((fmap[DPNPFuncName::DPNP_FN_MULTIPLY_EXT][FT1][FTs] =
{populate_func_types<FT1, FTs>(),
(void*)dpnp_multiply_c_ext<func_type_map_t::find_type<populate_func_types<FT1, FTs>()>,
func_type_map_t::find_type<FT1>,
func_type_map_t::find_type<FTs>>}),
...);
((fmap[DPNPFuncName::DPNP_FN_POWER_EXT][FT1][FTs] =
{populate_func_types<FT1, FTs>(),
(void*)dpnp_power_c_ext<func_type_map_t::find_type<populate_func_types<FT1, FTs>()>,
func_type_map_t::find_type<FT1>,
func_type_map_t::find_type<FTs>>}),
...);
((fmap[DPNPFuncName::DPNP_FN_SUBTRACT_EXT][FT1][FTs] =
{populate_func_types<FT1, FTs>(),
(void*)dpnp_subtract_c_ext<func_type_map_t::find_type<populate_func_types<FT1, FTs>()>,
func_type_map_t::find_type<FT1>,
func_type_map_t::find_type<FTs>>}),
...);
((fmap[DPNPFuncName::DPNP_FN_DIVIDE_EXT][FT1][FTs] =
{get_divide_res_type<FT1, FTs>(),
(void*)dpnp_divide_c_ext<func_type_map_t::find_type<get_divide_res_type<FT1, FTs>()>,
func_type_map_t::find_type<FT1>,
func_type_map_t::find_type<FTs>>,
get_divide_res_type<FT1, FTs, std::false_type>(),
(void*)dpnp_divide_c_ext<func_type_map_t::find_type<get_divide_res_type<FT1, FTs, std::false_type>()>,
func_type_map_t::find_type<FT1>,
func_type_map_t::find_type<FTs>>}),
...);
}

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

fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_INT][eft_INT] = {eft_INT,
(void*)dpnp_power_c_ext<int32_t, int32_t, int32_t>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_INT][eft_LNG] = {eft_LNG,
(void*)dpnp_power_c_ext<int64_t, int32_t, int64_t>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_INT][eft_FLT] = {eft_DBL,
(void*)dpnp_power_c_ext<double, int32_t, float>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_INT][eft_DBL] = {eft_DBL,
(void*)dpnp_power_c_ext<double, int32_t, double>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_LNG][eft_INT] = {eft_LNG,
(void*)dpnp_power_c_ext<int64_t, int64_t, int32_t>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_LNG][eft_LNG] = {eft_LNG,
(void*)dpnp_power_c_ext<int64_t, int64_t, int64_t>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_LNG][eft_FLT] = {eft_DBL,
(void*)dpnp_power_c_ext<double, int64_t, float>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_LNG][eft_DBL] = {eft_DBL,
(void*)dpnp_power_c_ext<double, int64_t, double>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_FLT][eft_INT] = {eft_DBL,
(void*)dpnp_power_c_ext<double, float, int32_t>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_FLT][eft_LNG] = {eft_DBL,
(void*)dpnp_power_c_ext<double, float, int64_t>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_FLT][eft_FLT] = {eft_FLT,
(void*)dpnp_power_c_ext<float, float, float>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_FLT][eft_DBL] = {eft_DBL,
(void*)dpnp_power_c_ext<double, float, double>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_DBL][eft_INT] = {eft_DBL,
(void*)dpnp_power_c_ext<double, double, int32_t>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_DBL][eft_LNG] = {eft_DBL,
(void*)dpnp_power_c_ext<double, double, int64_t>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_DBL][eft_FLT] = {eft_DBL,
(void*)dpnp_power_c_ext<double, double, float>};
fmap[DPNPFuncName::DPNP_FN_POWER_EXT][eft_DBL][eft_DBL] = {eft_DBL,
(void*)dpnp_power_c_ext<double, double, double>};

fmap[DPNPFuncName::DPNP_FN_SUBTRACT][eft_INT][eft_INT] = {
eft_INT, (void*)dpnp_subtract_c_default<int32_t, int32_t, int32_t>};
fmap[DPNPFuncName::DPNP_FN_SUBTRACT][eft_INT][eft_LNG] = {
Expand Down
11 changes: 9 additions & 2 deletions dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ def __int__(self):

# '__invert__',
# '__ior__',
# '__ipow__',

def __ipow__(self, other):
dpnp.power(self, other, out=self)
return self

# '__irshift__',
# '__isub__',
# '__iter__',
Expand Down Expand Up @@ -279,7 +283,10 @@ def __rmul__(self, other):
return dpnp.multiply(other, self)

# '__ror__',
# '__rpow__',

def __rpow__(self, other):
return dpnp.power(other, self)

# '__rrshift__',
# '__rshift__',

Expand Down
38 changes: 19 additions & 19 deletions dpnp/dpnp_iface_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def equal(x1,

Limitations
-----------
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`,
Expand Down Expand Up @@ -323,8 +323,8 @@ def greater(x1,

Limitations
-----------
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`,
Expand Down Expand Up @@ -393,8 +393,8 @@ def greater_equal(x1,

Limitations
-----------
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`,
Expand Down Expand Up @@ -638,8 +638,8 @@ def less(x1,

Limitations
-----------
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`,
Expand Down Expand Up @@ -708,8 +708,8 @@ def less_equal(x1,

Limitations
-----------
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`,
Expand Down Expand Up @@ -778,8 +778,8 @@ def logical_and(x1,

Limitations
-----------
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`,
Expand Down Expand Up @@ -847,7 +847,7 @@ def logical_not(x,

Limitations
-----------
Parameters `x` is only supported as :class:`dpnp.ndarray`.
Parameters `x` is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`.
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
Otherwise the function will be executed sequentially on CPU.
Input array data type is limited by supported DPNP :ref:`Data types`,
Expand Down Expand Up @@ -904,8 +904,8 @@ def logical_or(x1,

Limitations
-----------
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`,
Expand Down Expand Up @@ -973,8 +973,8 @@ def logical_xor(x1,

Limitations
-----------
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`,
Expand Down Expand Up @@ -1042,8 +1042,8 @@ def not_equal(x1,

Limitations
-----------
Parameters `x1` and `x2` are supported as either :class:`dpnp.ndarray` or scalar,
but not both (at least either `x1` or `x2` should be as :class:`dpnp.ndarray`).
Parameters `x1` and `x2` are supported as either scalar, :class:`dpnp.ndarray`
or :class:`dpctl.tensor.usm_ndarray`, but both `x1` and `x2` can not be scalars at the same time.
Parameters `out`, `where`, `dtype` and `subok` are supported with their default values.
Otherwise the function will be executed sequentially on CPU.
Input array data types are limited by supported DPNP :ref:`Data types`,
Expand Down
Loading