Skip to content
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

implement maximum and minimum #1558

Merged
merged 5 commits into from
Sep 29, 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_iface_fptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,17 @@ enum class DPNPFuncName : size_t
requires extra parameters */
DPNP_FN_MAX, /**< Used in numpy.max() impl */
DPNP_FN_MAX_EXT, /**< Used in numpy.max() impl, requires extra parameters */
DPNP_FN_MAXIMUM, /**< Used in numpy.maximum() impl */
DPNP_FN_MAXIMUM_EXT, /**< Used in numpy.maximum() impl , requires extra
DPNP_FN_MAXIMUM, /**< Used in numpy.fmax() impl */
DPNP_FN_MAXIMUM_EXT, /**< Used in numpy.fmax() impl , requires extra
parameters */
DPNP_FN_MEAN, /**< Used in numpy.mean() impl */
DPNP_FN_MEDIAN, /**< Used in numpy.median() impl */
DPNP_FN_MEDIAN_EXT, /**< Used in numpy.median() impl, requires extra
parameters */
DPNP_FN_MIN, /**< Used in numpy.min() impl */
DPNP_FN_MIN_EXT, /**< Used in numpy.min() impl, requires extra parameters */
DPNP_FN_MINIMUM, /**< Used in numpy.minimum() impl */
DPNP_FN_MINIMUM_EXT, /**< Used in numpy.minimum() impl, requires extra
DPNP_FN_MINIMUM, /**< Used in numpy.fmin() impl */
DPNP_FN_MINIMUM_EXT, /**< Used in numpy.fmax() impl, requires extra
parameters */
DPNP_FN_MODF, /**< Used in numpy.modf() impl */
DPNP_FN_MODF_EXT, /**< Used in numpy.modf() impl, requires extra parameters
Expand Down
5 changes: 2 additions & 3 deletions dpnp/dpnp_algo/dpnp_algo.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,10 @@ Mathematical functions
"""
cpdef dpnp_descriptor dpnp_hypot(dpnp_descriptor x1_obj, dpnp_descriptor x2_obj, object dtype=*,
dpnp_descriptor out=*, object where=*)
cpdef dpnp_descriptor dpnp_maximum(dpnp_descriptor x1_obj, dpnp_descriptor x2_obj, object dtype=*,
cpdef dpnp_descriptor dpnp_fmax(dpnp_descriptor x1_obj, dpnp_descriptor x2_obj, object dtype=*,
dpnp_descriptor out=*, object where=*)
cpdef dpnp_descriptor dpnp_minimum(dpnp_descriptor x1_obj, dpnp_descriptor x2_obj, object dtype=*,
cpdef dpnp_descriptor dpnp_fmin(dpnp_descriptor x1_obj, dpnp_descriptor x2_obj, object dtype=*,
dpnp_descriptor out=*, object where=*)

"""
Array manipulation routines
"""
Expand Down
8 changes: 4 additions & 4 deletions dpnp/dpnp_algo/dpnp_algo_mathematical.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ __all__ += [
"dpnp_fmod",
"dpnp_gradient",
'dpnp_hypot',
"dpnp_maximum",
"dpnp_minimum",
"dpnp_fmax",
"dpnp_fmin",
"dpnp_modf",
"dpnp_nancumprod",
"dpnp_nancumsum",
Expand Down Expand Up @@ -281,15 +281,15 @@ cpdef utils.dpnp_descriptor dpnp_hypot(utils.dpnp_descriptor x1_obj,
return call_fptr_2in_1out_strides(DPNP_FN_HYPOT_EXT, x1_obj, x2_obj, dtype, out, where)


cpdef utils.dpnp_descriptor dpnp_maximum(utils.dpnp_descriptor x1_obj,
cpdef utils.dpnp_descriptor dpnp_fmax(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_MAXIMUM_EXT, x1_obj, x2_obj, dtype, out, where)


cpdef utils.dpnp_descriptor dpnp_minimum(utils.dpnp_descriptor x1_obj,
cpdef utils.dpnp_descriptor dpnp_fmin(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
utils.dpnp_descriptor out=None,
Expand Down
94 changes: 94 additions & 0 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"dpnp_logical_not",
"dpnp_logical_or",
"dpnp_logical_xor",
"dpnp_maximum",
"dpnp_minimum",
"dpnp_multiply",
"dpnp_negative",
"dpnp_positive",
Expand Down Expand Up @@ -1813,6 +1815,98 @@ def dpnp_logical_xor(x1, x2, out=None, order="K"):
return dpnp_array._create_from_usm_ndarray(res_usm)


_maximum_docstring_ = """
maximum(x1, x2, out=None, order='K')

Compares two input arrays `x1` and `x2` and returns
a new array containing the element-wise maxima.

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", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
dpnp.ndarray:
An array containing the element-wise maxima. The data type of
the returned array is determined by the Type Promotion Rules.
"""


maximum_func = BinaryElementwiseFunc(
"maximum",
ti._maximum_result_type,
ti._maximum,
_maximum_docstring_,
)


def dpnp_maximum(x1, x2, out=None, order="K"):
"""Invokes maximum() from dpctl.tensor implementation for maximum() 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)

res_usm = maximum_func(
x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order
)
return dpnp_array._create_from_usm_ndarray(res_usm)


_minimum_docstring_ = """
minimum(x1, x2, out=None, order='K')

Compares two input arrays `x1` and `x2` and returns
a new array containing the element-wise minima.

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", optional):
Memory layout of the newly output array, if parameter `out` is `None`.
Default: "K".
Returns:
dpnp.ndarray:
An array containing the element-wise minima. The data type of
the returned array is determined by the Type Promotion Rules.
"""


minimum_func = BinaryElementwiseFunc(
"minimum",
ti._minimum_result_type,
ti._minimum,
_minimum_docstring_,
)


def dpnp_minimum(x1, x2, out=None, order="K"):
"""Invokes minimum() from dpctl.tensor implementation for minimum() 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)

res_usm = minimum_func(
x1_usm_or_scalar, x2_usm_or_scalar, out=out_usm, order=order
)
return dpnp_array._create_from_usm_ndarray(res_usm)


_multiply_docstring_ = """
multiply(x1, x2, out=None, order="K")

Expand Down
Loading
Loading