Moritz Pflanzer | 3ce3ff4 | 2017-07-21 17:41:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 3 | * |
| 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 | */ |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 24 | #include "tests/validation/Helpers.h" |
Moritz Pflanzer | 3ce3ff4 | 2017-07-21 17:41:02 +0100 | [diff] [blame] | 25 | |
| 26 | namespace arm_compute |
| 27 | { |
| 28 | namespace test |
| 29 | { |
| 30 | namespace validation |
| 31 | { |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 32 | void fill_mask_from_pattern(uint8_t *mask, int cols, int rows, MatrixPattern pattern) |
| 33 | { |
| 34 | unsigned int v = 0; |
| 35 | std::mt19937 gen(library->seed()); |
| 36 | std::bernoulli_distribution dist(0.5); |
| 37 | |
| 38 | for(int r = 0; r < rows; ++r) |
| 39 | { |
| 40 | for(int c = 0; c < cols; ++c, ++v) |
| 41 | { |
| 42 | uint8_t val = 0; |
| 43 | |
| 44 | switch(pattern) |
| 45 | { |
| 46 | case MatrixPattern::BOX: |
| 47 | val = 255; |
| 48 | break; |
| 49 | case MatrixPattern::CROSS: |
| 50 | val = ((r == (rows / 2)) || (c == (cols / 2))) ? 255 : 0; |
| 51 | break; |
| 52 | case MatrixPattern::DISK: |
| 53 | val = (((r - rows / 2.0f + 0.5f) * (r - rows / 2.0f + 0.5f)) / ((rows / 2.0f) * (rows / 2.0f)) + ((c - cols / 2.0f + 0.5f) * (c - cols / 2.0f + 0.5f)) / ((cols / 2.0f) * |
| 54 | (cols / 2.0f))) <= 1.0f ? 255 : 0; |
| 55 | break; |
| 56 | case MatrixPattern::OTHER: |
| 57 | val = (dist(gen) ? 0 : 255); |
| 58 | break; |
| 59 | default: |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | mask[v] = val; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if(pattern == MatrixPattern::OTHER) |
| 68 | { |
| 69 | std::uniform_int_distribution<uint8_t> distribution_u8(0, ((cols * rows) - 1)); |
| 70 | mask[distribution_u8(gen)] = 255; |
| 71 | } |
| 72 | } |
| 73 | |
Moritz Pflanzer | 3ce3ff4 | 2017-07-21 17:41:02 +0100 | [diff] [blame] | 74 | TensorShape calculate_depth_concatenate_shape(const std::vector<TensorShape> &input_shapes) |
| 75 | { |
| 76 | ARM_COMPUTE_ERROR_ON(input_shapes.empty()); |
| 77 | |
| 78 | TensorShape out_shape = input_shapes[0]; |
| 79 | |
| 80 | size_t max_x = 0; |
| 81 | size_t max_y = 0; |
| 82 | size_t depth = 0; |
| 83 | |
| 84 | for(const auto &shape : input_shapes) |
| 85 | { |
| 86 | max_x = std::max(shape.x(), max_x); |
| 87 | max_y = std::max(shape.y(), max_y); |
| 88 | depth += shape.z(); |
| 89 | } |
| 90 | |
| 91 | out_shape.set(0, max_x); |
| 92 | out_shape.set(1, max_y); |
| 93 | out_shape.set(2, depth); |
| 94 | |
| 95 | return out_shape; |
| 96 | } |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 97 | |
| 98 | HarrisCornersParameters harris_corners_parameters() |
| 99 | { |
| 100 | HarrisCornersParameters params; |
| 101 | |
| 102 | std::mt19937 gen(library->seed()); |
| 103 | std::uniform_real_distribution<float> threshold_dist(0.f, 0.01f); |
| 104 | std::uniform_real_distribution<float> sensitivity(0.04f, 0.15f); |
| 105 | std::uniform_real_distribution<float> euclidean_distance(0.f, 30.f); |
| 106 | std::uniform_int_distribution<uint8_t> int_dist(0, 255); |
| 107 | |
| 108 | params.threshold = threshold_dist(gen); |
| 109 | params.sensitivity = sensitivity(gen); |
| 110 | params.min_dist = euclidean_distance(gen); |
| 111 | params.constant_border_value = int_dist(gen); |
| 112 | |
| 113 | return params; |
| 114 | } |
Moritz Pflanzer | 3ce3ff4 | 2017-07-21 17:41:02 +0100 | [diff] [blame] | 115 | } // namespace validation |
| 116 | } // namespace test |
| 117 | } // namespace arm_compute |