2 * Copyright (c) 2017, 2018 ARM Limited.
4 * SPDX-License-Identifier: MIT
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:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
37 /* Advance the iterator to the first character which is not a comment
39 * @param[in,out] fs Stream to drop comments from
41 void discard_comments(std::ifstream &fs)
43 while(fs.peek() == '#')
45 fs.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
49 /* Advance the string iterator to the next character which is neither a space or a comment
51 * @param[in,out] fs Stream to drop comments from
53 void discard_comments_and_spaces(std::ifstream &fs)
59 if(isspace(fs.peek()) == 0)
69 #ifndef BENCHMARK_EXAMPLES
70 int run_example(int argc, char **argv, Example &example)
77 example.do_setup(argc, argv);
79 example.do_teardown();
81 std::cout << "\nTest passed\n";
87 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
88 std::cerr << std::endl
89 << "ERROR " << err.what() << "(" << err.err() << ")" << std::endl;
90 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
92 #endif /* ARM_COMPUTE_CL */
93 catch(std::runtime_error &err)
95 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
96 std::cerr << std::endl
97 << "ERROR " << err.what() << " " << (errno ? strerror(errno) : "") << std::endl;
98 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
101 std::cout << "\nTest FAILED\n";
105 #endif /* BENCHMARK_EXAMPLES */
107 void draw_detection_rectangle(ITensor *tensor, const DetectionWindow &rect, uint8_t r, uint8_t g, uint8_t b)
109 ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(tensor, Format::RGB888);
111 uint8_t *top = tensor->info()->offset_element_in_bytes(Coordinates(rect.x, rect.y)) + tensor->buffer();
112 uint8_t *bottom = tensor->info()->offset_element_in_bytes(Coordinates(rect.x, rect.y + rect.height)) + tensor->buffer();
114 uint8_t *right = tensor->info()->offset_element_in_bytes(Coordinates(rect.x + rect.width, rect.y)) + tensor->buffer();
115 size_t stride = tensor->info()->strides_in_bytes()[Window::DimY];
117 for(size_t x = 0; x < rect.width; ++x)
130 for(size_t y = 0; y < rect.height; ++y)
144 std::tuple<unsigned int, unsigned int, int> parse_ppm_header(std::ifstream &fs)
146 // Check the PPM magic number is valid
147 std::array<char, 2> magic_number{ { 0 } };
148 fs >> magic_number[0] >> magic_number[1];
149 ARM_COMPUTE_ERROR_ON_MSG(magic_number[0] != 'P' || magic_number[1] != '6', "Invalid file type");
150 ARM_COMPUTE_UNUSED(magic_number);
152 discard_comments_and_spaces(fs);
154 unsigned int width = 0;
157 discard_comments_and_spaces(fs);
159 unsigned int height = 0;
162 discard_comments_and_spaces(fs);
167 discard_comments(fs);
169 ARM_COMPUTE_ERROR_ON_MSG(isspace(fs.peek()) == 0, "Invalid PPM header");
172 return std::make_tuple(width, height, max_val);
175 std::tuple<std::vector<unsigned long>, bool, std::string> parse_npy_header(std::ifstream &fs) //NOLINT
177 std::vector<unsigned long> shape; // NOLINT
180 std::string header = npy::read_header(fs);
183 bool fortran_order = false;
185 npy::parse_header(header, typestr, fortran_order, shape);
189 std::reverse(shape.begin(), shape.end());
192 return std::make_tuple(shape, fortran_order, typestr);
195 } // namespace arm_compute