| 29 | namespace { |
| 30 | |
| 31 | TEST(TensorUtil, DeepCopy0d) { |
| 32 | Tensor x(DT_FLOAT, TensorShape({})); |
| 33 | x.scalar<float>()() = 10.0; |
| 34 | |
| 35 | // Make y a deep copy of x and then change it. |
| 36 | Tensor y = tensor::DeepCopy(x); |
| 37 | y.scalar<float>()() = 20.0; |
| 38 | |
| 39 | // x doesn't change |
| 40 | EXPECT_EQ(10.0, x.scalar<float>()()); |
| 41 | |
| 42 | // Change x. |
| 43 | x.scalar<float>()() = 30.0; |
| 44 | |
| 45 | // Y doesn't change. |
| 46 | EXPECT_EQ(20.0, y.scalar<float>()()); |
| 47 | |
| 48 | Tensor z = tensor::DeepCopy(y); |
| 49 | |
| 50 | // Change y. |
| 51 | y.scalar<float>()() = 40.0; |
| 52 | |
| 53 | // The final states should all be different. |
| 54 | EXPECT_EQ(20.0, z.scalar<float>()()); |
| 55 | EXPECT_EQ(30.0, x.scalar<float>()()); |
| 56 | EXPECT_EQ(40.0, y.scalar<float>()()); |
| 57 | |
| 58 | // Should have the same shape and type. |
| 59 | EXPECT_EQ(TensorShape({}), x.shape()); |
| 60 | EXPECT_EQ(TensorShape({}), y.shape()); |
| 61 | EXPECT_EQ(TensorShape({}), z.shape()); |
| 62 | |
| 63 | EXPECT_EQ(DT_FLOAT, x.dtype()); |
| 64 | EXPECT_EQ(DT_FLOAT, y.dtype()); |
| 65 | EXPECT_EQ(DT_FLOAT, z.dtype()); |
| 66 | } |
| 67 | |
| 68 | TEST(TensorUtil, DeepCopyZeroElements) { |
| 69 | Tensor x; |
nothing calls this directly
no test coverage detected