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/kernel/Buffer.h"
18 #include "nncc/core/ADT/kernel/NCHWLayout.h"
20 #include <gtest/gtest.h>
22 using nncc::core::ADT::kernel::Shape;
23 using nncc::core::ADT::kernel::NCHWLayout;
24 using nncc::core::ADT::kernel::Buffer;
26 using nncc::core::ADT::kernel::make_buffer;
28 TEST(ADT_KERNEL_BUFFER, ctor)
30 const Shape shape{2, 4, 6, 3};
31 auto buffer = make_buffer<int, NCHWLayout>(shape);
33 ASSERT_EQ(shape.count(), buffer.shape().count());
34 ASSERT_EQ(shape.depth(), buffer.shape().depth());
35 ASSERT_EQ(shape.height(), buffer.shape().height());
36 ASSERT_EQ(shape.width(), buffer.shape().width());
39 TEST(ADT_KERNEL_BUFFER, access)
41 const Shape shape{2, 4, 6, 3};
42 auto buffer = make_buffer<int, NCHWLayout>(shape);
44 ASSERT_EQ(0, buffer.at(1, 3, 5, 2));
45 buffer.at(1, 3, 5, 2) = 4;
47 // Casting is introduced to use 'const T &at(...) const' method
48 ASSERT_EQ(4, static_cast<const Buffer<int> &>(buffer).at(1, 3, 5, 2));