diff options
Diffstat (limited to 'tests/AssetsLibrary.h')
-rw-r--r-- | tests/AssetsLibrary.h | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/AssetsLibrary.h b/tests/AssetsLibrary.h index 49e3a83399..9c93ee0757 100644 --- a/tests/AssetsLibrary.h +++ b/tests/AssetsLibrary.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017, 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -275,6 +275,17 @@ public: */ void fill(RawTensor &raw, const std::string &name, Format format, Channel channel) const; + /** Fills the specified @p tensor with the content of the raw tensor. + * + * @param[in, out] tensor To be filled tensor. + * @param[in] raw Raw tensor used to fill the tensor. + * + * @warning No check is performed that the specified format actually + * matches the format of the tensor. + */ + template <typename T> + void fill(T &&tensor, RawTensor raw) const; + /** Fill a tensor with uniform distribution across the range of its type * * @param[in, out] tensor To be filled tensor. @@ -475,6 +486,19 @@ void AssetsLibrary::fill(T &&tensor, const std::string &name, Format format, Cha } template <typename T> +void AssetsLibrary::fill(T &&tensor, RawTensor raw) const +{ + for(size_t offset = 0; offset < raw.size(); offset += raw.element_size()) + { + const Coordinates id = index2coord(raw.shape(), offset / raw.element_size()); + + const RawTensor::value_type *const raw_ptr = raw.data() + offset; + const auto out_ptr = static_cast<RawTensor::value_type *>(tensor(id)); + std::copy_n(raw_ptr, raw.element_size(), out_ptr); + } +} + +template <typename T> void AssetsLibrary::fill_tensor_uniform(T &&tensor, std::random_device::result_type seed_offset) const { switch(tensor.data_type()) |