1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #14952 from smirnov-alexey:gapi_transform_macro_rework

G-API: GAPI_TRANSFORM internal functionality rework (#14952)

* Change internal pattern and substitute signatures and refactor tests

* Enhance GArrayU with type-checker function

Add a couple of new tests on GAPI_TRANSFORM
This commit is contained in:
Alexey Smirnov
2019-07-24 23:29:52 +03:00
committed by Alexander Alekhin
parent 89f23a35c5
commit 8313209704
3 changed files with 106 additions and 67 deletions
+29 -1
View File
@@ -55,6 +55,12 @@ namespace detail
class VectorRef;
using ConstructVec = std::function<void(VectorRef&)>;
// This is the base struct for GArrayU type holder
struct TypeHintBase{virtual ~TypeHintBase() = default;};
// This class holds type of initial GArray to be checked from GArrayU
template <typename T>
struct TypeHint final : public TypeHintBase{};
// This class strips type information from GArray<T> and makes it usable
// in the G-API graph compiler (expression unrolling, graph generation, etc).
@@ -64,6 +70,9 @@ namespace detail
public:
GArrayU(const GNode &n, std::size_t out); // Operation result constructor
template <typename T>
bool holds() const; // Check if was created from GArray<T>
GOrigin& priv(); // Internal use only
const GOrigin& priv() const; // Internal use only
@@ -73,7 +82,23 @@ namespace detail
void setConstructFcn(ConstructVec &&cv); // Store T-aware constructor
template <typename T>
void specifyType(); // Store type of initial GArray<T>
std::shared_ptr<GOrigin> m_priv;
std::shared_ptr<TypeHintBase> m_hint;
};
template <typename T>
bool GArrayU::holds() const{
GAPI_Assert(m_hint != nullptr);
using U = typename std::decay<T>::type;
return dynamic_cast<TypeHint<U>*>(m_hint.get()) != nullptr;
};
template <typename T>
void GArrayU::specifyType(){
m_hint.reset(new TypeHint<typename std::decay<T>::type>);
};
// This class represents a typed STL vector reference.
@@ -239,7 +264,10 @@ public:
private:
static void VCTor(detail::VectorRef& vref) { vref.reset<T>(); }
void putDetails() {m_ref.setConstructFcn(&VCTor); }
void putDetails() {
m_ref.setConstructFcn(&VCTor);
m_ref.specifyType<T>();
}
detail::GArrayU m_ref;
};
@@ -16,13 +16,16 @@
#include <opencv2/gapi/garg.hpp>
#include <opencv2/gapi/gtype_traits.hpp>
#include <opencv2/gapi/util/compiler_hints.hpp>
#include <opencv2/gapi/gcomputation.hpp>
namespace cv
{
struct GAPI_EXPORTS GTransform
{
using F = std::function<GArgs(const GArgs &)>;
// FIXME: consider another simplified
// class instead of GComputation
using F = std::function<GComputation()>;
std::string description;
F pattern;
@@ -41,20 +44,22 @@ template <typename K, typename... Ins, typename Out>
struct TransHelper<K, std::tuple<Ins...>, Out>
{
template <typename Callable, int... IIs, int... OIs>
static GArgs invoke(Callable f, const GArgs &in_args, Seq<IIs...>, Seq<OIs...>)
static GComputation invoke(Callable f, Seq<IIs...>, Seq<OIs...>)
{
const auto r = tuple_wrap_helper<Out>::get(f(in_args.at(IIs).template get<Ins>()...));
return GArgs{GArg(std::get<OIs>(r))...};
const std::tuple<Ins...> ins;
const auto r = tuple_wrap_helper<Out>::get(f(std::get<IIs>(ins)...));
return GComputation(cv::GIn(std::get<IIs>(ins)...),
cv::GOut(std::get<OIs>(r)...));
}
static GArgs get_pattern(const GArgs &in_args)
static GComputation get_pattern()
{
return invoke(K::pattern, in_args, typename MkSeq<sizeof...(Ins)>::type(),
return invoke(K::pattern, typename MkSeq<sizeof...(Ins)>::type(),
typename MkSeq<std::tuple_size<typename tuple_wrap_helper<Out>::type>::value>::type());
}
static GArgs get_substitute(const GArgs &in_args)
static GComputation get_substitute()
{
return invoke(K::substitute, in_args, typename MkSeq<sizeof...(Ins)>::type(),
return invoke(K::substitute, typename MkSeq<sizeof...(Ins)>::type(),
typename MkSeq<std::tuple_size<typename tuple_wrap_helper<Out>::type>::value>::type());
}
};