| 38 | } |
| 39 | |
| 40 | Status CheckValidPadding(Padding padding_type, |
| 41 | const std::vector<int64>& explicit_paddings, |
| 42 | int num_dims, TensorFormat data_format) { |
| 43 | if (padding_type == Padding::EXPLICIT) { |
| 44 | if (explicit_paddings.size() != 2 * num_dims) { |
| 45 | return errors::InvalidArgument( |
| 46 | "explicit_paddings attribute must contain ", 2 * num_dims, |
| 47 | " values, but got: ", explicit_paddings.size()); |
| 48 | } |
| 49 | for (int64 padding_value : explicit_paddings) { |
| 50 | if (padding_value < 0) { |
| 51 | return errors::InvalidArgument( |
| 52 | "All elements of explicit_paddings must be nonnegative"); |
| 53 | } |
| 54 | } |
| 55 | const int32 batch_index = GetTensorBatchDimIndex(num_dims, data_format); |
| 56 | const int32 depth_index = GetTensorFeatureDimIndex(num_dims, data_format); |
| 57 | if (explicit_paddings[2 * batch_index] != 0 || |
| 58 | explicit_paddings[2 * batch_index + 1] != 0 || |
| 59 | explicit_paddings[2 * depth_index] != 0 || |
| 60 | explicit_paddings[2 * depth_index + 1] != 0) { |
| 61 | return errors::InvalidArgument( |
| 62 | "Nonzero explicit padding in the batch or depth dimensions is not " |
| 63 | "supported"); |
| 64 | } |
| 65 | } else if (!explicit_paddings.empty()) { |
| 66 | return errors::InvalidArgument( |
| 67 | "explicit_paddings attribute must be empty if the padding attribute is " |
| 68 | "not EXPLICIT"); |
| 69 | } |
| 70 | return Status::OK(); |
| 71 | } |
| 72 | |
| 73 | string GetPaddingAttrString() { return "padding: {'SAME', 'VALID'}"; } |
| 74 |
no test coverage detected