| 691 | } |
| 692 | |
| 693 | TEST(DirectSessionTest, KeepsStateAcrossRunsOfSession) { |
| 694 | GraphDef def; |
| 695 | Graph g(OpRegistry::Global()); |
| 696 | Node* var = test::graph::Var(&g, DT_FLOAT, TensorShape({10})); |
| 697 | var->set_assigned_device_name("/job:localhost/replica:0/task:0/cpu:0"); |
| 698 | |
| 699 | Tensor twenty(DT_FLOAT, TensorShape({10})); |
| 700 | for (int i = 0; i < 10; ++i) { |
| 701 | twenty.flat<float>()(i) = 20.0; |
| 702 | } |
| 703 | |
| 704 | Node* twenty_node = test::graph::Constant(&g, twenty); |
| 705 | twenty_node->set_assigned_device_name( |
| 706 | "/job:localhost/replica:0/task:0/cpu:0"); |
| 707 | |
| 708 | Node* init = test::graph::Assign(&g, var, twenty_node); |
| 709 | init->set_assigned_device_name("/job:localhost/replica:0/task:0/cpu:0"); |
| 710 | |
| 711 | g.ToGraphDef(&def); |
| 712 | |
| 713 | auto session = CreateSession(); |
| 714 | ASSERT_TRUE(session != nullptr); |
| 715 | TF_ASSERT_OK(session->Create(def)); |
| 716 | |
| 717 | std::vector<std::pair<string, Tensor>> inputs; |
| 718 | std::vector<Tensor> outputs; |
| 719 | |
| 720 | // Initialize the variable |
| 721 | Status s = session->Run(inputs, {init->name()}, {}, &outputs); |
| 722 | TF_ASSERT_OK(s); |
| 723 | |
| 724 | // Get the variable's data |
| 725 | s = session->Run(inputs, {var->name() + ":0"}, {}, &outputs); |
| 726 | TF_ASSERT_OK(s); |
| 727 | ASSERT_EQ(1, outputs.size()); |
| 728 | ASSERT_TRUE(outputs[0].IsInitialized()); |
| 729 | EXPECT_EQ(20.0, outputs[0].flat<float>()(0)); |
| 730 | } |
| 731 | |
| 732 | TEST(DirectSessionTest, MultipleFeedTest) { |
| 733 | GraphDef def; |
nothing calls this directly
no test coverage detected