| 27 | namespace { |
| 28 | |
| 29 | Status ValidateVariableResourceHandle(InferenceContext* c, |
| 30 | ShapeAndType* shape_and_type) { |
| 31 | auto* handle_data = c->input_handle_shapes_and_types(0); |
| 32 | if (handle_data == nullptr || handle_data->empty()) { |
| 33 | shape_and_type->shape = c->UnknownShape(); |
| 34 | shape_and_type->dtype = DT_INVALID; |
| 35 | } else { |
| 36 | *shape_and_type = (*handle_data)[0]; |
| 37 | DataType value_dtype; |
| 38 | TF_RETURN_IF_ERROR(c->GetAttr("dtype", &value_dtype)); |
| 39 | if (shape_and_type->dtype != value_dtype) { |
| 40 | return errors::InvalidArgument( |
| 41 | "Trying to read variable with wrong dtype. " |
| 42 | "Expected ", |
| 43 | DataTypeString(shape_and_type->dtype), " got ", |
| 44 | DataTypeString(value_dtype)); |
| 45 | } |
| 46 | } |
| 47 | return Status::OK(); |
| 48 | } |
| 49 | |
| 50 | } // namesapce |
| 51 |
no test coverage detected