| 541 | |
| 542 | template <typename T, typename D> |
| 543 | void AssetsLibrary::fill_boxes(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const |
| 544 | { |
| 545 | using DistributionType = typename std::remove_reference<D>::type; |
| 546 | using ResultType = typename DistributionType::result_type; |
| 547 | |
| 548 | std::mt19937 gen(_seed + seed_offset); |
| 549 | TensorShape shape(tensor.shape()); |
| 550 | const uint32_t num_boxes = tensor.num_elements() / 4; |
| 551 | // Iterate over all elements |
| 552 | DistributionType size_dist{ResultType(0.f), ResultType(1.f)}; |
| 553 | for (uint32_t element_idx = 0; element_idx < num_boxes * 4; element_idx += 4) |
| 554 | { |
| 555 | const ResultType delta = size_dist(gen); |
| 556 | const ResultType epsilon = size_dist(gen); |
| 557 | const ResultType left = distribution(gen); |
| 558 | const ResultType top = distribution(gen); |
| 559 | const ResultType right = left + delta; |
| 560 | const ResultType bottom = top + epsilon; |
| 561 | const std::tuple<ResultType, ResultType, ResultType, ResultType> box(left, top, right, bottom); |
| 562 | Coordinates x1 = index2coord(shape, element_idx); |
| 563 | Coordinates y1 = index2coord(shape, element_idx + 1); |
| 564 | Coordinates x2 = index2coord(shape, element_idx + 2); |
| 565 | Coordinates y2 = index2coord(shape, element_idx + 3); |
| 566 | ResultType &target_value_x1 = reinterpret_cast<ResultType *>(tensor(x1))[0]; |
| 567 | ResultType &target_value_y1 = reinterpret_cast<ResultType *>(tensor(y1))[0]; |
| 568 | ResultType &target_value_x2 = reinterpret_cast<ResultType *>(tensor(x2))[0]; |
| 569 | ResultType &target_value_y2 = reinterpret_cast<ResultType *>(tensor(y2))[0]; |
| 570 | store_value_with_data_type(&target_value_x1, std::get<0>(box), tensor.data_type()); |
| 571 | store_value_with_data_type(&target_value_y1, std::get<1>(box), tensor.data_type()); |
| 572 | store_value_with_data_type(&target_value_x2, std::get<2>(box), tensor.data_type()); |
| 573 | store_value_with_data_type(&target_value_y2, std::get<3>(box), tensor.data_type()); |
| 574 | } |
| 575 | fill_borders_with_garbage(tensor, distribution, seed_offset); |
| 576 | } |
| 577 | |
| 578 | template <typename T, typename D> |
| 579 | void AssetsLibrary::fill(std::vector<T> &vec, D &&distribution, std::random_device::result_type seed_offset) const |
no test coverage detected