From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Tue, 17 Jul 2018 10:52:08 +0000 (+0900) Subject: [nest] Add 'Closure' class (#688) X-Git-Tag: nncc_backup~2398 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb46c25cfb29e6dff7f337920ef3c2764ff7bd9f;p=platform%2Fcore%2Fml%2Fnnfw.git [nest] Add 'Closure' class (#688) This commit adds 'Closure' class which temporarily records the domain and index expressions, which makes it easy for user to construct IR. Signed-off-by: Jonghyun Park --- diff --git a/contrib/nest/include/nest/Closure.h b/contrib/nest/include/nest/Closure.h new file mode 100644 index 0000000..e9127e6 --- /dev/null +++ b/contrib/nest/include/nest/Closure.h @@ -0,0 +1,33 @@ +#ifndef __NEST_CLOSURE_H__ +#define __NEST_CLOSURE_H__ + +#include "nest/DomainID.h" +#include "nest/Expr.h" + +namespace nest +{ + +class Closure +{ +public: + template + Closure(const DomainID &id, Args &&... indices) : _id{id}, _sub{std::forward(indices)...} + { + // DO NOTHING + } + +public: + operator Expr() const; + +public: + const DomainID &id(void) const { return _id; } + const expr::Subscript &sub(void) const { return _sub; } + +private: + DomainID const _id; + expr::Subscript const _sub; +}; + +} // namespace nest + +#endif // __NEST_CLOSURE_H__ diff --git a/contrib/nest/src/Closure.cpp b/contrib/nest/src/Closure.cpp new file mode 100644 index 0000000..151e414 --- /dev/null +++ b/contrib/nest/src/Closure.cpp @@ -0,0 +1,8 @@ +#include "nest/Closure.h" + +namespace nest +{ + +Closure::operator Expr(void) const { return std::make_shared(_id, _sub); } + +} // namespace nest diff --git a/contrib/nest/src/Closure.test.cpp b/contrib/nest/src/Closure.test.cpp new file mode 100644 index 0000000..bab8d5a --- /dev/null +++ b/contrib/nest/src/Closure.test.cpp @@ -0,0 +1,29 @@ +#include "nest/Closure.h" + +#include + +namespace +{ +struct DummyNode final : public nest::expr::Node +{ +}; +} + +TEST(Closure, ctor) +{ + nest::DomainID dom_id{0}; + nest::Closure closure{dom_id, std::make_shared()}; + + ASSERT_EQ(closure.id().value(), 0); + ASSERT_EQ(closure.sub().rank(), 1); +} + +TEST(Closure, cast) +{ + nest::DomainID dom_id{0}; + nest::Closure closure{dom_id, std::make_shared()}; + + auto check = [](const nest::Expr &e) { ASSERT_NE(e.get(), nullptr); }; + + check(closure); +}