Use unsigned int for num_elements of Shape (#6507)
author이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Thu, 22 Aug 2019 01:16:31 +0000 (10:16 +0900)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 22 Aug 2019 01:16:31 +0000 (10:16 +0900)
- This fixes build break on tizen aarch64
- Assert for non-negative check

Signed-off-by: Chunseok Lee <chunseok.lee@samsung.com>
runtimes/neurun/core/include/model/Shape.h
runtimes/neurun/core/src/model/Shape.cc

index a1b7eed..c8d9866 100644 (file)
@@ -48,7 +48,7 @@ public:
 
   int32_t &dim(int i) { return _dimensions.at(i); }
 
-  int64_t num_elements() const;
+  uint64_t num_elements() const;
 
 public:
   FeatureShape asFeature(Layout layout) const;
index 723edb3..b7f7bff 100644 (file)
@@ -72,10 +72,14 @@ void Shape::extendRank(int to_rank)
   _dimensions.insert(_dimensions.cbegin(), to_rank - rank(), 1);
 }
 
-int64_t Shape::num_elements() const
+uint64_t Shape::num_elements() const
 {
-  return std::accumulate(_dimensions.cbegin(), _dimensions.cend(), INT64_C(1),
-                         std::multiplies<int64_t>());
+  // All of the nodes must have non-negative dimension
+  assert(std::all_of(_dimensions.begin(), _dimensions.end(),
+                     [](const int32_t &v) { return (v >= 0); }));
+
+  return std::accumulate(_dimensions.cbegin(), _dimensions.cend(), UINT64_C(1),
+                         std::multiplies<uint64_t>());
 }
 
 } // namespace model