| 126 | } |
| 127 | |
| 128 | tensorflow::Status ValidateDefaultValueShape( |
| 129 | const TensorShapeProto& default_value_shape, |
| 130 | const TensorShapeProto& value_shape) { |
| 131 | if (default_value_shape.unknown_rank() || value_shape.unknown_rank()) { |
| 132 | return tensorflow::Status::OK(); |
| 133 | } |
| 134 | |
| 135 | if (default_value_shape.dim_size() > value_shape.dim_size()) { |
| 136 | // TODO(martinz): This constraint is unnecessary. The |
| 137 | // default value could have as many dimensions as shape. If there is a |
| 138 | // discrepancy, it will be picked up when we broadcast the default value. |
| 139 | // For now, I'll relax the constraint only slightly. |
| 140 | return InvalidArgument( |
| 141 | "default_value_shape must have no more dimensions than the value. " |
| 142 | "default_value_shape: ", |
| 143 | default_value_shape.DebugString(), |
| 144 | " default_value_shape.dim_size(): ", default_value_shape.dim_size(), |
| 145 | " value_shape: ", value_shape.DebugString(), |
| 146 | " value_shape.dim_size(): ", value_shape.dim_size()); |
| 147 | } |
| 148 | for (int i = 0; |
| 149 | i < std::min(default_value_shape.dim_size(), value_shape.dim_size() - 1); |
| 150 | ++i) { |
| 151 | if (default_value_shape.dim(i).size() >= 0 && |
| 152 | value_shape.dim(i + 1).size() >= 0 && |
| 153 | default_value_shape.dim(i).size() != 1 && |
| 154 | default_value_shape.dim(i).size() != value_shape.dim(i + 1).size()) { |
| 155 | return InvalidArgument( |
| 156 | "default_value_shape and value_shape do not match on dimension ", i); |
| 157 | } |
| 158 | } |
| 159 | return tensorflow::Status::OK(); |
| 160 | } |
| 161 | |
| 162 | } // namespace tensorflow |