ONE - On-device Neural Engine
Loading...
Searching...
No Matches
TensorShape.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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 __LOCO_IR_TENSOR_SHAPE_H__
18#define __LOCO_IR_TENSOR_SHAPE_H__
19
20#include "loco/IR/Dimension.h"
21
22#include <initializer_list>
23#include <vector>
24
25namespace loco
26{
27
29{
30public:
31 TensorShape() = default;
32 TensorShape(std::initializer_list<Dimension> dims) : _dims(dims.begin(), dims.end()) {}
33
34public:
35 uint32_t rank(void) const { return _dims.size(); }
36 void rank(uint32_t r) { _dims.resize(r); }
37
38 const Dimension &dim(uint32_t axis) const { return _dims.at(axis); }
39 Dimension &dim(uint32_t axis) { return _dims.at(axis); }
40
41private:
42 std::vector<Dimension> _dims;
43};
44
58uint32_t element_count(const loco::TensorShape *tensor_shape);
59
63bool operator==(const TensorShape &lhs, const TensorShape &rhs);
64
65} // namespace loco
66
67#endif // __LOCO_IR_TENSOR_SHAPE_H__
The value of one dimension in a tensor shape.
Definition Dimension.h:30
const Dimension & dim(uint32_t axis) const
Definition TensorShape.h:38
Dimension & dim(uint32_t axis)
Definition TensorShape.h:39
TensorShape(std::initializer_list< Dimension > dims)
Definition TensorShape.h:32
TensorShape()=default
void rank(uint32_t r)
Definition TensorShape.h:36
uint32_t rank(void) const
Definition TensorShape.h:35
bool operator==(const Dimension &, const Dimension &)
Equality operator between two Dimensions.
Definition Dimension.cpp:22
uint32_t element_count(const loco::TensorShape *tensor_shape)
Return the number of elements in a tensor of given shape.
int32_t begin[5]
Definition Slice.cpp:33