| 59 | } |
| 60 | |
| 61 | TEST_F(RestoreOpTest, RestoreSimple) { |
| 62 | const string filename = io::JoinPath(testing::TmpDir(), "tensor_simple"); |
| 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_string", "tensor_complex64", |
| 67 | "tensor_half", "tensor_float_empty"}; |
| 68 | |
| 69 | // We first need to write a tensor using the save_op |
| 70 | { |
| 71 | // Initialize an operation |
| 72 | NodeDef save; |
| 73 | TF_ASSERT_OK( |
| 74 | NodeDefBuilder("myop", "Save") |
| 75 | .Input(FakeInput()) |
| 76 | .Input(FakeInput()) |
| 77 | .Input(FakeInput({DT_BOOL, DT_INT32, DT_FLOAT, DT_DOUBLE, DT_QINT8, |
| 78 | DT_QINT32, DT_UINT8, DT_INT8, DT_INT16, DT_STRING, |
| 79 | DT_COMPLEX64, DT_HALF})) |
| 80 | .Finalize(&save)); |
| 81 | |
| 82 | std::unique_ptr<Device> device( |
| 83 | DeviceFactory::NewDevice("CPU", {}, "/job:a/replica:0/task:0")); |
| 84 | |
| 85 | gtl::InlinedVector<TensorValue, 4> inputs; |
| 86 | |
| 87 | Status status; |
| 88 | std::unique_ptr<OpKernel> op(CreateOpKernel(DEVICE_CPU, device.get(), |
| 89 | cpu_allocator(), save, |
| 90 | TF_GRAPH_DEF_VERSION, &status)); |
| 91 | TF_EXPECT_OK(status); |
| 92 | |
| 93 | // Run it |
| 94 | |
| 95 | // Input #0 is the file name |
| 96 | Tensor input_0(DT_STRING, TensorShape({})); |
| 97 | input_0.scalar<tstring>()() = filename; |
| 98 | inputs.push_back({nullptr, &input_0}); |
| 99 | |
| 100 | // Input #1 is the tensor names |
| 101 | Tensor input_1 = MakeInput<tstring>( |
| 102 | TensorShape({static_cast<int>(tensor_names.size())}), |
| 103 | [&tensor_names](int x) -> string { return tensor_names[x]; }); |
| 104 | inputs.push_back({nullptr, &input_1}); |
| 105 | |
| 106 | // Input #2 is a 1-d bool tensor |
| 107 | Tensor input_2 = |
| 108 | MakeInput<bool>(TensorShape({2}), [](int x) -> bool { return x != 0; }); |
| 109 | inputs.push_back({nullptr, &input_2}); |
| 110 | // Input #3 is a 1-d integer tensor |
| 111 | Tensor input_3 = MakeInput<int32>(TensorShape({10}), |
| 112 | [](int x) -> int32 { return x + 1; }); |
| 113 | inputs.push_back({nullptr, &input_3}); |
| 114 | // Input #4 is a 2-d float tensor |
| 115 | Tensor input_4 = MakeInput<float>(TensorShape({2, 4}), [](int x) -> float { |
| 116 | return static_cast<float>(x) / 10; |
| 117 | }); |
| 118 | inputs.push_back({nullptr, &input_4}); |
nothing calls this directly
no test coverage detected