[neurun] Introduce asShape4D (#2626)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Thu, 6 Sep 2018 10:24:06 +0000 (19:24 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Thu, 6 Sep 2018 10:24:06 +0000 (19:24 +0900)
This commit introduces asShape4D function to convert from
`operand::Shape` to `operand::LowerInfo::Shape4D`. This is
normalization to 4D shape.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/graph/operand/Shape4DConvert.h [new file with mode: 0644]

diff --git a/runtimes/neurun/src/graph/operand/Shape4DConvert.h b/runtimes/neurun/src/graph/operand/Shape4DConvert.h
new file mode 100644 (file)
index 0000000..9c00501
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef __NEURUN_GRAPH_OPERAND_SHAPE4D_CONVERT_H__
+#define __NEURUN_GRAPH_OPERAND_SHAPE4D_CONVERT_H__
+
+#include "LowerInfo.h"
+
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+
+inline LowerInfo::Shape4D asShape4D(const Shape &shape)
+{
+  switch (shape.rank())
+  {
+    case 0u:
+      return LowerInfo::Shape4D(1, 1, 1, 1);
+
+    case 1u:
+      return LowerInfo::Shape4D(1, 1, 1, shape.dim(0));
+
+    case 2u:
+      return LowerInfo::Shape4D(1, 1, shape.dim(1), shape.dim(0));
+
+    case 3u:
+      return LowerInfo::Shape4D(1, shape.dim(2), shape.dim(1), shape.dim(0));
+
+    case 4u:
+      return LowerInfo::Shape4D(shape.dim(3), shape.dim(2), shape.dim(1), shape.dim(0));
+
+    default:
+      throw "Unsupported rank > 4";
+  }
+}
+
+} // namespace operand
+} // namespace graph
+} // namespace neurun
+
+#endif // __NEURUN_GRAPH_OPERAND_SHAPE4D_CONVERT_H__