Skip to content

Commit

Permalink
Implement dpnp.gradient function (#1859)
Browse files Browse the repository at this point in the history
* Implement dpnp.gradient function

* Resolve pre-commit issues

* Update dpnp/dpnp_iface_mathematical.py

Co-authored-by: vtavana <120411540+vtavana@users.noreply.github.com>

* Update dpnp/dpnp_iface_mathematical.py

Co-authored-by: vtavana <120411540+vtavana@users.noreply.github.com>

---------

Co-authored-by: vtavana <120411540+vtavana@users.noreply.github.com>
  • Loading branch information
antonwolfy and vtavana authored May 31, 2024
1 parent 59be03d commit 841664c
Show file tree
Hide file tree
Showing 7 changed files with 734 additions and 118 deletions.
31 changes: 0 additions & 31 deletions dpnp/dpnp_algo/dpnp_algo_mathematical.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ __all__ += [
"dpnp_ediff1d",
"dpnp_fabs",
"dpnp_fmod",
"dpnp_gradient",
"dpnp_fmax",
"dpnp_fmin",
"dpnp_modf",
Expand Down Expand Up @@ -123,36 +122,6 @@ cpdef utils.dpnp_descriptor dpnp_fmod(utils.dpnp_descriptor x1_obj,
return call_fptr_2in_1out_strides(DPNP_FN_FMOD_EXT, x1_obj, x2_obj, dtype, out, where)


cpdef utils.dpnp_descriptor dpnp_gradient(utils.dpnp_descriptor y1, int dx=1):

cdef size_t size = y1.size

y1_obj = y1.get_array()

# create result array with type given by FPTR data
cdef shape_type_c result_shape = utils._object_to_tuple(size)
cdef utils.dpnp_descriptor result = utils_py.create_output_descriptor_py(result_shape,
dpnp.default_float_type(y1_obj.sycl_queue),
None,
device=y1_obj.sycl_device,
usm_type=y1_obj.usm_type,
sycl_queue=y1_obj.sycl_queue)

cdef double cur = (y1.get_pyobj()[1] - y1.get_pyobj()[0]) / dx

result.get_pyobj().flat[0] = cur

cur = (y1.get_pyobj()[-1] - y1.get_pyobj()[-2]) / dx

result.get_pyobj().flat[size - 1] = cur

for i in range(1, size - 1):
cur = (y1.get_pyobj()[i + 1] - y1.get_pyobj()[i - 1]) / (2 * dx)
result.get_pyobj().flat[i] = cur

return result


cpdef utils.dpnp_descriptor dpnp_fmax(utils.dpnp_descriptor x1_obj,
utils.dpnp_descriptor x2_obj,
object dtype=None,
Expand Down
Loading

0 comments on commit 841664c

Please sign in to comment.