Skip to content

Commit

Permalink
address reviewer's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vtavana committed Aug 16, 2023
1 parent 15e2611 commit b60eb41
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 90 deletions.
82 changes: 41 additions & 41 deletions dpnp/backend/include/dpnp_iface_fptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,47 +69,47 @@ enum class DPNPFuncName : size_t
DPNP_FN_ALLCLOSE_EXT, /**< Used in numpy.allclose() impl, requires extra
parameters */
DPNP_FN_ANY, /**< Used in numpy.any() impl */
DPNP_FN_ARANGE, /**< Used in numpy.arange() impl */
DPNP_FN_ARCCOS, /**< Used in numpy.arccos() impl */
DPNP_FN_ARCCOS_EXT, /**< Used in numpy.arccos() impl, requires extra
parameters */
DPNP_FN_ARCCOSH, /**< Used in numpy.arccosh() impl */
DPNP_FN_ARCCOSH_EXT, /**< Used in numpy.arccosh() impl, requires extra
parameters */
DPNP_FN_ARCSIN, /**< Used in numpy.arcsin() impl */
DPNP_FN_ARCSIN_EXT, /**< Used in numpy.arcsin() impl, requires extra
parameters */
DPNP_FN_ARCSINH, /**< Used in numpy.arcsinh() impl */
DPNP_FN_ARCSINH_EXT, /**< Used in numpy.arcsinh() impl, requires extra
parameters */
DPNP_FN_ARCTAN, /**< Used in numpy.arctan() impl */
DPNP_FN_ARCTAN_EXT, /**< Used in numpy.arctan() impl, requires extra
parameters */
DPNP_FN_ARCTAN2, /**< Used in numpy.arctan2() impl */
DPNP_FN_ARCTAN2_EXT, /**< Used in numpy.arctan2() impl, requires extra
parameters */
DPNP_FN_ARCTANH, /**< Used in numpy.arctanh() impl */
DPNP_FN_ARCTANH_EXT, /**< Used in numpy.arctanh() impl, requires extra
parameters */
DPNP_FN_ARGMAX, /**< Used in numpy.argmax() impl */
DPNP_FN_ARGMAX_EXT, /**< Used in numpy.argmax() impl, requires extra
parameters */
DPNP_FN_ARGMIN, /**< Used in numpy.argmin() impl */
DPNP_FN_ARGMIN_EXT, /**< Used in numpy.argmin() impl, requires extra
parameters */
DPNP_FN_ARGSORT, /**< Used in numpy.argsort() impl */
DPNP_FN_ARGSORT_EXT, /**< Used in numpy.argsort() impl, requires extra
parameters */
DPNP_FN_AROUND, /**< Used in numpy.around() impl */
DPNP_FN_AROUND_EXT, /**< Used in numpy.around() impl, requires extra
parameters */
DPNP_FN_ASTYPE, /**< Used in numpy.astype() impl */
DPNP_FN_ASTYPE_EXT, /**< Used in numpy.astype() impl, requires extra
parameters */
DPNP_FN_BITWISE_AND, /**< Used in numpy.bitwise_and() impl */
DPNP_FN_BITWISE_OR, /**< Used in numpy.bitwise_or() impl */
DPNP_FN_BITWISE_XOR, /**< Used in numpy.bitwise_xor() impl */
DPNP_FN_CBRT, /**< Used in numpy.cbrt() impl */
DPNP_FN_ARANGE, /**< Used in numpy.arange() impl */
DPNP_FN_ARCCOS, /**< Used in numpy.arccos() impl */
DPNP_FN_ARCCOS_EXT, /**< Used in numpy.arccos() impl, requires extra
parameters */
DPNP_FN_ARCCOSH, /**< Used in numpy.arccosh() impl */
DPNP_FN_ARCCOSH_EXT, /**< Used in numpy.arccosh() impl, requires extra
parameters */
DPNP_FN_ARCSIN, /**< Used in numpy.arcsin() impl */
DPNP_FN_ARCSIN_EXT, /**< Used in numpy.arcsin() impl, requires extra
parameters */
DPNP_FN_ARCSINH, /**< Used in numpy.arcsinh() impl */
DPNP_FN_ARCSINH_EXT, /**< Used in numpy.arcsinh() impl, requires extra
parameters */
DPNP_FN_ARCTAN, /**< Used in numpy.arctan() impl */
DPNP_FN_ARCTAN_EXT, /**< Used in numpy.arctan() impl, requires extra
parameters */
DPNP_FN_ARCTAN2, /**< Used in numpy.arctan2() impl */
DPNP_FN_ARCTAN2_EXT, /**< Used in numpy.arctan2() impl, requires extra
parameters */
DPNP_FN_ARCTANH, /**< Used in numpy.arctanh() impl */
DPNP_FN_ARCTANH_EXT, /**< Used in numpy.arctanh() impl, requires extra
parameters */
DPNP_FN_ARGMAX, /**< Used in numpy.argmax() impl */
DPNP_FN_ARGMAX_EXT, /**< Used in numpy.argmax() impl, requires extra
parameters */
DPNP_FN_ARGMIN, /**< Used in numpy.argmin() impl */
DPNP_FN_ARGMIN_EXT, /**< Used in numpy.argmin() impl, requires extra
parameters */
DPNP_FN_ARGSORT, /**< Used in numpy.argsort() impl */
DPNP_FN_ARGSORT_EXT, /**< Used in numpy.argsort() impl, requires extra
parameters */
DPNP_FN_AROUND, /**< Used in numpy.around() impl */
DPNP_FN_AROUND_EXT, /**< Used in numpy.around() impl, requires extra
parameters */
DPNP_FN_ASTYPE, /**< Used in numpy.astype() impl */
DPNP_FN_ASTYPE_EXT, /**< Used in numpy.astype() impl, requires extra
parameters */
DPNP_FN_BITWISE_AND, /**< Used in numpy.bitwise_and() impl */
DPNP_FN_BITWISE_OR, /**< Used in numpy.bitwise_or() impl */
DPNP_FN_BITWISE_XOR, /**< Used in numpy.bitwise_xor() impl */
DPNP_FN_CBRT, /**< Used in numpy.cbrt() impl */
DPNP_FN_CBRT_EXT, /**< Used in numpy.cbrt() impl, requires extra parameters
*/
DPNP_FN_CEIL, /**< Used in numpy.ceil() impl */
Expand Down
98 changes: 49 additions & 49 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,55 +186,6 @@ def dpnp_add(x1, x2, out=None, order="K"):
return dpnp_array._create_from_usm_ndarray(res_usm)


_cos_docstring = """
cos(x, out=None, order='K')
Computes cosine for each element `x_i` for input array `x`.
Args:
x (dpnp.ndarray):
Input array, expected to have numeric data type.
out ({None, dpnp.ndarray}, optional):
Output array to populate. Array must have the correct
shape and the expected data type.
order ("C","F","A","K", optional): memory layout of the new
output array, if parameter `out` is `None`.
Default: "K".
Return:
dpnp.ndarray:
An array containing the element-wise cosine. The data type
of the returned array is determined by the Type Promotion Rules.
"""


def dpnp_cos(x, out=None, order="K"):
"""
Invokes cos() function from pybind11 extension of OneMKL VM if possible.
Otherwise fully relies on dpctl.tensor implementation for cos() function.
"""

def _call_cos(src, dst, sycl_queue, depends=None):
"""A callback to register in UnaryElementwiseFunc class of dpctl.tensor"""

if depends is None:
depends = []

if vmi._mkl_cos_to_call(sycl_queue, src, dst):
# call pybind11 extension for cos() function from OneMKL VM
return vmi._cos(sycl_queue, src, dst, depends)
return ti._cos(src, dst, sycl_queue, depends)

# dpctl.tensor only works with usm_ndarray
x1_usm = dpnp.get_usm_ndarray(x)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)

func = UnaryElementwiseFunc(
"cos", ti._cos_result_type, _call_cos, _cos_docstring
)
res_usm = func(x1_usm, out=out_usm, order=order)
return dpnp_array._create_from_usm_ndarray(res_usm)


_bitwise_and_docstring_ = """
bitwise_and(x1, x2, out=None, order='K')
Expand Down Expand Up @@ -367,6 +318,55 @@ def dpnp_bitwise_xor(x1, x2, out=None, order="K"):
return dpnp_array._create_from_usm_ndarray(res_usm)


_cos_docstring = """
cos(x, out=None, order='K')
Computes cosine for each element `x_i` for input array `x`.
Args:
x (dpnp.ndarray):
Input array, expected to have numeric data type.
out ({None, dpnp.ndarray}, optional):
Output array to populate. Array must have the correct
shape and the expected data type.
order ("C","F","A","K", optional): memory layout of the new
output array, if parameter `out` is `None`.
Default: "K".
Return:
dpnp.ndarray:
An array containing the element-wise cosine. The data type
of the returned array is determined by the Type Promotion Rules.
"""


def dpnp_cos(x, out=None, order="K"):
"""
Invokes cos() function from pybind11 extension of OneMKL VM if possible.
Otherwise fully relies on dpctl.tensor implementation for cos() function.
"""

def _call_cos(src, dst, sycl_queue, depends=None):
"""A callback to register in UnaryElementwiseFunc class of dpctl.tensor"""

if depends is None:
depends = []

if vmi._mkl_cos_to_call(sycl_queue, src, dst):
# call pybind11 extension for cos() function from OneMKL VM
return vmi._cos(sycl_queue, src, dst, depends)
return ti._cos(src, dst, sycl_queue, depends)

# dpctl.tensor only works with usm_ndarray
x1_usm = dpnp.get_usm_ndarray(x)
out_usm = None if out is None else dpnp.get_usm_ndarray(out)

func = UnaryElementwiseFunc(
"cos", ti._cos_result_type, _call_cos, _cos_docstring
)
res_usm = func(x1_usm, out=out_usm, order=order)
return dpnp_array._create_from_usm_ndarray(res_usm)


_divide_docstring_ = """
divide(x1, x2, out=None, order="K")
Expand Down
5 changes: 5 additions & 0 deletions tests/test_bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_bitwise_and(self, lhs, rhs, dtype):
assert_array_equal(dp_a & dp_b, np_a & np_b)

"""
TODO: unmute once dpctl support that
if (
not (inp.isscalar(dp_a) or inp.isscalar(dp_b))
and dp_a.shape == dp_b.shape
Expand All @@ -84,6 +85,7 @@ def test_bitwise_or(self, lhs, rhs, dtype):
assert_array_equal(dp_a | dp_b, np_a | np_b)

"""
TODO: unmute once dpctl support that
if (
not (inp.isscalar(dp_a) or inp.isscalar(dp_b))
and dp_a.shape == dp_b.shape
Expand All @@ -100,6 +102,7 @@ def test_bitwise_xor(self, lhs, rhs, dtype):
assert_array_equal(dp_a ^ dp_b, np_a ^ np_b)

"""
TODO: unmute once dpctl support that
if (
not (inp.isscalar(dp_a) or inp.isscalar(dp_b))
and dp_a.shape == dp_b.shape
Expand All @@ -120,6 +123,7 @@ def test_left_shift(self, lhs, rhs, dtype):
assert_array_equal(dp_a << dp_b, np_a << np_b)

"""
TODO: unmute once dpctl support that
if (
not (inp.isscalar(dp_a) or inp.isscalar(dp_b))
and dp_a.shape == dp_b.shape
Expand All @@ -136,6 +140,7 @@ def test_right_shift(self, lhs, rhs, dtype):
assert_array_equal(dp_a >> dp_b, np_a >> np_b)

"""
TODO: unmute once dpctl support that
if (
not (inp.isscalar(dp_a) or inp.isscalar(dp_b))
and dp_a.shape == dp_b.shape
Expand Down

0 comments on commit b60eb41

Please sign in to comment.