From a835484557831646ff005f36b0afaa9543d2b827 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=EC=B6=98=EC=84=9D/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 22 Aug 2019 10:16:31 +0900 Subject: [PATCH] Use unsigned int for num_elements of Shape (#6507) - This fixes build break on tizen aarch64 - Assert for non-negative check Signed-off-by: Chunseok Lee --- runtimes/neurun/core/include/model/Shape.h | 2 +- runtimes/neurun/core/src/model/Shape.cc | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/runtimes/neurun/core/include/model/Shape.h b/runtimes/neurun/core/include/model/Shape.h index a1b7eed..c8d9866 100644 --- a/runtimes/neurun/core/include/model/Shape.h +++ b/runtimes/neurun/core/include/model/Shape.h @@ -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; diff --git a/runtimes/neurun/core/src/model/Shape.cc b/runtimes/neurun/core/src/model/Shape.cc index 723edb3..b7f7bff 100644 --- a/runtimes/neurun/core/src/model/Shape.cc +++ b/runtimes/neurun/core/src/model/Shape.cc @@ -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()); + // 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()); } } // namespace model -- 2.7.4