MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / fill_with_generator

Method fill_with_generator

tests/AssetsLibrary.h:595–626  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

593
594template <typename T, typename ResultType>
595void AssetsLibrary::fill_with_generator(T &&tensor, const GeneratorFunctionType<ResultType> &generate_value) const
596{
597 const bool is_nhwc = tensor.data_layout() == DataLayout::NHWC;
598 TensorShape shape(tensor.shape());
599 if (is_nhwc)
600 {
601 // Ensure that the equivalent tensors will be filled for both data layouts
602 permute(shape, PermutationVector(1U, 2U, 0U));
603 }
604
605 // Iterate over all elements
606 const uint32_t num_elements = tensor.num_elements();
607 for (uint32_t element_idx = 0; element_idx < num_elements; ++element_idx)
608 {
609 Coordinates id = index2coord(shape, element_idx);
610
611 if (is_nhwc)
612 {
613 // Write in the correct id for permuted shapes
614 permute(id, PermutationVector(2U, 0U, 1U));
615 }
616
617 // Iterate over all channels
618 for (int channel = 0; channel < tensor.num_channels(); ++channel)
619 {
620 const ResultType value = generate_value();
621 ResultType &target_value = reinterpret_cast<ResultType *>(tensor(id))[channel];
622
623 store_value_with_data_type(&target_value, value, tensor.data_type());
624 }
625 }
626}
627
628template <typename T, typename D>
629void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const

Callers

nothing calls this directly

Calls 8

index2coordFunction · 0.85
permuteFunction · 0.50
data_layoutMethod · 0.45
shapeMethod · 0.45
num_elementsMethod · 0.45
num_channelsMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected