Skip to content

Commit 744a3f2

Browse files
authored
Add support of logical comparison operations (#1280)
1 parent 733b32c commit 744a3f2

11 files changed

+479
-134
lines changed

dpnp/backend/include/dpnp_gen_1arg_1type_tbl.hpp

+63-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//*****************************************************************************
2-
// Copyright (c) 2016-2020, Intel Corporation
2+
// Copyright (c) 2016-2023, Intel Corporation
33
// All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
@@ -23,6 +23,8 @@
2323
// THE POSSIBILITY OF SUCH DAMAGE.
2424
//*****************************************************************************
2525

26+
#if defined(MACRO_1ARG_1TYPE_OP)
27+
2628
/*
2729
* This header file contains single argument element wise functions definitions
2830
*
@@ -35,10 +37,6 @@
3537
*
3638
*/
3739

38-
#ifndef MACRO_1ARG_1TYPE_OP
39-
#error "MACRO_1ARG_1TYPE_OP is not defined"
40-
#endif
41-
4240
#ifdef _SECTION_DOCUMENTATION_GENERATION_
4341

4442
#define MACRO_1ARG_1TYPE_OP(__name__, __operation1__, __operation2__) \
@@ -88,7 +86,7 @@
8886
const shape_elem_type* input1_strides, \
8987
const size_t* where);
9088

91-
#endif
89+
#endif // _SECTION_DOCUMENTATION_GENERATION_
9290

9391
MACRO_1ARG_1TYPE_OP(dpnp_conjugate_c, std::conj(input_elem), q.submit(kernel_func))
9492
MACRO_1ARG_1TYPE_OP(dpnp_copy_c, input_elem, q.submit(kernel_func))
@@ -107,3 +105,62 @@ MACRO_1ARG_1TYPE_OP(dpnp_square_c,
107105
oneapi::mkl::vm::sqr(q, input1_size, input1_data, result))
108106

109107
#undef MACRO_1ARG_1TYPE_OP
108+
109+
#elif defined(MACRO_1ARG_1TYPE_LOGIC_OP)
110+
111+
/*
112+
* This header file contains single argument element wise functions definitions
113+
*
114+
* Macro `MACRO_1ARG_1TYPE_LOGIC_OP` must be defined before usage
115+
*
116+
* Parameters:
117+
* - public name of the function and kernel name
118+
* - operation used to calculate the result
119+
*
120+
*/
121+
122+
#ifdef _SECTION_DOCUMENTATION_GENERATION_
123+
124+
#define MACRO_1ARG_1TYPE_LOGIC_OP(__name__, __operation__) \
125+
/** @ingroup BACKEND_API */ \
126+
/** @brief Per element operation function __name__ */ \
127+
/** */ \
128+
/** Function "__name__" executes operator "__operation__" over corresponding elements of input array */ \
129+
/** */ \
130+
/** @param[in] q_ref Reference to SYCL queue. */ \
131+
/** @param[out] result_out Output array. */ \
132+
/** @param[in] result_size Output array size. */ \
133+
/** @param[in] result_ndim Number of output array dimensions. */ \
134+
/** @param[in] result_shape Output array shape. */ \
135+
/** @param[in] result_strides Output array strides. */ \
136+
/** @param[in] input1_in Input array 1. */ \
137+
/** @param[in] input1_size Input array 1 size. */ \
138+
/** @param[in] input1_ndim Number of input array 1 dimensions. */ \
139+
/** @param[in] input1_shape Input array 1 shape. */ \
140+
/** @param[in] input1_strides Input array 1 strides. */ \
141+
/** @param[in] where Where condition. */ \
142+
/** @param[in] dep_event_vec_ref Reference to vector of SYCL events. */ \
143+
template <typename _DataType_input1> \
144+
DPCTLSyclEventRef __name__(DPCTLSyclQueueRef q_ref, \
145+
void* result_out, \
146+
const size_t result_size, \
147+
const size_t result_ndim, \
148+
const shape_elem_type* result_shape, \
149+
const shape_elem_type* result_strides, \
150+
const void* input1_in, \
151+
const size_t input1_size, \
152+
const size_t input1_ndim, \
153+
const shape_elem_type* input1_shape, \
154+
const shape_elem_type* input1_strides, \
155+
const size_t* where, \
156+
const DPCTLEventVectorRef dep_event_vec_ref);
157+
158+
#endif // _SECTION_DOCUMENTATION_GENERATION_
159+
160+
MACRO_1ARG_1TYPE_LOGIC_OP(dpnp_logical_not_c, !input1_elem)
161+
162+
#undef MACRO_1ARG_1TYPE_LOGIC_OP
163+
164+
#else
165+
#error "MACRO_1ARG_1TYPE_OP or MACRO_1ARG_1TYPE_LOGIC_OP is not defined"
166+
#endif // MACRO_1ARG_1TYPE_OP || MACRO_1ARG_1TYPE_LOGIC_OP

dpnp/backend/include/dpnp_gen_2arg_2type_tbl.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
/** @param[in] input2_strides Input array 2 strides. */ \
6565
/** @param[in] where Where condition. */ \
6666
/** @param[in] dep_event_vec_ref Reference to vector of SYCL events. */ \
67-
template <typename _DataType_output, typename _DataType_input1, typename _DataType_input2> \
67+
template <typename _DataType_input1, typename _DataType_input2> \
6868
DPCTLSyclEventRef __name__(DPCTLSyclQueueRef q_ref, \
6969
void* result_out, \
7070
const size_t result_size, \
@@ -91,6 +91,9 @@ MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_greater_c, input1_elem > input2_elem)
9191
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_greater_equal_c, input1_elem >= input2_elem)
9292
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_less_c, input1_elem < input2_elem)
9393
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_less_equal_c, input1_elem <= input2_elem)
94+
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_logical_and_c, input1_elem && input2_elem)
95+
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_logical_or_c, input1_elem || input2_elem)
96+
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_logical_xor_c, (!!input1_elem) != (!!input2_elem))
9497
MACRO_2ARG_2TYPES_LOGIC_OP(dpnp_not_equal_c, input1_elem != input2_elem)
9598

9699
#undef MACRO_2ARG_2TYPES_LOGIC_OP

dpnp/backend/include/dpnp_iface_fptr.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ enum class DPNPFuncName : size_t
205205
DPNP_FN_LOG2_EXT, /**< Used in numpy.log2() impl, requires extra parameters */
206206
DPNP_FN_LOG1P, /**< Used in numpy.log1p() impl */
207207
DPNP_FN_LOG1P_EXT, /**< Used in numpy.log1p() impl, requires extra parameters */
208+
DPNP_FN_LOGICAL_AND_EXT, /**< Used in numpy.logical_and() impl, requires extra parameters */
209+
DPNP_FN_LOGICAL_NOT_EXT, /**< Used in numpy.logical_not() impl, requires extra parameters */
210+
DPNP_FN_LOGICAL_OR_EXT, /**< Used in numpy.logical_or() impl, requires extra parameters */
211+
DPNP_FN_LOGICAL_XOR_EXT, /**< Used in numpy.logical_xor() impl, requires extra parameters */
208212
DPNP_FN_MATMUL, /**< Used in numpy.matmul() impl */
209213
DPNP_FN_MATMUL_EXT, /**< Used in numpy.matmul() impl, requires extra parameters */
210214
DPNP_FN_MATRIX_RANK, /**< Used in numpy.linalg.matrix_rank() impl */

0 commit comments

Comments
 (0)