Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / compiler / souschef / include / souschef / Dims.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __SOUSCHEF_DIMS_H__
18 #define __SOUSCHEF_DIMS_H__
19
20 #include <functional>
21 #include <numeric>
22 #include <vector>
23
24 namespace souschef
25 {
26
27 template <typename T> using Dims = std::vector<T>;
28
29 template <typename SHAPETYPE> Dims<int32_t> as_dims(const SHAPETYPE &shape)
30 {
31   std::vector<int32_t> res;
32
33   for (auto &dim : shape.dim())
34   {
35     res.emplace_back(static_cast<int32_t>(dim));
36   }
37
38   return res;
39 }
40
41 int32_t element_count(const Dims<int32_t> &dims)
42 {
43   return std::accumulate(dims.begin(), dims.end(), 1, std::multiplies<int32_t>());
44 }
45
46 } // namespace souschef
47
48 #endif // __SOUSCHEF_DIMS_H__