| 275 | // are determined based on type of the 'values' parameter. |
| 276 | template <typename Type> |
| 277 | typename std::enable_if<internal::TensorProtoHelper<Type>::value, |
| 278 | TensorProto>::type |
| 279 | CreateTensorProto(const std::vector<Type>& values, |
| 280 | const std::vector<size_t>& shape) { |
| 281 | TensorProto tensor; |
| 282 | TensorShapeProto tensor_shape_proto; |
| 283 | internal::SetTensorProtoShape(shape, &tensor_shape_proto); |
| 284 | if (TensorShape(tensor_shape_proto).num_elements() != values.size()) { |
| 285 | LOG(ERROR) << "Shape and number of values (" << values.size() |
| 286 | << ") are incompatible."; |
| 287 | return tensor; |
| 288 | } |
| 289 | using TypeHelper = internal::TensorProtoHelper<Type>; |
| 290 | tensor.set_dtype(TypeHelper::GetDataType()); |
| 291 | tensor.mutable_tensor_shape()->Swap(&tensor_shape_proto); |
| 292 | TypeHelper::AddValues(values.begin(), values.end(), &tensor); |
| 293 | return tensor; |
| 294 | } |
| 295 | |
| 296 | // Converts values in tensor to run-length encoded compressed form. |
| 297 | // |