Skip to content

Commit 4f907e1

Browse files
committed
style: Apply clang-format for tests
Change-Id: I1632ba971cf0f42ecba07de6e3fd48ecffad461d Signed-off-by: Pablo Marquez Tello <[email protected]>
1 parent afd78dd commit 4f907e1

File tree

714 files changed

+36813
-27669
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

714 files changed

+36813
-27669
lines changed

tests/AssetsLibrary.cpp

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2020, 2023-2024 Arm Limited.
2+
* Copyright (c) 2017-2020, 2023-2025 Arm Limited.
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -23,10 +23,11 @@
2323
*/
2424
#include "tests/AssetsLibrary.h"
2525

26-
#include "Utils.h"
26+
#include "arm_compute/core/ITensor.h"
27+
2728
#include "utils/TypePrinter.h"
2829

29-
#include "arm_compute/core/ITensor.h"
30+
#include "Utils.h"
3031

3132
#pragma GCC diagnostic push
3233
#pragma GCC diagnostic ignored "-Wunused-parameter"
@@ -54,15 +55,17 @@ template <typename T, typename std::enable_if<std::is_integral<T>::value, int>::
5455
void rgb_to_luminance(const RawTensor &src, RawTensor &dst)
5556
{
5657
// Ensure in/out tensors have same image dimensions (independent of element size and number of channels)
57-
ARM_COMPUTE_ERROR_ON_MSG(src.num_elements() != dst.num_elements(), "Input and output images must have equal dimensions");
58+
ARM_COMPUTE_ERROR_ON_MSG(src.num_elements() != dst.num_elements(),
59+
"Input and output images must have equal dimensions");
5860

5961
const size_t num_elements = dst.num_elements();
6062

6163
// Currently, input is always RGB888 (3 U8 channels per element). Output can be U8, U16/S16 or U32
6264
// Note that src.data()[i] returns pointer to first channel of element[i], so RGB values have [0,1,2] offsets
63-
for(size_t i = 0, j = 0; j < num_elements; i += 3, ++j)
65+
for (size_t i = 0, j = 0; j < num_elements; i += 3, ++j)
6466
{
65-
reinterpret_cast<T *>(dst.data())[j] = 0.2126f * src.data()[i] + 0.7152f * src.data()[i + 1] + 0.0722f * src.data()[i + 2];
67+
reinterpret_cast<T *>(dst.data())[j] =
68+
0.2126f * src.data()[i] + 0.7152f * src.data()[i + 1] + 0.0722f * src.data()[i + 2];
6669
}
6770
}
6871

@@ -72,7 +75,7 @@ void extract_r_from_rgb(const RawTensor &src, RawTensor &dst)
7275

7376
const size_t num_elements = dst.num_elements();
7477

75-
for(size_t i = 0, j = 0; j < num_elements; i += 3, ++j)
78+
for (size_t i = 0, j = 0; j < num_elements; i += 3, ++j)
7679
{
7780
dst.data()[j] = src.data()[i];
7881
}
@@ -84,7 +87,7 @@ void extract_g_from_rgb(const RawTensor &src, RawTensor &dst)
8487

8588
const size_t num_elements = dst.num_elements();
8689

87-
for(size_t i = 1, j = 0; j < num_elements; i += 3, ++j)
90+
for (size_t i = 1, j = 0; j < num_elements; i += 3, ++j)
8891
{
8992
dst.data()[j] = src.data()[i];
9093
}
@@ -96,27 +99,27 @@ void extract_b_from_rgb(const RawTensor &src, RawTensor &dst)
9699

97100
const size_t num_elements = dst.num_elements();
98101

99-
for(size_t i = 2, j = 0; j < num_elements; i += 3, ++j)
102+
for (size_t i = 2, j = 0; j < num_elements; i += 3, ++j)
100103
{
101104
dst.data()[j] = src.data()[i];
102105
}
103106
}
104107

105108
void discard_comments(std::ifstream &fs)
106109
{
107-
while(fs.peek() == '#')
110+
while (fs.peek() == '#')
108111
{
109112
fs.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
110113
}
111114
}
112115

113116
void discard_comments_and_spaces(std::ifstream &fs)
114117
{
115-
while(true)
118+
while (true)
116119
{
117120
discard_comments(fs);
118121

119-
if(isspace(fs.peek()) == 0)
122+
if (isspace(fs.peek()) == 0)
120123
{
121124
break;
122125
}
@@ -128,10 +131,10 @@ void discard_comments_and_spaces(std::ifstream &fs)
128131
std::tuple<unsigned int, unsigned int, int> parse_netpbm_format_header(std::ifstream &fs, char number)
129132
{
130133
// check file type magic number is valid
131-
std::array<char, 2> magic_number{ { 0 } };
134+
std::array<char, 2> magic_number{{0}};
132135
fs >> magic_number[0] >> magic_number[1];
133136

134-
if(magic_number[0] != 'P' || magic_number[1] != number)
137+
if (magic_number[0] != 'P' || magic_number[1] != number)
135138
{
136139
throw std::runtime_error("File type magic number not supported");
137140
}
@@ -151,19 +154,19 @@ std::tuple<unsigned int, unsigned int, int> parse_netpbm_format_header(std::ifst
151154
int max_value = 0;
152155
fs >> max_value;
153156

154-
if(!fs.good())
157+
if (!fs.good())
155158
{
156159
throw std::runtime_error("Cannot read image dimensions");
157160
}
158161

159-
if(max_value != 255)
162+
if (max_value != 255)
160163
{
161164
throw std::runtime_error("RawTensor doesn't have 8-bit values");
162165
}
163166

164167
discard_comments(fs);
165168

166-
if(isspace(fs.peek()) == 0)
169+
if (isspace(fs.peek()) == 0)
167170
{
168171
throw std::runtime_error("Invalid image header");
169172
}
@@ -190,7 +193,7 @@ void check_image_size(std::ifstream &fs, size_t raw_size)
190193
const size_t end_position = fs.tellg();
191194
fs.seekg(current_position, std::ios_base::beg);
192195

193-
if((end_position - current_position) < raw_size)
196+
if ((end_position - current_position) < raw_size)
194197
{
195198
throw std::runtime_error("Not enough data in file");
196199
}
@@ -200,7 +203,7 @@ void read_image_buffer(std::ifstream &fs, RawTensor &raw)
200203
{
201204
fs.read(reinterpret_cast<std::fstream::char_type *>(raw.data()), raw.size());
202205

203-
if(!fs.good())
206+
if (!fs.good())
204207
{
205208
throw std::runtime_error("Failure while reading image buffer");
206209
}
@@ -210,7 +213,7 @@ RawTensor load_ppm(const std::string &path)
210213
{
211214
std::ifstream file(path, std::ios::in | std::ios::binary);
212215

213-
if(!file.good())
216+
if (!file.good())
214217
{
215218
throw framework::FileNotFound("Could not load PPM image: " + path);
216219
}
@@ -232,7 +235,7 @@ RawTensor load_pgm(const std::string &path)
232235
{
233236
std::ifstream file(path, std::ios::in | std::ios::binary);
234237

235-
if(!file.good())
238+
if (!file.good())
236239
{
237240
throw framework::FileNotFound("Could not load PGM image: " + path);
238241
}
@@ -252,8 +255,7 @@ RawTensor load_pgm(const std::string &path)
252255
} // namespace
253256

254257
AssetsLibrary::AssetsLibrary(std::string path, std::random_device::result_type seed) //NOLINT
255-
: _library_path(std::move(path)),
256-
_seed{ seed }
258+
: _library_path(std::move(path)), _seed{seed}
257259
{
258260
}
259261

@@ -292,15 +294,11 @@ void AssetsLibrary::fill(RawTensor &raw, const std::string &name, Format format,
292294

293295
const AssetsLibrary::Loader &AssetsLibrary::get_loader(const std::string &extension) const
294296
{
295-
static std::unordered_map<std::string, Loader> loaders =
296-
{
297-
{ "ppm", load_ppm },
298-
{ "pgm", load_pgm }
299-
};
297+
static std::unordered_map<std::string, Loader> loaders = {{"ppm", load_ppm}, {"pgm", load_pgm}};
300298

301299
const auto it = loaders.find(extension);
302300

303-
if(it != loaders.end())
301+
if (it != loaders.end())
304302
{
305303
return it->second;
306304
}
@@ -312,17 +310,15 @@ const AssetsLibrary::Loader &AssetsLibrary::get_loader(const std::string &extens
312310

313311
const AssetsLibrary::Converter &AssetsLibrary::get_converter(Format src, Format dst) const
314312
{
315-
static std::map<std::pair<Format, Format>, Converter> converters =
316-
{
317-
{ std::make_pair(Format::RGB888, Format::U8), rgb_to_luminance<uint8_t> },
318-
{ std::make_pair(Format::RGB888, Format::U16), rgb_to_luminance<uint16_t> },
319-
{ std::make_pair(Format::RGB888, Format::S16), rgb_to_luminance<int16_t> },
320-
{ std::make_pair(Format::RGB888, Format::U32), rgb_to_luminance<uint32_t> }
321-
};
313+
static std::map<std::pair<Format, Format>, Converter> converters = {
314+
{std::make_pair(Format::RGB888, Format::U8), rgb_to_luminance<uint8_t>},
315+
{std::make_pair(Format::RGB888, Format::U16), rgb_to_luminance<uint16_t>},
316+
{std::make_pair(Format::RGB888, Format::S16), rgb_to_luminance<int16_t>},
317+
{std::make_pair(Format::RGB888, Format::U32), rgb_to_luminance<uint32_t>}};
322318

323319
const auto it = converters.find(std::make_pair(src, dst));
324320

325-
if(it != converters.end())
321+
if (it != converters.end())
326322
{
327323
return it->second;
328324
}
@@ -340,7 +336,7 @@ const AssetsLibrary::Converter &AssetsLibrary::get_converter(DataType src, Forma
340336

341337
const auto it = converters.find(std::make_pair(src, dst));
342338

343-
if(it != converters.end())
339+
if (it != converters.end())
344340
{
345341
return it->second;
346342
}
@@ -358,7 +354,7 @@ const AssetsLibrary::Converter &AssetsLibrary::get_converter(DataType src, DataT
358354

359355
const auto it = converters.find(std::make_pair(src, dst));
360356

361-
if(it != converters.end())
357+
if (it != converters.end())
362358
{
363359
return it->second;
364360
}
@@ -376,7 +372,7 @@ const AssetsLibrary::Converter &AssetsLibrary::get_converter(Format src, DataTyp
376372

377373
const auto it = converters.find(std::make_pair(src, dst));
378374

379-
if(it != converters.end())
375+
if (it != converters.end())
380376
{
381377
return it->second;
382378
}
@@ -390,16 +386,14 @@ const AssetsLibrary::Converter &AssetsLibrary::get_converter(Format src, DataTyp
390386

391387
const AssetsLibrary::Extractor &AssetsLibrary::get_extractor(Format format, Channel channel) const
392388
{
393-
static std::map<std::pair<Format, Channel>, Extractor> extractors =
394-
{
395-
{ std::make_pair(Format::RGB888, Channel::R), extract_r_from_rgb },
396-
{ std::make_pair(Format::RGB888, Channel::G), extract_g_from_rgb },
397-
{ std::make_pair(Format::RGB888, Channel::B), extract_b_from_rgb }
398-
};
389+
static std::map<std::pair<Format, Channel>, Extractor> extractors = {
390+
{std::make_pair(Format::RGB888, Channel::R), extract_r_from_rgb},
391+
{std::make_pair(Format::RGB888, Channel::G), extract_g_from_rgb},
392+
{std::make_pair(Format::RGB888, Channel::B), extract_b_from_rgb}};
399393

400394
const auto it = extractors.find(std::make_pair(format, channel));
401395

402-
if(it != extractors.end())
396+
if (it != extractors.end())
403397
{
404398
return it->second;
405399
}
@@ -430,14 +424,14 @@ const RawTensor &AssetsLibrary::find_or_create_raw_tensor(const std::string &nam
430424

431425
const RawTensor *ptr = _cache.find(std::forward_as_tuple(name, format));
432426

433-
if(ptr != nullptr)
427+
if (ptr != nullptr)
434428
{
435429
return *ptr;
436430
}
437431

438432
RawTensor raw = load_image(name);
439433

440-
if(raw.format() != format)
434+
if (raw.format() != format)
441435
{
442436
//FIXME: Remove unnecessary copy
443437
RawTensor dst(raw.shape(), format);
@@ -454,7 +448,7 @@ const RawTensor &AssetsLibrary::find_or_create_raw_tensor(const std::string &nam
454448

455449
const RawTensor *ptr = _cache.find(std::forward_as_tuple(name, format, channel));
456450

457-
if(ptr != nullptr)
451+
if (ptr != nullptr)
458452
{
459453
return *ptr;
460454
}
@@ -524,7 +518,8 @@ RawTensor AssetsLibrary::get(const std::string &name, Format format, Channel cha
524518

525519
namespace detail
526520
{
527-
inline void validate_npy_header(std::ifstream &stream, const std::string &expect_typestr, const TensorShape &expect_shape)
521+
inline void
522+
validate_npy_header(std::ifstream &stream, const std::string &expect_typestr, const TensorShape &expect_shape)
528523
{
529524
ARM_COMPUTE_UNUSED(expect_typestr);
530525
ARM_COMPUTE_UNUSED(expect_shape);
@@ -543,16 +538,16 @@ inline void validate_npy_header(std::ifstream &stream, const std::string &expect
543538

544539
// Validate tensor shape
545540
ARM_COMPUTE_ERROR_ON_MSG(shape.size() != expect_shape.num_dimensions(), "Tensor ranks mismatch");
546-
if(fortran_order)
541+
if (fortran_order)
547542
{
548-
for(size_t i = 0; i < shape.size(); ++i)
543+
for (size_t i = 0; i < shape.size(); ++i)
549544
{
550545
ARM_COMPUTE_ERROR_ON_MSG(expect_shape[i] != shape[i], "Tensor dimensions mismatch");
551546
}
552547
}
553548
else
554549
{
555-
for(size_t i = 0; i < shape.size(); ++i)
550+
for (size_t i = 0; i < shape.size(); ++i)
556551
{
557552
ARM_COMPUTE_ERROR_ON_MSG(expect_shape[i] != shape[shape.size() - i - 1], "Tensor dimensions mismatch");
558553
}

0 commit comments

Comments
 (0)