| 58 | namespace tensorflow { |
| 59 | |
| 60 | static void SetConstOp(const string& name, std::initializer_list<int64> dims, |
| 61 | DataType data_type, NodeDef* node) { |
| 62 | Tensor tensor(data_type, TensorShape(dims)); |
| 63 | for (int64 i = 0; i < tensor.NumElements(); ++i) { |
| 64 | switch (data_type) { |
| 65 | case DT_FLOAT: |
| 66 | tensor.flat<float>()(i) = i / 10.0f; |
| 67 | break; |
| 68 | case DT_HALF: |
| 69 | tensor.flat<Eigen::half>()(i) = Eigen::half(i / 10.0f); |
| 70 | break; |
| 71 | default: |
| 72 | LOG(FATAL) << "Unknown data type " << data_type; |
| 73 | } |
| 74 | } |
| 75 | TF_CHECK_OK(NodeDefBuilder(name, "Const") |
| 76 | .Attr("dtype", data_type) |
| 77 | .Attr("value", tensor) |
| 78 | .Finalize(node)); |
| 79 | } |
| 80 | |
| 81 | static void SetConstSizesOp(const string& name, const std::vector<int32>& sizes, |
| 82 | NodeDef* node) { |
no test coverage detected