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

Function TestByteSwap

tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc:283–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281// Type-specific subroutine of SwapBytes test below
282template <typename T>
283void TestByteSwap(const T* forward, const T* swapped, int array_len) {
284 auto bytes_per_elem = sizeof(T);
285
286 // Convert the entire array at once
287 std::unique_ptr<T[]> forward_copy(new T[array_len]);
288 std::memcpy(forward_copy.get(), forward, array_len * bytes_per_elem);
289 TF_EXPECT_OK(ByteSwapArray(reinterpret_cast<char*>(forward_copy.get()),
290 bytes_per_elem, array_len));
291 for (int i = 0; i < array_len; i++) {
292 EXPECT_EQ(forward_copy.get()[i], swapped[i]);
293 }
294
295 // Then the array wrapped in a tensor
296 auto shape = TensorShape({array_len});
297 auto dtype = DataTypeToEnum<T>::value;
298 Tensor forward_tensor(dtype, shape);
299 Tensor swapped_tensor(dtype, shape);
300 std::memcpy(const_cast<char*>(forward_tensor.tensor_data().data()), forward,
301 array_len * bytes_per_elem);
302 std::memcpy(const_cast<char*>(swapped_tensor.tensor_data().data()), swapped,
303 array_len * bytes_per_elem);
304 TF_EXPECT_OK(ByteSwapTensor(&forward_tensor));
305 test::ExpectTensorEqual<T>(forward_tensor, swapped_tensor);
306}
307
308// Unit test of the byte-swapping operations that TensorBundle uses.
309TEST(TensorBundleTest, SwapBytes) {

Callers 1

TESTFunction · 0.85

Calls 6

ByteSwapArrayFunction · 0.85
ByteSwapTensorFunction · 0.85
tensor_dataMethod · 0.80
TensorShapeClass · 0.50
getMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected