Skip to content

Commit 20fb928

Browse files
committed
Merge pull request opencv#16496 from andrey-golubev:unify_g_typed_kernel
2 parents 57c9991 + e569e9d commit 20fb928

File tree

2 files changed

+21
-38
lines changed

2 files changed

+21
-38
lines changed

modules/gapi/include/opencv2/gapi/gkernel.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,20 @@ class GKernelType<K, std::function<R(Args...)> >
228228
}
229229
};
230230

231+
namespace detail {
232+
// This tiny class eliminates the semantic difference between
233+
// GKernelType and GKernelTypeM.
234+
template<typename, typename> class KernelTypeMedium;
235+
236+
template<typename K, typename... R, typename... Args>
237+
class KernelTypeMedium<K, std::function<std::tuple<R...>(Args...)>> :
238+
public cv::GKernelTypeM<K, std::function<std::tuple<R...>(Args...)>> {};
239+
240+
template<typename K, typename R, typename... Args>
241+
class KernelTypeMedium<K, std::function<R(Args...)>> :
242+
public cv::GKernelType<K, std::function<R(Args...)>> {};
243+
} // namespace detail
244+
231245
} // namespace cv
232246

233247

@@ -256,12 +270,12 @@ class GKernelType<K, std::function<R(Args...)> >
256270
*
257271
* @param Class type name for this operation.
258272
* @param API an `std::function<>`-like signature for the operation;
259-
* return type is a single value.
273+
* return type is a single value or a tuple of multiple values.
260274
* @param Id string identifier for the operation. Must be unique.
261275
*/
262-
#define G_TYPED_KERNEL_HELPER(Class, API, Id) \
263-
G_ID_HELPER_BODY(Class, Id) \
264-
struct Class final: public cv::GKernelType<Class, std::function API >, \
276+
#define G_TYPED_KERNEL_HELPER(Class, API, Id) \
277+
G_ID_HELPER_BODY(Class, Id) \
278+
struct Class final: public cv::detail::KernelTypeMedium<Class, std::function API >, \
265279
public G_ID_HELPER_CLASS(Class)
266280
// {body} is to be defined by user
267281

@@ -319,10 +333,7 @@ G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8, _
319333
* return type is a tuple of multiple values.
320334
* @param Id string identifier for the operation. Must be unique.
321335
*/
322-
#define G_TYPED_KERNEL_M_HELPER(Class, API, Id) \
323-
G_ID_HELPER_BODY(Class, Id) \
324-
struct Class final: public cv::GKernelTypeM<Class, std::function API >, \
325-
public G_ID_HELPER_CLASS(Class)
336+
#define G_TYPED_KERNEL_M_HELPER G_TYPED_KERNEL_HELPER
326337
// {body} is to be defined by user
327338

328339
#define G_TYPED_KERNEL_M_HELPER_2(Class, _1, _2, Id) \
@@ -358,21 +369,10 @@ G_TYPED_KERNEL_HELPER(Class, COMBINE_SIGNATURE(_1, _2, _3, _4, _5, _6, _7, _8, _
358369
*
359370
* @param Class type name for this operation.
360371
*/
361-
#define G_TYPED_KERNEL_M(Class, ...) __WRAP_VAARGS(GET_G_TYPED_KERNEL(__VA_ARGS__, \
362-
G_TYPED_KERNEL_M_HELPER_10, \
363-
G_TYPED_KERNEL_M_HELPER_9, \
364-
G_TYPED_KERNEL_M_HELPER_8, \
365-
G_TYPED_KERNEL_M_HELPER_7, \
366-
G_TYPED_KERNEL_M_HELPER_6, \
367-
G_TYPED_KERNEL_M_HELPER_5, \
368-
G_TYPED_KERNEL_M_HELPER_4, \
369-
G_TYPED_KERNEL_M_HELPER_3, \
370-
G_TYPED_KERNEL_M_HELPER_2, \
371-
G_TYPED_KERNEL_M_HELPER)(Class, __VA_ARGS__)) \
372-
// {body} is to be defined by user
372+
#define G_TYPED_KERNEL_M G_TYPED_KERNEL
373373

374374
#define G_API_OP G_TYPED_KERNEL
375-
#define G_API_OP_M G_TYPED_KERNEL_M
375+
#define G_API_OP_M G_API_OP
376376

377377
namespace cv
378378
{

modules/gapi/include/opencv2/gapi/infer.hpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,6 @@
2323

2424
namespace cv {
2525

26-
namespace detail {
27-
// This tiny class eliminates the semantic difference between
28-
// GKernelType and GKernelTypeM.
29-
// FIXME: Something similar can be reused for regular kernels
30-
template<typename, typename>
31-
struct KernelTypeMedium;
32-
33-
template<class K, typename... R, typename... Args>
34-
struct KernelTypeMedium<K, std::function<std::tuple<R...>(Args...)> >:
35-
public GKernelTypeM<K, std::function<std::tuple<R...>(Args...)> > {};
36-
37-
template<class K, typename R, typename... Args>
38-
struct KernelTypeMedium<K, std::function<R(Args...)> >:
39-
public GKernelType<K, std::function<R(Args...)> > {};
40-
41-
} // namespace detail
42-
4326
template<typename, typename> class GNetworkType;
4427

4528
// TODO: maybe tuple_wrap_helper from util.hpp may help with this.

0 commit comments

Comments
 (0)