| 21 | namespace paddle { |
| 22 | namespace framework { |
| 23 | TEST(DenseTensor, PrintDenseTensor) { |
| 24 | phi::DenseTensor tensor1; |
| 25 | tensor1.Resize({2}); |
| 26 | tensor1.mutable_data<float>(phi::CPUPlace()); |
| 27 | tensor1.data<float>()[0] = 0.2; |
| 28 | tensor1.data<float>()[1] = 0.5; |
| 29 | std::string res = PrintDenseTensor(&tensor1, -1, 2); |
| 30 | ASSERT_EQ(res, "access violation"); |
| 31 | res = PrintDenseTensor(&tensor1, 0, 2); |
| 32 | ASSERT_EQ(res, "0.2,0.5"); |
| 33 | |
| 34 | phi::DenseTensor tensor2; |
| 35 | tensor2.Resize({2}); |
| 36 | tensor2.mutable_data<int64_t>(phi::CPUPlace()); |
| 37 | tensor2.data<int64_t>()[0] = 1; |
| 38 | tensor2.data<int64_t>()[1] = 2; |
| 39 | res = PrintDenseTensor(&tensor2, -1, 2); |
| 40 | ASSERT_EQ(res, "access violation"); |
| 41 | res = PrintDenseTensor(&tensor2, 0, 2); |
| 42 | ASSERT_EQ(res, "1,2"); |
| 43 | |
| 44 | phi::DenseTensor tensor3; |
| 45 | tensor3.Resize({2}); |
| 46 | tensor3.mutable_data<double>(phi::CPUPlace()); |
| 47 | tensor3.data<double>()[0] = 0.1; |
| 48 | tensor3.data<double>()[1] = 0.2; |
| 49 | res = PrintDenseTensor(&tensor3, 0, 2); |
| 50 | ASSERT_EQ(res, "0.1,0.2"); |
| 51 | |
| 52 | phi::DenseTensor tensor4; |
| 53 | tensor4.Resize({2}); |
| 54 | tensor4.mutable_data<double>(phi::CPUPlace()); |
| 55 | tensor4.data<double>()[0] = 0.1; |
| 56 | tensor4.data<double>()[1] = 0.2; |
| 57 | res = ""; |
| 58 | PrintDenseTensor(&tensor4, 0, 2, res); |
| 59 | // ASSERT_EQ(res, "0.1,0.2"); |
| 60 | |
| 61 | phi::DenseTensor tensor5; |
| 62 | tensor5.Resize({2}); |
| 63 | tensor5.mutable_data<int64_t>(phi::CPUPlace()); |
| 64 | tensor5.data<int64_t>()[0] = 1; |
| 65 | tensor5.data<int64_t>()[1] = 2; |
| 66 | res = ""; |
| 67 | PrintDenseTensor(&tensor5, -1, 2, res); |
| 68 | ASSERT_EQ(res, "access violation"); |
| 69 | res = ""; |
| 70 | PrintDenseTensor(&tensor5, 0, 2, res); |
| 71 | ASSERT_EQ(res, "1,2"); |
| 72 | |
| 73 | phi::DenseTensor tensor6; |
| 74 | tensor6.Resize({2}); |
| 75 | tensor6.mutable_data<float>(phi::CPUPlace()); |
| 76 | tensor6.data<float>()[0] = 0.2; |
| 77 | tensor6.data<float>()[1] = 0.5; |
| 78 | res = ""; |
| 79 | PrintDenseTensor(&tensor6, -1, 2, res); |
| 80 | // ASSERT_EQ(res, "access violation"); |
nothing calls this directly
no test coverage detected