Skip to content

Commit c90b74c

Browse files
authored
NEGATIVE add kernel required for black_scholes (#674)
1 parent 19fcc96 commit c90b74c

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

dpnp/backend/include/dpnp_gen_1arg_1type_tbl.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@
5757

5858
MACRO_1ARG_1TYPE_OP(dpnp_conjugate_c, std::conj(input_elem), DPNP_QUEUE.submit(kernel_func))
5959
MACRO_1ARG_1TYPE_OP(dpnp_copy_c, input_elem, DPNP_QUEUE.submit(kernel_func))
60-
MACRO_1ARG_1TYPE_OP(dpnp_erf_c, input_elem, oneapi::mkl::vm::erf(DPNP_QUEUE, size, array1, result))
60+
MACRO_1ARG_1TYPE_OP(dpnp_erf_c,
61+
cl::sycl::erf((double)input_elem),
62+
oneapi::mkl::vm::erf(DPNP_QUEUE, size, array1, result)) // no sycl::erf for int and long
63+
MACRO_1ARG_1TYPE_OP(dpnp_negative_c, -input_elem, DPNP_QUEUE.submit(kernel_func))
6164
MACRO_1ARG_1TYPE_OP(dpnp_recip_c,
6265
_DataType(1) / input_elem,
6366
DPNP_QUEUE.submit(kernel_func)) // error: no member named 'recip' in namespace 'cl::sycl'

dpnp/backend/include/dpnp_iface_fptr.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ enum class DPNPFuncName : size_t
134134
DPNP_FN_MINIMUM, /**< Used in numpy.minimum() implementation */
135135
DPNP_FN_MODF, /**< Used in numpy.modf() implementation */
136136
DPNP_FN_MULTIPLY, /**< Used in numpy.multiply() implementation */
137+
DPNP_FN_NEGATIVE, /**< Used in numpy.negative() implementation */
137138
DPNP_FN_NONZERO, /**< Used in numpy.nonzero() implementation */
138139
DPNP_FN_ONES, /**< Used in numpy.ones() implementation */
139140
DPNP_FN_ONES_LIKE, /**< Used in numpy.ones_like() implementation */

dpnp/backend/kernels/dpnp_krnl_elemwise.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ static void func_map_init_elemwise_1arg_1type(func_map_t& fmap)
317317
fmap[DPNPFuncName::DPNP_FN_FLATTEN][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_copy_c<double>};
318318
fmap[DPNPFuncName::DPNP_FN_FLATTEN][eft_C128][eft_C128] = {eft_C128, (void*)dpnp_copy_c<std::complex<double>>};
319319

320+
fmap[DPNPFuncName::DPNP_FN_NEGATIVE][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_negative_c<int>};
321+
fmap[DPNPFuncName::DPNP_FN_NEGATIVE][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_negative_c<long>};
322+
fmap[DPNPFuncName::DPNP_FN_NEGATIVE][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_negative_c<float>};
323+
fmap[DPNPFuncName::DPNP_FN_NEGATIVE][eft_DBL][eft_DBL] = {eft_DBL, (void*)dpnp_negative_c<double>};
324+
320325
fmap[DPNPFuncName::DPNP_FN_RECIP][eft_INT][eft_INT] = {eft_INT, (void*)dpnp_recip_c<int>};
321326
fmap[DPNPFuncName::DPNP_FN_RECIP][eft_LNG][eft_LNG] = {eft_LNG, (void*)dpnp_recip_c<long>};
322327
fmap[DPNPFuncName::DPNP_FN_RECIP][eft_FLT][eft_FLT] = {eft_FLT, (void*)dpnp_recip_c<float>};

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
107107
DPNP_FN_MINIMUM
108108
DPNP_FN_MODF
109109
DPNP_FN_MULTIPLY
110+
DPNP_FN_NEGATIVE
110111
DPNP_FN_NONZERO
111112
DPNP_FN_ONES
112113
DPNP_FN_ONES_LIKE

dpnp/dpnp_algo/dpnp_algo_mathematical.pyx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,7 @@ cpdef dpnp_nansum(dparray x1):
330330

331331

332332
cpdef dparray dpnp_negative(dparray array1):
333-
cdef dparray result = dparray(array1.shape, dtype=array1.dtype)
334-
335-
for i in range(result.size):
336-
result[i] = -(array1[i])
337-
338-
return result
333+
return call_fptr_1in_1out(DPNP_FN_NEGATIVE, array1, array1.shape)
339334

340335

341336
cpdef dparray dpnp_power(object x1_obj, object x2_obj, object dtype=None, dparray out=None, object where=True):

tests/test_mathematical.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,21 @@ def test_nancumsum(array):
197197
numpy.testing.assert_array_equal(expected, result)
198198

199199

200+
@pytest.mark.parametrize("data",
201+
[[[1., -1.], [0.1, -0.1]], [-2, -1, 0, 1, 2]],
202+
ids=['[[1., -1.], [0.1, -0.1]]', '[-2, -1, 0, 1, 2]'])
203+
@pytest.mark.parametrize("dtype",
204+
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
205+
ids=['numpy.float64', 'numpy.float32', 'numpy.int64', 'numpy.int32'])
206+
def test_negative(data, dtype):
207+
a = numpy.array(data, dtype=dtype)
208+
ia = inp.array(data, dtype=dtype)
209+
210+
result = inp.negative(ia)
211+
expected = numpy.negative(a)
212+
numpy.testing.assert_array_equal(result, expected)
213+
214+
200215
@pytest.mark.parametrize("val_type",
201216
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
202217
ids=['numpy.float64', 'numpy.float32', 'numpy.int64', 'numpy.int32'])

0 commit comments

Comments
 (0)