| 58 | } |
| 59 | |
| 60 | void RunTest(StringPiece save_op_to_use) { |
| 61 | const string filename = |
| 62 | io::JoinPath(testing::TmpDir(), "tensor_simple-", save_op_to_use); |
| 63 | const std::vector<string> tensor_names = { |
| 64 | "tensor_bool", "tensor_int", "tensor_float", "tensor_double", |
| 65 | "tensor_qint8", "tensor_qint32", "tensor_uint8", "tensor_int8", |
| 66 | "tensor_int16", "tensor_int64", "tensor_complex64", "tensor_half"}; |
| 67 | |
| 68 | // We first need to write using the desired save op. |
| 69 | { |
| 70 | // Initialize an operation. |
| 71 | NodeDef save; |
| 72 | if (save_op_to_use != "Save") { |
| 73 | TF_ASSERT_OK( |
| 74 | NodeDefBuilder("myop", save_op_to_use) |
| 75 | .Input(FakeInput()) // prefix |
| 76 | .Input(FakeInput()) // tensor_names |
| 77 | .Input(FakeInput()) // shape_and_slices |
| 78 | .Input(FakeInput({DT_BOOL, DT_INT32, DT_FLOAT, DT_DOUBLE, |
| 79 | DT_QINT8, DT_QINT32, DT_UINT8, DT_INT8, |
| 80 | DT_INT16, DT_COMPLEX64, DT_HALF})) // tensors |
| 81 | .Finalize(&save)); |
| 82 | } else { |
| 83 | TF_ASSERT_OK( |
| 84 | NodeDefBuilder("myop", save_op_to_use) |
| 85 | .Input(FakeInput()) // file |
| 86 | .Input(FakeInput()) // tensor_names |
| 87 | .Input(FakeInput({DT_BOOL, DT_INT32, DT_FLOAT, DT_DOUBLE, |
| 88 | DT_QINT8, DT_QINT32, DT_UINT8, DT_INT8, |
| 89 | DT_INT16, DT_COMPLEX64, DT_HALF})) // tensors |
| 90 | .Finalize(&save)); |
| 91 | } |
| 92 | |
| 93 | std::unique_ptr<Device> device( |
| 94 | DeviceFactory::NewDevice("CPU", {}, "/job:a/replica:0/task:0")); |
| 95 | |
| 96 | gtl::InlinedVector<TensorValue, 4> inputs; |
| 97 | |
| 98 | Status status; |
| 99 | std::unique_ptr<OpKernel> op( |
| 100 | CreateOpKernel(DEVICE_CPU, device.get(), cpu_allocator(), save, |
| 101 | TF_GRAPH_DEF_VERSION, &status)); |
| 102 | TF_EXPECT_OK(status); |
| 103 | |
| 104 | // Run it |
| 105 | |
| 106 | // Input #0 is the file name |
| 107 | Tensor input_0(DT_STRING, TensorShape({})); |
| 108 | input_0.scalar<tstring>()() = filename; |
| 109 | inputs.push_back({nullptr, &input_0}); |
| 110 | |
| 111 | // Input #1 is the tensor names |
| 112 | Tensor input_1 = MakeInput<tstring>( |
| 113 | TensorShape({static_cast<int>(tensor_names.size())}), |
| 114 | [&tensor_names](int x) -> string { return tensor_names[x]; }); |
| 115 | inputs.push_back({nullptr, &input_1}); |
| 116 | |
| 117 | Tensor shape_and_slices = MakeInput<tstring>( |
nothing calls this directly
no test coverage detected