ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Shape.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright (C) 2017 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "Shape.h"
19
20#include <cstddef> // For 'size_t'
21
22bool SameShape(const Shape &in1, const Shape &in2)
23{
24 if (in1.type != in2.type || in1.dimensions.size() != in2.dimensions.size())
25 {
26 return false;
27 }
28 for (size_t i = 0; i < in1.dimensions.size(); i++)
29 {
30 if (in1.dimensions[i] != in2.dimensions[i])
31 {
32 return false;
33 }
34 }
35 return true;
36}
37
38bool SetShape(const Shape &in, Shape *out)
39{
40 if (in.type != out->type || in.dimensions.size() != out->dimensions.size())
41 {
42 return false;
43 }
44 out->dimensions = in.dimensions;
45 return true;
46}
47
48uint32_t getNumberOfElements(const Shape &shape)
49{
50 uint32_t count = 1;
51 for (size_t i = 0; i < shape.dimensions.size(); i++)
52 {
53 count *= shape.dimensions[i];
54 }
55 return count;
56}
57
58uint32_t getNumberOfDimensions(const Shape &shape) { return shape.dimensions.size(); }
59
60uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx)
61{
62 if (dimensionIdx >= shape.dimensions.size())
63 {
64 // TODO, log the error
65 return 0;
66 }
67 return shape.dimensions[dimensionIdx];
68}
uint32_t getNumberOfElements(const Shape &shape)
Definition Shape.cpp:48
bool SetShape(const Shape &in, Shape *out)
Definition Shape.cpp:38
uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx)
Definition Shape.cpp:60
bool SameShape(const Shape &in1, const Shape &in2)
Definition Shape.cpp:22
uint32_t getNumberOfDimensions(const Shape &shape)
Definition Shape.cpp:58
Definition Shape.h:28
OperandType type
Definition Shape.h:29
std::vector< uint32_t > dimensions
Definition Shape.h:30