2 * Copyright (c) 2018 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 "nncc/core/ADT/tensor/Overlay.h"
18 #include "nncc/core/ADT/tensor/LexicalLayout.h"
20 #include <gtest/gtest.h>
22 using nncc::core::ADT::tensor::Shape;
23 using nncc::core::ADT::tensor::Index;
24 using nncc::core::ADT::tensor::LexicalLayout;
25 using nncc::core::ADT::tensor::Overlay;
27 using nncc::core::ADT::tensor::make_overlay;
29 TEST(ADT_TENSOR_OVERLAY, ctor)
31 const Shape shape{2, 3};
36 auto view = make_overlay<int, LexicalLayout>(shape, data);
38 ASSERT_EQ(shape, view.shape());
41 TEST(ADT_TENSOR_OVERLAY, read)
43 const Shape shape{2, 3};
48 const auto view = make_overlay<int, LexicalLayout>(shape, data);
50 LexicalLayout layout{};
52 const Index index{1, 2};
54 ASSERT_EQ(0, data[layout.offset(shape, index)]);
55 data[layout.offset(shape, index)] = 2;
56 ASSERT_EQ(2, view.at(index));
59 TEST(ADT_TENSOR_OVERLAY, access)
61 const Shape shape{2, 3};
66 auto view = make_overlay<int, LexicalLayout>(shape, data);
68 LexicalLayout layout{};
70 const Index index{1, 2};
72 ASSERT_EQ(0, data[layout.offset(shape, index)]);
74 ASSERT_EQ(4, data[layout.offset(shape, index)]);