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

Function TestEncodeDecode

tensorflow/c/c_api_test.cc:228–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226}
227
228void TestEncodeDecode(int line, const std::vector<string>& data) {
229 const tensorflow::int64 n = data.size();
230 TF_Status* status = TF_NewStatus();
231 for (const std::vector<tensorflow::int64>& dims :
232 std::vector<std::vector<tensorflow::int64>>{
233 {n}, {1, n}, {n, 1}, {n / 2, 2}}) {
234 // Create C++ Tensor
235 Tensor src(tensorflow::DT_STRING, TensorShape(dims));
236 for (tensorflow::int64 i = 0; i < src.NumElements(); ++i) {
237 src.flat<tstring>()(i) = data[i];
238 }
239 TF_Tensor* dst = TF_TensorFromTensor(src, status);
240 ASSERT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
241
242 // Convert back to a C++ Tensor and ensure we get expected output.
243 Tensor output;
244 ASSERT_EQ(Status::OK(), TF_TensorToTensor(dst, &output)) << line;
245 ASSERT_EQ(src.NumElements(), output.NumElements()) << line;
246 for (tensorflow::int64 i = 0; i < src.NumElements(); ++i) {
247 ASSERT_EQ(data[i], output.flat<tstring>()(i)) << line;
248 }
249
250 TF_DeleteTensor(dst);
251 }
252 TF_DeleteStatus(status);
253}
254
255TEST(CAPI, TensorEncodeDecodeStrings) {
256 TestEncodeDecode(__LINE__, {});

Callers 1

TESTFunction · 0.85

Calls 10

TF_NewStatusFunction · 0.85
TF_TensorFromTensorFunction · 0.85
TF_GetCodeFunction · 0.85
TF_MessageFunction · 0.85
TF_TensorToTensorFunction · 0.85
TF_DeleteTensorFunction · 0.85
TF_DeleteStatusFunction · 0.85
TensorShapeClass · 0.50
sizeMethod · 0.45
NumElementsMethod · 0.45

Tested by

no test coverage detected