blob: d9763150f7e436ebb7dd1fd0647de0156a8e516a [file] [log] [blame]
mathad01b392e982021-04-07 12:07:30 +01001//
2// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ParserFlatbuffersSerializeFixture.hpp"
7#include <armnnDeserializer/IDeserializer.hpp>
8
Colm Donelanc42a9872022-02-02 16:35:09 +00009#include <armnnUtils/QuantizeHelper.hpp>
mathad01b392e982021-04-07 12:07:30 +010010#include <ResolveType.hpp>
11
mathad01b392e982021-04-07 12:07:30 +010012#include <string>
13
Sadik Armagan1625efc2021-06-10 18:24:34 +010014TEST_SUITE("Deserializer_Cast")
15{
mathad01b392e982021-04-07 12:07:30 +010016struct CastFixture : public ParserFlatbuffersSerializeFixture
17{
18 explicit CastFixture(const std::string& inputShape,
19 const std::string& outputShape,
20 const std::string& inputDataType,
21 const std::string& outputDataType)
22 {
23 m_JsonString = R"(
24 {
25 inputIds: [0],
26 outputIds: [2],
27 layers: [
28 {
29 layer_type: "InputLayer",
30 layer: {
31 base: {
32 layerBindingId: 0,
33 base: {
34 index: 0,
35 layerName: "inputTensor",
36 layerType: "Input",
37 inputSlots: [{
38 index: 0,
39 connection: { sourceLayerIndex:0, outputSlotIndex:0 },
40 }],
41 outputSlots: [{
42 index: 0,
43 tensorInfo: {
44 dimensions: )" + inputShape + R"(,
45 dataType: )" + inputDataType + R"(
46 }
47 }]
48 }
49 }
50 }
51 },
52 {
53 layer_type: "CastLayer",
54 layer: {
55 base: {
56 index:1,
57 layerName: "CastLayer",
58 layerType: "Cast",
59 inputSlots: [{
60 index: 0,
61 connection: { sourceLayerIndex:0, outputSlotIndex:0 },
62 }],
63 outputSlots: [{
64 index: 0,
65 tensorInfo: {
66 dimensions: )" + outputShape + R"(,
67 dataType: )" + outputDataType + R"(
68 },
69 }],
70 },
71 },
72 },
73 {
74 layer_type: "OutputLayer",
75 layer: {
76 base:{
77 layerBindingId: 2,
78 base: {
79 index: 2,
80 layerName: "outputTensor",
81 layerType: "Output",
82 inputSlots: [{
83 index: 0,
84 connection: { sourceLayerIndex:1, outputSlotIndex:0 },
85 }],
86 outputSlots: [{
87 index: 0,
88 tensorInfo: {
89 dimensions: )" + outputShape + R"(,
90 dataType: )" + outputDataType + R"(
91 },
92 }],
93 }
94 }
95 },
96 }
97 ]
98 }
99 )";
100 Setup();
101 }
102};
103
104struct SimpleCastFixture : CastFixture
105{
106 SimpleCastFixture() : CastFixture("[ 1, 6 ]",
107 "[ 1, 6 ]",
108 "Signed32",
109 "Float32") {}
110};
111
Sadik Armagan1625efc2021-06-10 18:24:34 +0100112TEST_CASE_FIXTURE(SimpleCastFixture, "SimpleCast")
mathad01b392e982021-04-07 12:07:30 +0100113{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100114 RunTest<2, armnn::DataType::Signed32 , armnn::DataType::Float32>(
115 0,
116 {{"inputTensor", { 0, -1, 5, -100, 200, -255 }}},
117 {{"outputTensor", { 0.0f, -1.0f, 5.0f, -100.0f, 200.0f, -255.0f }}});
mathad01b392e982021-04-07 12:07:30 +0100118}
119
Sadik Armagan1625efc2021-06-10 18:24:34 +0100120}