From e9c2d1fc7dedf1f001c7a7efb8a37e918f918035 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 11 Sep 2018 10:17:48 +0900 Subject: [PATCH] [morph] Introduce dims.h (#1432) This commit introduces dims modulue which will include helpers for dims object creation from various shapes. The current implementation supports only a helper for tensor shape. Signed-off-by: Jonghyun Park --- contrib/morph/include/morph/dims.h | 17 +++++++++++++++++ contrib/morph/src/dims.cpp | 20 ++++++++++++++++++++ contrib/morph/src/dims.test.cpp | 16 ++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 contrib/morph/include/morph/dims.h create mode 100644 contrib/morph/src/dims.cpp create mode 100644 contrib/morph/src/dims.test.cpp diff --git a/contrib/morph/include/morph/dims.h b/contrib/morph/include/morph/dims.h new file mode 100644 index 0000000..93190d6 --- /dev/null +++ b/contrib/morph/include/morph/dims.h @@ -0,0 +1,17 @@ +#ifndef __MORPH_DIMS_H__ +#define __MORPH_DIMS_H__ + +#include + +#include + +namespace morph +{ + +template using Dims = std::vector; + +Dims as_dims(const nncc::core::ADT::tensor::Shape &); + +} // namespace morph + +#endif // __MORPH_DIMS_H__ diff --git a/contrib/morph/src/dims.cpp b/contrib/morph/src/dims.cpp new file mode 100644 index 0000000..e7db50c --- /dev/null +++ b/contrib/morph/src/dims.cpp @@ -0,0 +1,20 @@ +#include "morph/dims.h" + +using namespace nncc::core::ADT; + +namespace morph +{ + +Dims as_dims(const tensor::Shape &shape) +{ + Dims res; + + for (uint32_t n = 0; n < shape.rank(); ++n) + { + res.emplace_back(shape.dim(n)); + } + + return res; +} + +} // namespace morph diff --git a/contrib/morph/src/dims.test.cpp b/contrib/morph/src/dims.test.cpp new file mode 100644 index 0000000..5223594 --- /dev/null +++ b/contrib/morph/src/dims.test.cpp @@ -0,0 +1,16 @@ +#include "morph/dims.h" + +#include + +using namespace nncc::core::ADT; + +TEST(DimsTest, as_dims_from_tensor) +{ + auto dims = morph::as_dims(tensor::Shape{1, 3, 4, 5}); + + ASSERT_EQ(dims.size(), 4); + ASSERT_EQ(dims.at(0), 1); + ASSERT_EQ(dims.at(1), 3); + ASSERT_EQ(dims.at(2), 4); + ASSERT_EQ(dims.at(3), 5); +} -- 2.7.4