| 52 | namespace { |
| 53 | |
| 54 | void InitializeTensor(DataType type, Tensor* tensor) { |
| 55 | const int period = 7; |
| 56 | if (type == DT_FLOAT) { |
| 57 | auto flat = tensor->flat<float>(); |
| 58 | // Populate numbers 0, 0.1, 0.2, ..., 0.5, 0.6, 0, 0.1, 0.2, ... |
| 59 | for (int i = 0; i < flat.size(); i++) { |
| 60 | flat(i) = static_cast<float>(i % period) / 10.0f; |
| 61 | } |
| 62 | } else if (type == DT_INT64) { |
| 63 | auto flat = tensor->flat<int64>(); |
| 64 | // Populate numbers 0, 1, 2, ..., 5, 6, 0, 1, 2, ... |
| 65 | for (int i = 0; i < flat.size(); i++) { |
| 66 | flat(i) = i % period; |
| 67 | } |
| 68 | } else if (type != DT_STRING && type != DT_RESOURCE && type != DT_VARIANT) { |
| 69 | // DT_STRING, DT_RESOURCE and DT_VARIANT are not simple types according to |
| 70 | // is_simple_type<> in tensorflow/core/framework/type_traits.h, and |
| 71 | // Allocator will run non-trivial constructor/destructor for a Tensor with |
| 72 | // one of these types, so we should not memset its buffer. |
| 73 | memset(const_cast<char*>(tensor->tensor_data().data()), 0, |
| 74 | tensor->tensor_data().size()); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // Applies the same graph pruning logic to the graph as Session.Run in TF. |
| 79 | // If the returned status is not OK, item state may be inconsistent. |
no test coverage detected