Skip to content

Reuse dpctl.tensor comparison functions for dpnp #1438

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

Closed
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
12 changes: 0 additions & 12 deletions dpnp/dpnp_algo/dpnp_algo.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_EIG_EXT
DPNP_FN_EIGVALS
DPNP_FN_EIGVALS_EXT
DPNP_FN_EQUAL_EXT
DPNP_FN_ERF
DPNP_FN_ERF_EXT
DPNP_FN_EYE
Expand Down Expand Up @@ -150,8 +149,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_FMOD_EXT
DPNP_FN_FULL
DPNP_FN_FULL_LIKE
DPNP_FN_GREATER_EXT
DPNP_FN_GREATER_EQUAL_EXT
DPNP_FN_HYPOT
DPNP_FN_HYPOT_EXT
DPNP_FN_IDENTITY
Expand All @@ -166,8 +163,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_KRON_EXT
DPNP_FN_LEFT_SHIFT
DPNP_FN_LEFT_SHIFT_EXT
DPNP_FN_LESS_EXT
DPNP_FN_LESS_EQUAL_EXT
DPNP_FN_LOG
DPNP_FN_LOG_EXT
DPNP_FN_LOG10
Expand Down Expand Up @@ -201,7 +196,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
DPNP_FN_NEGATIVE
DPNP_FN_NEGATIVE_EXT
DPNP_FN_NONZERO
DPNP_FN_NOT_EQUAL_EXT
DPNP_FN_ONES
DPNP_FN_ONES_LIKE
DPNP_FN_PARTITION
Expand Down Expand Up @@ -482,18 +476,12 @@ cpdef dpnp_descriptor dpnp_right_shift(dpnp_descriptor x1_obj,
"""
Logic functions
"""
cpdef dpnp_descriptor dpnp_equal(dpnp_descriptor array1, dpnp_descriptor input2)
cpdef dpnp_descriptor dpnp_greater(dpnp_descriptor input1, dpnp_descriptor input2)
cpdef dpnp_descriptor dpnp_greater_equal(dpnp_descriptor input1, dpnp_descriptor input2)
cpdef dpnp_descriptor dpnp_isclose(dpnp_descriptor input1, dpnp_descriptor input2,
double rtol=*, double atol=*, cpp_bool equal_nan=*)
cpdef dpnp_descriptor dpnp_less(dpnp_descriptor input1, dpnp_descriptor input2)
cpdef dpnp_descriptor dpnp_less_equal(dpnp_descriptor input1, dpnp_descriptor input2)
cpdef dpnp_descriptor dpnp_logical_and(dpnp_descriptor input1, dpnp_descriptor input2)
cpdef dpnp_descriptor dpnp_logical_not(dpnp_descriptor input1)
cpdef dpnp_descriptor dpnp_logical_or(dpnp_descriptor input1, dpnp_descriptor input2)
cpdef dpnp_descriptor dpnp_logical_xor(dpnp_descriptor input1, dpnp_descriptor input2)
cpdef dpnp_descriptor dpnp_not_equal(dpnp_descriptor input1, dpnp_descriptor input2)


"""
Expand Down
54 changes: 0 additions & 54 deletions dpnp/dpnp_algo/dpnp_algo_logic.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,14 @@ __all__ += [
"dpnp_all",
"dpnp_allclose",
"dpnp_any",
"dpnp_equal",
"dpnp_greater",
"dpnp_greater_equal",
"dpnp_isclose",
"dpnp_isfinite",
"dpnp_isinf",
"dpnp_isnan",
"dpnp_less",
"dpnp_less_equal",
"dpnp_logical_and",
"dpnp_logical_not",
"dpnp_logical_or",
"dpnp_logical_xor",
"dpnp_not_equal"
]


Expand Down Expand Up @@ -167,30 +161,6 @@ cpdef utils.dpnp_descriptor dpnp_any(utils.dpnp_descriptor array1):
return result


cpdef utils.dpnp_descriptor dpnp_equal(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
utils.dpnp_descriptor out=None,
object where=True):
return call_fptr_2in_1out_strides(DPNP_FN_EQUAL_EXT, x1_obj, x2_obj, dtype, out, where, func_name="equal")


cpdef utils.dpnp_descriptor dpnp_greater(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
utils.dpnp_descriptor out=None,
object where=True):
return call_fptr_2in_1out_strides(DPNP_FN_GREATER_EXT, x1_obj, x2_obj, dtype, out, where, func_name="greater")


cpdef utils.dpnp_descriptor dpnp_greater_equal(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
utils.dpnp_descriptor out=None,
object where=True):
return call_fptr_2in_1out_strides(DPNP_FN_GREATER_EQUAL_EXT, x1_obj, x2_obj, dtype, out, where, func_name="greater_equal")


cpdef utils.dpnp_descriptor dpnp_isclose(utils.dpnp_descriptor input1,
utils.dpnp_descriptor input2,
double rtol=1e-05,
Expand Down Expand Up @@ -255,22 +225,6 @@ cpdef utils.dpnp_descriptor dpnp_isnan(utils.dpnp_descriptor input1):
return result


cpdef utils.dpnp_descriptor dpnp_less(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
utils.dpnp_descriptor out=None,
object where=True):
return call_fptr_2in_1out_strides(DPNP_FN_LESS_EXT, x1_obj, x2_obj, dtype, out, where, func_name="less")


cpdef utils.dpnp_descriptor dpnp_less_equal(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
utils.dpnp_descriptor out=None,
object where=True):
return call_fptr_2in_1out_strides(DPNP_FN_LESS_EQUAL_EXT, x1_obj, x2_obj, dtype, out, where, func_name="less_equal")


cpdef utils.dpnp_descriptor dpnp_logical_and(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
Expand Down Expand Up @@ -300,11 +254,3 @@ cpdef utils.dpnp_descriptor dpnp_logical_xor(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor out=None,
object where=True):
return call_fptr_2in_1out_strides(DPNP_FN_LOGICAL_XOR_EXT, x1_obj, x2_obj, dtype, out, where, func_name="logical_xor")


cpdef utils.dpnp_descriptor dpnp_not_equal(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
utils.dpnp_descriptor out=None,
object where=True):
return call_fptr_2in_1out_strides(DPNP_FN_NOT_EQUAL_EXT, x1_obj, x2_obj, dtype, out, where, func_name="not_equal")
248 changes: 247 additions & 1 deletion dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@
__all__ = [
"dpnp_add",
"dpnp_divide",
"dpnp_equal",
"dpnp_greater",
"dpnp_greater_equal",
"dpnp_less",
"dpnp_less_equal",
"dpnp_multiply",
"dpnp_subtract"
"dpnp_not_equal",
"dpnp_subtract",
]


Expand Down Expand Up @@ -241,3 +247,243 @@ def dpnp_subtract(x1, x2, out=None, order='K'):
_subtract_docstring_, ti._subtract_inplace)
res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order)
return dpnp_array._create_from_usm_ndarray(res_usm)


_less_docstring_ = """
less(x1, x2, out=None, order='K')

Calculates the less-than results for each element `x1_i` of
the input array `x1` the respective element `x2_i` of the input array `x2`.

Args:
x1 (dpnp.ndarray):
First input array, expected to have numeric data type.
x2 (dpnp.ndarray):
Second input array, also expected to have numeric data type.
out ({None, dpnp.ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", None, optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
dpnp.ndarray:
an array containing the result of element-wise less-than comparison.
The data type of the returned array is determined by the Type Promotion Rules.
"""

def dpnp_less(x1, x2, out=None, order='K'):
"""
Invokes less() from dpctl.tensor implementation for less() function.

"""

# dpctl.tensor only works with usm_ndarray or scalar
x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1)
x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)

func = BinaryElementwiseFunc("less", ti._less_result_type, ti._less,
_less_docstring_)
res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order)
return dpnp_array._create_from_usm_ndarray(res_usm)


_less_equal_docstring_ = """
less_equal(x1, x2, out=None, order='K')

Calculates the less-than or equal-to results for each element `x1_i` of
the input array `x1` the respective element `x2_i` of the input array `x2`.

Args:
x1 (dpnp.ndarray):
First input array, expected to have numeric data type.
x2 (dpnp.ndarray):
Second input array, also expected to have numeric data type.
out ({None, dpnp.ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", None, optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
dpnp.ndarray:
An array containing the result of element-wise less-than or equal-to comparison.
The data type of the returned array is determined by the Type Promotion Rules.
"""

def dpnp_less_equal(x1, x2, out=None, order='K'):
"""
Invokes less_equal() from dpctl.tensor implementation for less_equal() function.

"""

# dpctl.tensor only works with usm_ndarray or scalar
x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1)
x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)

func = BinaryElementwiseFunc("less_equal", ti._less_equal_result_type, ti._less_equal,
_less_equal_docstring_)
res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order)
return dpnp_array._create_from_usm_ndarray(res_usm)


_greater_docstring_ = """
greater(x1, x2, out=None, order='K')

Calculates the greater-than results for each element `x1_i` of
the input array `x1` the respective element `x2_i` of the input array `x2`.

Args:
x1 (dpnp.ndarray):
First input array, expected to have numeric data type.
x2 (dpnp.ndarray):
Second input array, also expected to have numeric data type.
out ({None, dpnp.ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", None, optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
dpnp.ndarray:
an array containing the result of element-wise greater-than comparison.
The data type of the returned array is determined by the Type Promotion Rules.
"""

def dpnp_greater(x1, x2, out=None, order='K'):
"""
Invokes greater() from dpctl.tensor implementation for greater() function.

"""

# dpctl.tensor only works with usm_ndarray or scalar
x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1)
x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)

func = BinaryElementwiseFunc("greater", ti._greater_result_type, ti._greater,
_greater_docstring_)
res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order)
return dpnp_array._create_from_usm_ndarray(res_usm)


_greater_equal_docstring_ = """
greater_equal(x1, x2, out=None, order='K')

Calculates the greater-than or equal-to results for each element `x1_i` of
the input array `x1` the respective element `x2_i` of the input array `x2`.

Args:
x1 (dpnp.ndarray):
First input array, expected to have numeric data type.
x2 (dpnp.ndarray):
Second input array, also expected to have numeric data type.
out ({None, dpnp.ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", None, optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
dpnp.ndarray:
an array containing the result of element-wise greater-than or equal-to comparison.
The data type of the returned array is determined by the Type Promotion Rules.
"""

def dpnp_greater_equal(x1, x2, out=None, order='K'):
"""
Invokes greater_equal() from dpctl.tensor implementation for greater_equal() function.

"""

# dpctl.tensor only works with usm_ndarray or scalar
x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1)
x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)

func = BinaryElementwiseFunc("greater_equal", ti._greater_equal_result_type,
ti._greater_equal, _greater_equal_docstring_)
res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order)
return dpnp_array._create_from_usm_ndarray(res_usm)


_equal_docstring_ = """
equal(x1, x2, out=None, order='K')

Calculates equality results for each element `x1_i` of
the input array `x1` the respective element `x2_i` of the input array `x2`.

Args:
x1 (dpnp.ndarray):
First input array, expected to have numeric data type.
x2 (dpnp.ndarray):
Second input array, also expected to have numeric data type.
out ({None, dpnp.ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", None, optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
dpnp.ndarray:
an array containing the result of element-wise equality comparison.
The data type of the returned array is determined by the Type Promotion Rules.
"""

def dpnp_equal(x1, x2, out=None, order='K'):
"""
Invokes equal() from dpctl.tensor implementation for equal() function.

"""

# dpctl.tensor only works with usm_ndarray or scalar
x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1)
x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)

func = BinaryElementwiseFunc("equal", ti._equal_result_type, ti._equal,
_equal_docstring_)
res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order)
return dpnp_array._create_from_usm_ndarray(res_usm)


_not_equal_docstring_ = """
not_equal(x1, x2, out=None, order='K')

Calculates inequality results for each element `x1_i` of
the input array `x1` the respective element `x2_i` of the input array `x2`.

Args:
x1 (dpnp.ndarray):
First input array, expected to have numeric data type.
x2 (dpnp.ndarray):
Second input array, also expected to have numeric data type.
out ({None, dpnp.ndarray}, optional):
Output array to populate.
Array have the correct shape and the expected data type.
order ("C","F","A","K", None, optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
dpnp.ndarray:
an array containing the result of element-wise inequality comparison.
The data type of the returned array is determined by the Type Promotion Rules.
"""

def dpnp_not_equal(x1, x2, out=None, order='K'):
"""
Invokes not_equal() from dpctl.tensor implementation for not_equal() function.

"""

# dpctl.tensor only works with usm_ndarray or scalar
x1_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x1)
x2_usm_or_scalar = dpnp.get_usm_ndarray_or_scalar(x2)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)

func = BinaryElementwiseFunc("not_equal", ti._not_equal_result_type, ti._not_equal,
_not_equal_docstring_)
res_usm = func(x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order)
return dpnp_array._create_from_usm_ndarray(res_usm)
Loading