blob: 9971ee867b4ba5e5bb4f93a1d110ff100bfdb4cd [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
mathad01b392e982021-04-07 12:07:30 +01006#include "ParserFlatbuffersFixture.hpp"
7#include "../TfLiteParser.hpp"
8
9#include <string>
10#include <iostream>
11
Sadik Armagan1625efc2021-06-10 18:24:34 +010012TEST_SUITE("TensorflowLiteParser_Cast")
13{
mathad01b392e982021-04-07 12:07:30 +010014struct CastFixture : public ParserFlatbuffersFixture
15{
16 explicit CastFixture(const std::string& inputShape,
17 const std::string& outputShape,
18 const std::string& inputDataType,
19 const std::string& outputDataType)
20 {
21 m_JsonString = R"(
22 {
23 "version": 3,
24 "operator_codes": [ { "builtin_code": "CAST" } ],
25 "subgraphs": [ {
26 "tensors": [
27 {
28 "shape": )" + inputShape + R"(,
29 "type": )" + inputDataType + R"(,
30 "buffer": 0,
31 "name": "inputTensor",
32 "quantization": {
33 "min": [ 0.0 ],
34 "max": [ 255.0 ],
35 "scale": [ 1.0 ],
36 "zero_point": [ 0 ],
37 }
38 },
39 {
40 "shape": )" + outputShape + R"(,
41 "type": )" + outputDataType + R"(,
42 "buffer": 1,
43 "name": "outputTensor",
44 "quantization": {
45 "min": [ 0.0 ],
46 "max": [ 255.0 ],
47 "scale": [ 1.0 ],
48 "zero_point": [ 0 ],
49 }
50 }
51 ],
52 "inputs": [ 0 ],
53 "outputs": [ 1 ],
54 "operators": [
55 {
56 "opcode_index": 0,
57 "inputs": [ 0 ],
58 "outputs": [ 1 ],
59 "custom_options_format": "FLEXBUFFERS"
60 }
61 ],
62 } ],
63 "buffers" : [ {}, {} ]
64 }
65 )";
66 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
67 }
68};
69
70struct SimpleCastFixture : CastFixture
71{
72 SimpleCastFixture() : CastFixture("[ 1, 6 ]",
73 "[ 1, 6 ]",
74 "INT32",
75 "FLOAT32") {}
76};
77
Sadik Armagan1625efc2021-06-10 18:24:34 +010078TEST_CASE_FIXTURE(SimpleCastFixture, "SimpleCast")
mathad01b392e982021-04-07 12:07:30 +010079{
80RunTest<2, armnn::DataType::Signed32 , armnn::DataType::Float32>(
810,
82{{"inputTensor", { 0, -1, 5, -100, 200, -255 }}},
83{{"outputTensor", { 0.0f, -1.0f, 5.0f, -100.0f, 200.0f, -255.0f }}});
84}
85
Sadik Armagan1625efc2021-06-10 18:24:34 +010086}