Skip to content

Commit 841664c

Browse files
antonwolfyvtavana
andauthored
Implement dpnp.gradient function (#1859)
* 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>
1 parent 59be03d commit 841664c

File tree

7 files changed

+734
-118
lines changed

7 files changed

+734
-118
lines changed

dpnp/dpnp_algo/dpnp_algo_mathematical.pxi

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ __all__ += [
3939
"dpnp_ediff1d",
4040
"dpnp_fabs",
4141
"dpnp_fmod",
42-
"dpnp_gradient",
4342
"dpnp_fmax",
4443
"dpnp_fmin",
4544
"dpnp_modf",
@@ -123,36 +122,6 @@ cpdef utils.dpnp_descriptor dpnp_fmod(utils.dpnp_descriptor x1_obj,
123122
return call_fptr_2in_1out_strides(DPNP_FN_FMOD_EXT, x1_obj, x2_obj, dtype, out, where)
124123

125124

126-
cpdef utils.dpnp_descriptor dpnp_gradient(utils.dpnp_descriptor y1, int dx=1):
127-
128-
cdef size_t size = y1.size
129-
130-
y1_obj = y1.get_array()
131-
132-
# create result array with type given by FPTR data
133-
cdef shape_type_c result_shape = utils._object_to_tuple(size)
134-
cdef utils.dpnp_descriptor result = utils_py.create_output_descriptor_py(result_shape,
135-
dpnp.default_float_type(y1_obj.sycl_queue),
136-
None,
137-
device=y1_obj.sycl_device,
138-
usm_type=y1_obj.usm_type,
139-
sycl_queue=y1_obj.sycl_queue)
140-
141-
cdef double cur = (y1.get_pyobj()[1] - y1.get_pyobj()[0]) / dx
142-
143-
result.get_pyobj().flat[0] = cur
144-
145-
cur = (y1.get_pyobj()[-1] - y1.get_pyobj()[-2]) / dx
146-
147-
result.get_pyobj().flat[size - 1] = cur
148-
149-
for i in range(1, size - 1):
150-
cur = (y1.get_pyobj()[i + 1] - y1.get_pyobj()[i - 1]) / (2 * dx)
151-
result.get_pyobj().flat[i] = cur
152-
153-
return result
154-
155-
156125
cpdef utils.dpnp_descriptor dpnp_fmax(utils.dpnp_descriptor x1_obj,
157126
utils.dpnp_descriptor x2_obj,
158127
object dtype=None,

0 commit comments

Comments
 (0)