aboutsummaryrefslogtreecommitdiff
path: root/delegate/test/BroadcastToTest.cpp
blob: 99f1a29af03ed74d1ab828a6895196c36346902b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "BroadcastToTestHelper.hpp"

#include <armnn_delegate.hpp>
#include <flatbuffers/flatbuffers.h>
#include <tensorflow/lite/interpreter.h>
#include <tensorflow/lite/kernels/register.h>
#include <tensorflow/lite/model.h>
#include <tensorflow/lite/version.h>
#include <doctest/doctest.h>

namespace armnnDelegate
{
template<typename T>
void BroadcastToTest(std::vector<armnn::BackendId> &backends, tflite::TensorType inputTensorType)
{
    // Set input data
    std::vector<T> inputValues = {
                                      0, 1, 2, 3
                                  };
    // Set output data
    std::vector<T> expectedOutputValues = {
                                               0, 1, 2, 3,
                                               0, 1, 2, 3,
                                               0, 1, 2, 3
                                           };

    // The shape data
    const std::vector<int32_t> shapeData = {3, 4};

    // Set shapes
    const std::vector<int32_t> inputShape = {1, 4};
    const std::vector<int32_t> shapeShape = {2};
    const std::vector<int32_t> expectedOutputShape = {3, 4};

    BroadcastToTestImpl<T>(inputTensorType,
                           tflite::BuiltinOperator_BROADCAST_TO,
                           inputValues,
                           inputShape,
                           shapeShape,
                           shapeData,
                           expectedOutputValues,
                           expectedOutputShape,
                           backends);
}

TEST_SUITE("BroadcastToTests_Tests")
{

    /**
     * Only CpuRef is supported for these tests.
     */
    TEST_CASE ("BroadcastTo_int_Test")
    {
        std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
        BroadcastToTest<int32_t>(backends, ::tflite::TensorType::TensorType_INT32);
    }

    TEST_CASE ("BroadcastTo_Float32_Test")
    {
        std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
        BroadcastToTest<float>(backends, ::tflite::TensorType::TensorType_FLOAT32);
    }

    TEST_CASE ("BroadcastTo_Uint8_t_Test")
    {
        std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
        BroadcastToTest<uint8_t>(backends, ::tflite::TensorType::TensorType_UINT8);
    }

    TEST_CASE ("BroadcastTo_Int8_t_Test")
    {
        std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
        BroadcastToTest<int8_t>(backends, ::tflite::TensorType::TensorType_INT8);
    }

} // TEST_SUITE("BroadcastToTests_CpuRefTests")
}