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 #include "angkor/TensorIndex.h"
19 #include <gtest/gtest.h>
21 TEST(TensorIndexTest, ctor)
23 angkor::TensorIndex index;
25 ASSERT_EQ(0, index.rank());
28 TEST(TensorIndexTest, ctor_initializer_list)
30 const angkor::TensorIndex index{1, 3, 5, 7};
32 ASSERT_EQ(4, index.rank());
34 ASSERT_EQ(1, index.at(0));
35 ASSERT_EQ(3, index.at(1));
36 ASSERT_EQ(5, index.at(2));
37 ASSERT_EQ(7, index.at(3));
40 TEST(TensorIndexTest, resize)
42 angkor::TensorIndex index;
46 ASSERT_EQ(4, index.rank());
49 TEST(TensorIndexTest, at)
51 angkor::TensorIndex index;
55 uint32_t indices[4] = {3, 5, 2, 7};
57 for (uint32_t axis = 0; axis < 4; ++axis)
59 index.at(axis) = indices[axis];
60 ASSERT_EQ(indices[axis], index.at(axis));
64 TEST(TensorIndexTest, copy)
66 const angkor::TensorIndex original{3, 5, 2, 7};
67 const angkor::TensorIndex copied{original};
69 ASSERT_EQ(copied.rank(), original.rank());
71 for (uint32_t axis = 0; axis < 4; ++axis)
73 ASSERT_EQ(copied.at(axis), original.at(axis));
77 TEST(TensorIndexTest, fill)
79 angkor::TensorIndex index{1, 6};
83 ASSERT_EQ(2, index.rank());
85 ASSERT_EQ(3, index.at(0));
86 ASSERT_EQ(3, index.at(1));