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 "locomotiv/NodeData.h"
19 #include <nncc/core/ADT/tensor/Shape.h>
20 #include <nncc/core/ADT/tensor/Buffer.h>
21 #include <nncc/core/ADT/tensor/LexicalLayout.h>
23 #include <gtest/gtest.h>
25 using nncc::core::ADT::tensor::Index;
26 using nncc::core::ADT::tensor::Shape;
27 using nncc::core::ADT::tensor::LexicalLayout;
28 using nncc::core::ADT::tensor::make_buffer;
30 TEST(NodeData, as_s32_buffer_wrapper)
33 auto buf = make_buffer<int32_t, LexicalLayout>(shape);
34 buf.at(Index{0}) = 42;
36 auto data = locomotiv::make_data(buf);
38 ASSERT_EQ(loco::DataType::S32, data->dtype());
39 ASSERT_EQ(shape, *(data->shape()));
40 ASSERT_EQ(42, data->as_s32_bufptr()->at(Index{0}));
43 TEST(NodeData, as_f32_buffer_wrapper)
46 auto buf = make_buffer<float, LexicalLayout>(shape);
47 buf.at(Index{0}) = 3.14f;
49 auto data = locomotiv::make_data(buf);
51 ASSERT_EQ(loco::DataType::FLOAT32, data->dtype());
52 ASSERT_EQ(shape, *(data->shape()));
53 ASSERT_FLOAT_EQ(3.14f, data->as_f32_bufptr()->at(Index{0}));