MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TestCopies

Function TestCopies

tensorflow/core/framework/tensor_test.cc:118–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116
117template <typename T>
118void TestCopies(const Tensor& t) {
119 {
120 LOG(INFO) << "CopyFrom()";
121 Tensor t2(t.dtype());
122 EXPECT_TRUE(t2.CopyFrom(t, t.shape()));
123 test::ExpectTensorEqual<T>(t, t2);
124 }
125 {
126 LOG(INFO) << "operator=()";
127 Tensor t2(t.dtype());
128 t2 = t;
129 test::ExpectTensorEqual<T>(t, t2);
130 }
131 {
132 LOG(INFO) << "deep copy";
133 Tensor t2(t.dtype(), t.shape());
134 t2.flat<T>() = t.flat<T>();
135 test::ExpectTensorEqual<T>(t, t2);
136 }
137 {
138 LOG(INFO) << "AsProtoField()";
139 TensorProto proto;
140 t.AsProtoField(&proto);
141 Tensor t2(t.dtype());
142 EXPECT_TRUE(t2.FromProto(proto));
143 test::ExpectTensorEqual<T>(t, t2);
144 }
145 {
146 LOG(INFO) << "AsProtoTensorContent()";
147 TensorProto proto;
148 t.AsProtoTensorContent(&proto);
149 Tensor t2(t.dtype());
150 EXPECT_TRUE(t2.FromProto(proto));
151 test::ExpectTensorEqual<T>(t, t2);
152 // Make another copy via tensor_content field.
153 *proto.mutable_tensor_content() = proto.tensor_content();
154 Tensor t3(t.dtype());
155 EXPECT_TRUE(t3.FromProto(proto));
156 test::ExpectTensorEqual<T>(t, t2);
157 }
158 {
159 LOG(INFO) << "AsTensor";
160 gtl::ArraySlice<T> values(t.flat<T>().data(), t.NumElements());
161 Tensor t2 = test::AsTensor(values, t.shape());
162 test::ExpectTensorEqual<T>(t, t2);
163 }
164 {
165 LOG(INFO) << "Move constructor";
166 Tensor t2 = t;
167 Tensor t3(std::move(t2));
168 test::ExpectTensorEqual<T>(t, t3);
169 EXPECT_TRUE(t3.IsInitialized());
170 EXPECT_FALSE(t2.IsInitialized());
171 }
172 {
173 LOG(INFO) << "Move assignment";
174 Tensor t2 = t;
175 Tensor t3 = std::move(t2);

Callers

nothing calls this directly

Calls 10

AsProtoFieldMethod · 0.80
AsProtoTensorContentMethod · 0.80
AsTensorFunction · 0.70
dtypeMethod · 0.45
CopyFromMethod · 0.45
shapeMethod · 0.45
FromProtoMethod · 0.45
dataMethod · 0.45
NumElementsMethod · 0.45
IsInitializedMethod · 0.45

Tested by

no test coverage detected