| 593 | |
| 594 | template <typename T, typename ResultType> |
| 595 | void 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 | |
| 628 | template <typename T, typename D> |
| 629 | void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const |
nothing calls this directly
no test coverage detected