blob: f0beb4ed003f6de2332812b38d86b6b32bc46540 [file] [log] [blame]
Isabella Gottardi02aabcc2017-10-12 17:28:51 +01001/*
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +00002 * Copyright (c) 2017-2019 ARM Limited.
Isabella Gottardi02aabcc2017-10-12 17:28:51 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/core/Types.h"
25#include "arm_compute/runtime/Distribution1D.h"
26#include "arm_compute/runtime/NEON/functions/NEHistogram.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29#include "tests/NEON/Accessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/BorderModeDataset.h"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/HistogramFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45TEST_SUITE(NEON)
46TEST_SUITE(Histogram)
47
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +000048DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::Small2DShapes(),
Isabella Gottardi02aabcc2017-10-12 17:28:51 +010049 framework::dataset::make("DataType", DataType::U8)),
50 shape, data_type)
51{
52 // Setup Distribution
53 std::mt19937 gen(library->seed());
54 std::uniform_int_distribution<size_t> distribution_size_t(1, 30);
55 const size_t num_bins = distribution_size_t(gen);
56 std::uniform_int_distribution<int32_t> distribution_int32_t(0, 125);
57 const size_t offset = distribution_int32_t(gen);
58 std::uniform_int_distribution<uint32_t> distribution_uint32_t(1, 255 - offset);
59 const size_t range = distribution_uint32_t(gen);
60 Distribution1D distribution_dst(num_bins, offset, range);
61
62 // Create tensors
63 Tensor src = create_tensor<Tensor>(shape, data_type);
64 TensorShape dst_shape(num_bins);
65 Tensor dst = create_tensor<Tensor>(dst_shape, DataType::U32);
66
67 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
68 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
69
70 // Create and configure function
71 NEHistogram histogram;
72 histogram.configure(&src, &distribution_dst);
73
74 // Validate valid region
75 const ValidRegion valid_region = shape_to_valid_region(shape);
76 validate(src.info()->valid_region(), valid_region);
77 const ValidRegion valid_region_dst = shape_to_valid_region(dst_shape);
78 validate(dst.info()->valid_region(), valid_region_dst);
79
80 // Validate padding
81 const PaddingSize padding;
82 validate(src.info()->padding(), padding);
83 validate(dst.info()->padding(), padding);
84}
85
86template <typename T>
87using NEHistogramFixture = HistogramValidationFixture<Tensor, Accessor, NEHistogram, T, Distribution1D>;
88
89FIXTURE_DATA_TEST_CASE(RunSmall, NEHistogramFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), framework::dataset::make("DataType",
90 DataType::U8)))
91{
92 // Validate output
93 validate(Accessor(_target), _reference);
94}
95FIXTURE_DATA_TEST_CASE(RunLarge, NEHistogramFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), framework::dataset::make("DataType",
96 DataType::U8)))
97{
98 // Validate output
99 validate(Accessor(_target), _reference);
100}
101
102TEST_SUITE_END()
103TEST_SUITE_END()
104} // namespace validation
105} // namespace test
106} // namespace arm_compute