| 43 | |
| 44 | template <typename ShapeLike> |
| 45 | void ValidateSampleShape( |
| 46 | int sample_index, |
| 47 | ShapeLike &&sample_shape, |
| 48 | std::optional<int> expected_ndim = std::nullopt) { |
| 49 | int ndim = std::size(sample_shape); |
| 50 | if (expected_ndim.has_value() && ndim != *expected_ndim) |
| 51 | throw std::invalid_argument(make_string( |
| 52 | "Unexpected number of dimensions (", ndim, ") in sample ", sample_index, |
| 53 | ". Expected ", *expected_ndim, ".")); |
| 54 | |
| 55 | for (int j = 0; j < ndim; j++) |
| 56 | if (sample_shape[j] < 0) |
| 57 | throw std::invalid_argument(make_string( |
| 58 | "Negative extent encountered in the shape of sample ", sample_index, ". Offending shape: ", |
| 59 | TensorShape<-1>(sample_shape))); |
| 60 | } |
| 61 | |
| 62 | inline void ValidateNumSamples(int num_samples) { |
| 63 | if (num_samples < 0) |
no test coverage detected