blob: e0f9c63e72770adde081c5ce79261df886be1acf [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 <boost/test/unit_test.hpp>
7#include "ParserFlatbuffersFixture.hpp"
8#include "../TfLiteParser.hpp"
9
10#include <string>
11#include <iostream>
12
13BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14
15struct 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
71struct SimpleCastFixture : CastFixture
72{
73 SimpleCastFixture() : CastFixture("[ 1, 6 ]",
74 "[ 1, 6 ]",
75 "INT32",
76 "FLOAT32") {}
77};
78
79BOOST_FIXTURE_TEST_CASE(SimpleCast, SimpleCastFixture)
80{
81RunTest<2, armnn::DataType::Signed32 , armnn::DataType::Float32>(
820,
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
88BOOST_AUTO_TEST_SUITE_END()