| 53 | |
| 54 | template <class Shape> |
| 55 | bool TensorShapeBase<Shape>::IsValid(const TensorShapeProto& proto) { |
| 56 | // NOTE(irving): Unfortunately, TensorShape allows parsing protos with |
| 57 | // unknown_shape() set, and it seems hard to remove this without backwards |
| 58 | // compatibility issues. |
| 59 | if (kIsPartial && proto.unknown_rank()) return proto.dim_size() == 0; |
| 60 | int64 num_elements = 1; |
| 61 | if (proto.dim().size() > MaxDimensions()) return false; |
| 62 | for (const auto& d : proto.dim()) { |
| 63 | if (d.size() < (kIsPartial ? -1 : 0)) return false; |
| 64 | if (d.size() == -1) { |
| 65 | num_elements = -1; |
| 66 | } else if (!kIsPartial || num_elements >= 0) { |
| 67 | num_elements = MultiplyWithoutOverflow(num_elements, d.size()); |
| 68 | if (num_elements < 0) return false; |
| 69 | } |
| 70 | } |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | template <class Shape> |
| 75 | Status TensorShapeBase<Shape>::IsValidShape(const TensorShapeProto& proto) { |
nothing calls this directly
no test coverage detected