If `device` is non-empty, run Min op on that device. Otherwise run it on the default device (CPU).
| 998 | // If `device` is non-empty, run Min op on that device. |
| 999 | // Otherwise run it on the default device (CPU). |
| 1000 | void RunMinTest(const string& device, bool use_XLA) { |
| 1001 | TF_Status* s = TF_NewStatus(); |
| 1002 | TF_Graph* graph = TF_NewGraph(); |
| 1003 | |
| 1004 | // Make a placeholder operation. |
| 1005 | TF_Operation* feed = Placeholder(graph, s); |
| 1006 | ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); |
| 1007 | |
| 1008 | // Make a constant operation with the scalar "0", for axis. |
| 1009 | TF_Operation* one = ScalarConst(0, graph, s); |
| 1010 | ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); |
| 1011 | |
| 1012 | // Create a session for this graph. |
| 1013 | CSession csession(graph, s, use_XLA); |
| 1014 | ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); |
| 1015 | |
| 1016 | if (!device.empty()) { |
| 1017 | LOG(INFO) << "Setting op Min on device " << device; |
| 1018 | } |
| 1019 | TF_Operation* min = MinWithDevice(feed, one, graph, device, s); |
| 1020 | ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); |
| 1021 | |
| 1022 | // Run the graph. |
| 1023 | csession.SetInputs({{feed, Int32Tensor({3, 2, 5})}}); |
| 1024 | csession.SetOutputs({min}); |
| 1025 | csession.Run(s); |
| 1026 | ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); |
| 1027 | TF_Tensor* out = csession.output_tensor(0); |
| 1028 | ASSERT_TRUE(out != nullptr); |
| 1029 | EXPECT_EQ(TF_INT32, TF_TensorType(out)); |
| 1030 | EXPECT_EQ(0, TF_NumDims(out)); // scalar |
| 1031 | ASSERT_EQ(sizeof(int32), TF_TensorByteSize(out)); |
| 1032 | int32* output_contents = static_cast<int32*>(TF_TensorData(out)); |
| 1033 | EXPECT_EQ(2, *output_contents); |
| 1034 | |
| 1035 | // Clean up |
| 1036 | csession.CloseAndDelete(s); |
| 1037 | ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); |
| 1038 | TF_DeleteGraph(graph); |
| 1039 | TF_DeleteStatus(s); |
| 1040 | } |
| 1041 | |
| 1042 | TEST(CAPI, Session_Min_CPU) { RunMinTest(/*device=*/"", /*use_XLA=*/false); } |
| 1043 |
no test coverage detected