blob: a9133cd1bf912b26e31ae7850951ed391468479a [file] [log] [blame]
Matthew Sloyanc8eb9552020-11-26 10:54:22 +00001//
Teresa Charlinad1b3d72023-03-14 12:10:28 +00002// Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved.
Matthew Sloyanc8eb9552020-11-26 10:54:22 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "ElementwiseUnaryTestHelper.hpp"
7#include "LogicalTestHelper.hpp"
8
9#include <armnn_delegate.hpp>
10
11#include <flatbuffers/flatbuffers.h>
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000012
13#include <doctest/doctest.h>
14
15namespace armnnDelegate
16{
17
Colm Donelaneff204a2023-11-28 15:46:09 +000018void LogicalBinaryAndBoolTest()
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000019{
20 std::vector<int32_t> input0Shape { 1, 2, 2 };
21 std::vector<int32_t> input1Shape { 1, 2, 2 };
22 std::vector<int32_t> expectedOutputShape { 1, 2, 2 };
23
24 // Set input and output values
25 std::vector<bool> input0Values { 0, 0, 1, 1 };
26 std::vector<bool> input1Values { 0, 1, 0, 1 };
27 std::vector<bool> expectedOutputValues { 0, 0, 0, 1 };
28
Matthew Sloyanebe392d2023-03-30 10:12:08 +010029 LogicalBinaryTest(tflite::BuiltinOperator_LOGICAL_AND,
30 ::tflite::TensorType_BOOL,
Matthew Sloyanebe392d2023-03-30 10:12:08 +010031 input0Shape,
32 input1Shape,
33 expectedOutputShape,
34 input0Values,
35 input1Values,
36 expectedOutputValues);
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000037}
38
Colm Donelaneff204a2023-11-28 15:46:09 +000039void LogicalBinaryAndBroadcastTest()
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000040{
41 std::vector<int32_t> input0Shape { 1, 2, 2 };
42 std::vector<int32_t> input1Shape { 1, 1, 1 };
43 std::vector<int32_t> expectedOutputShape { 1, 2, 2 };
44
45 std::vector<bool> input0Values { 0, 1, 0, 1 };
46 std::vector<bool> input1Values { 1 };
47 std::vector<bool> expectedOutputValues { 0, 1, 0, 1 };
48
Matthew Sloyanebe392d2023-03-30 10:12:08 +010049 LogicalBinaryTest(tflite::BuiltinOperator_LOGICAL_AND,
50 ::tflite::TensorType_BOOL,
Matthew Sloyanebe392d2023-03-30 10:12:08 +010051 input0Shape,
52 input1Shape,
53 expectedOutputShape,
54 input0Values,
55 input1Values,
56 expectedOutputValues);
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000057}
58
Colm Donelaneff204a2023-11-28 15:46:09 +000059void LogicalBinaryOrBoolTest()
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000060{
61 std::vector<int32_t> input0Shape { 1, 2, 2 };
62 std::vector<int32_t> input1Shape { 1, 2, 2 };
63 std::vector<int32_t> expectedOutputShape { 1, 2, 2 };
64
65 std::vector<bool> input0Values { 0, 0, 1, 1 };
66 std::vector<bool> input1Values { 0, 1, 0, 1 };
67 std::vector<bool> expectedOutputValues { 0, 1, 1, 1 };
68
Matthew Sloyanebe392d2023-03-30 10:12:08 +010069 LogicalBinaryTest(tflite::BuiltinOperator_LOGICAL_OR,
70 ::tflite::TensorType_BOOL,
Matthew Sloyanebe392d2023-03-30 10:12:08 +010071 input0Shape,
72 input1Shape,
73 expectedOutputShape,
74 input0Values,
75 input1Values,
76 expectedOutputValues);
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000077}
78
Colm Donelaneff204a2023-11-28 15:46:09 +000079void LogicalBinaryOrBroadcastTest()
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000080{
81 std::vector<int32_t> input0Shape { 1, 2, 2 };
82 std::vector<int32_t> input1Shape { 1, 1, 1 };
83 std::vector<int32_t> expectedOutputShape { 1, 2, 2 };
84
85 std::vector<bool> input0Values { 0, 1, 0, 1 };
86 std::vector<bool> input1Values { 1 };
87 std::vector<bool> expectedOutputValues { 1, 1, 1, 1 };
88
Matthew Sloyanebe392d2023-03-30 10:12:08 +010089 LogicalBinaryTest(tflite::BuiltinOperator_LOGICAL_OR,
90 ::tflite::TensorType_BOOL,
Matthew Sloyanebe392d2023-03-30 10:12:08 +010091 input0Shape,
92 input1Shape,
93 expectedOutputShape,
94 input0Values,
95 input1Values,
96 expectedOutputValues);
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000097}
98
99// LogicalNot operator uses ElementwiseUnary unary layer and descriptor but is still classed as logical operator.
Colm Donelaneff204a2023-11-28 15:46:09 +0000100void LogicalNotBoolTest()
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000101{
102 std::vector<int32_t> inputShape { 1, 2, 2 };
103
104 std::vector<bool> inputValues { 0, 1, 0, 1 };
105 std::vector<bool> expectedOutputValues { 1, 0, 1, 0 };
106
107 ElementwiseUnaryBoolTest(tflite::BuiltinOperator_LOGICAL_NOT,
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000108 inputShape,
109 inputValues,
110 expectedOutputValues);
111}
112
Colm Donelaneff204a2023-11-28 15:46:09 +0000113TEST_SUITE("LogicalBinaryTests_Tests")
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000114{
115
Colm Donelaneff204a2023-11-28 15:46:09 +0000116TEST_CASE ("LogicalBinary_AND_Bool_Test")
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000117{
Colm Donelaneff204a2023-11-28 15:46:09 +0000118 LogicalBinaryAndBoolTest();
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000119}
120
Colm Donelaneff204a2023-11-28 15:46:09 +0000121TEST_CASE ("LogicalBinary_AND_Broadcast_Test")
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000122{
Colm Donelaneff204a2023-11-28 15:46:09 +0000123 LogicalBinaryAndBroadcastTest();
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000124}
125
Colm Donelaneff204a2023-11-28 15:46:09 +0000126TEST_CASE ("Logical_NOT_Bool_Test")
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000127{
Colm Donelaneff204a2023-11-28 15:46:09 +0000128 LogicalNotBoolTest();
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000129}
130
Colm Donelaneff204a2023-11-28 15:46:09 +0000131TEST_CASE ("LogicalBinary_OR_Bool_Test")
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000132{
Colm Donelaneff204a2023-11-28 15:46:09 +0000133 LogicalBinaryOrBoolTest();
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000134}
135
Colm Donelaneff204a2023-11-28 15:46:09 +0000136TEST_CASE ("LogicalBinary_OR_Broadcast_Test")
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000137{
Colm Donelaneff204a2023-11-28 15:46:09 +0000138 LogicalBinaryOrBroadcastTest();
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000139}
140
141}
142
143} // namespace armnnDelegate