2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _NDARRAY_SHAPE_H_
18 #define _NDARRAY_SHAPE_H_
32 //_dims{} here and later since array does not have std::initializer_list ctor
33 // and aggregate initialization is not allowed here
34 explicit Shape(size_t rank) noexcept : _dims{}, _rank(rank)
36 std::fill(_dims.begin(), _dims.end(), 0);
39 Shape(std::initializer_list<size_t> list) noexcept : _dims{}, _rank(list.size())
41 std::copy(list.begin(), list.end(), _dims.begin());
44 size_t dim(int i) const noexcept { return _dims.at(i); }
46 size_t &dim(int i) noexcept { return _dims.at(i); }
48 size_t element_count() const noexcept
51 for (size_t i = 0; i < rank(); ++i)
53 assert(res <= 0xffffffff);
57 size_t rank() const noexcept { return _rank; }
60 std::array<size_t, NDARRAY_MAX_DIMENSION_COUNT> _dims;
64 } // namespace ndarray
66 #endif //_NDARRAY_SHAPE_H_