ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Dims.h
Go to the documentation of this file.
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 <cstdint>
21#include <functional>
22#include <numeric>
23#include <vector>
24
25namespace souschef
26{
27
28template <typename T> using Dims = std::vector<T>;
29
30template <typename SHAPETYPE> Dims<int32_t> as_dims(const SHAPETYPE &shape)
31{
32 std::vector<int32_t> res;
33
34 for (auto &dim : shape.dim())
35 {
36 res.emplace_back(static_cast<int32_t>(dim));
37 }
38
39 return res;
40}
41
42int32_t element_count(const Dims<int32_t> &dims)
43{
44 return std::accumulate(dims.begin(), dims.end(), 1, std::multiplies<int32_t>());
45}
46
47} // namespace souschef
48
49#endif // __SOUSCHEF_DIMS_H__
This file provides string <-> number cast helpers.
Definition Arguments.h:24
Dims< int32_t > as_dims(const SHAPETYPE &shape)
Definition Dims.h:30
int32_t element_count(const Dims< int32_t > &dims)
Definition Dims.h:42
Definition Dims.h:26