ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Index.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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#include <gtest/gtest.h>
18
19#include "mir/Shape.h"
20#include "mir/Index.h"
21
22using namespace mir;
23
24TEST(Shape, Base)
25{
26 Shape s1{3, 2};
27 ASSERT_EQ(s1.rank(), 2);
28 ASSERT_EQ(s1.dim(0), 3);
29 ASSERT_EQ(s1.dim(1), 2);
30 ASSERT_EQ(s1.dim(-1), 2);
31 ASSERT_EQ(s1.dim(-2), 3);
32 ASSERT_EQ(s1.numElements(), 6);
33
34 s1.dim(1) = 4;
35 ASSERT_EQ(s1.dim(1), 4);
36 ASSERT_EQ(s1.numElements(), 12);
37
38 Shape s2 = s1;
39 ASSERT_EQ(s1, s2);
40
41 s2.resize(1);
42 ASSERT_NE(s1, s2);
43
44 s2.resize(2);
45 s2.dim(1) = s1.dim(1);
46 ASSERT_EQ(s1, s2);
47}
48
49TEST(Index, Base)
50{
51 Index idx{3, 2};
52 ASSERT_EQ(idx.rank(), 2);
53 ASSERT_EQ(idx.at(0), 3);
54 ASSERT_EQ(idx.at(1), 2);
55 ASSERT_EQ(idx.at(-1), 2);
56 ASSERT_EQ(idx.at(-2), 3);
57
58 idx.at(1) = 4;
59 ASSERT_EQ(idx.at(1), 4);
60
61 idx.resize(1);
62 ASSERT_EQ(idx.rank(), 1);
63}
TEST(Shape, Base)
Definition Index.cpp:24
Definition Shape.h:28