ArmNN
 21.05
Cast.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <boost/test/unit_test.hpp>
8 #include "../TfLiteParser.hpp"
9 
10 #include <string>
11 #include <iostream>
12 
13 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14 
15 struct CastFixture : public ParserFlatbuffersFixture
16 {
17  explicit CastFixture(const std::string& inputShape,
18  const std::string& outputShape,
19  const std::string& inputDataType,
20  const std::string& outputDataType)
21  {
22  m_JsonString = R"(
23  {
24  "version": 3,
25  "operator_codes": [ { "builtin_code": "CAST" } ],
26  "subgraphs": [ {
27  "tensors": [
28  {
29  "shape": )" + inputShape + R"(,
30  "type": )" + inputDataType + R"(,
31  "buffer": 0,
32  "name": "inputTensor",
33  "quantization": {
34  "min": [ 0.0 ],
35  "max": [ 255.0 ],
36  "scale": [ 1.0 ],
37  "zero_point": [ 0 ],
38  }
39  },
40  {
41  "shape": )" + outputShape + R"(,
42  "type": )" + outputDataType + R"(,
43  "buffer": 1,
44  "name": "outputTensor",
45  "quantization": {
46  "min": [ 0.0 ],
47  "max": [ 255.0 ],
48  "scale": [ 1.0 ],
49  "zero_point": [ 0 ],
50  }
51  }
52  ],
53  "inputs": [ 0 ],
54  "outputs": [ 1 ],
55  "operators": [
56  {
57  "opcode_index": 0,
58  "inputs": [ 0 ],
59  "outputs": [ 1 ],
60  "custom_options_format": "FLEXBUFFERS"
61  }
62  ],
63  } ],
64  "buffers" : [ {}, {} ]
65  }
66  )";
67  SetupSingleInputSingleOutput("inputTensor", "outputTensor");
68  }
69 };
70 
71 struct SimpleCastFixture : CastFixture
72 {
73  SimpleCastFixture() : CastFixture("[ 1, 6 ]",
74  "[ 1, 6 ]",
75  "INT32",
76  "FLOAT32") {}
77 };
78 
79 BOOST_FIXTURE_TEST_CASE(SimpleCast, SimpleCastFixture)
80 {
81 RunTest<2, armnn::DataType::Signed32 , armnn::DataType::Float32>(
82 0,
83 {{"inputTensor", { 0, -1, 5, -100, 200, -255 }}},
84 {{"outputTensor", { 0.0f, -1.0f, 5.0f, -100.0f, 200.0f, -255.0f }}});
85 }
86 
87 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_FIXTURE_TEST_CASE(SimpleCast, SimpleCastFixture)
Definition: Cast.cpp:79
BOOST_AUTO_TEST_SUITE_END()
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)