@{ */ * Append this TensorListShape with shapes from other TensorListShapes. */
| 714 | * Append this TensorListShape with shapes from other TensorListShapes. |
| 715 | */ |
| 716 | void append(span<const TensorListShape<sample_ndim>> tlss) { |
| 717 | int new_samples = 0; |
| 718 | for (const auto &tls : tlss) { |
| 719 | new_samples += tls.num_samples(); |
| 720 | } |
| 721 | if (new_samples == 0) return; |
| 722 | |
| 723 | // The following line is imperfect, because uninitialized TensorListShape<-1> |
| 724 | // has `ndim` == 0, while `0` is legal number of dimensions. |
| 725 | bool is_uninitialized = empty() && sample_dim() <= 0; |
| 726 | |
| 727 | auto reference_dim_value = is_uninitialized ? tlss[0].sample_dim() : sample_dim(); |
| 728 | for (const auto &tls : tlss) { |
| 729 | if (tls.sample_dim() != reference_dim_value) { |
| 730 | throw std::invalid_argument( |
| 731 | "All samples in TensorListShape must have the same number of dimensions"); |
| 732 | } |
| 733 | } |
| 734 | nsamples += new_samples; |
| 735 | if (is_uninitialized) { |
| 736 | // If `this` TLS has DynamicDimensions and wasn't initialized yet |
| 737 | set_sample_dim(reference_dim_value); |
| 738 | } |
| 739 | shapes.reserve(nsamples * sample_dim()); |
| 740 | for (const auto &tls : tlss) { |
| 741 | shapes.insert(shapes.end(), tls.shapes.begin(), tls.shapes.end()); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | void append(const TensorListShape<sample_ndim> &tls) { |
| 746 | append(make_cspan(&tls, 1)); |
nothing calls this directly
no test coverage detected