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

Function ByteSwapArray

tensorflow/core/util/tensor_bundle/byte_swap.cc:22–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20namespace tensorflow {
21
22Status ByteSwapArray(char* array, size_t bytes_per_elem, int array_len) {
23 if (bytes_per_elem == 1) {
24 // No-op
25 return Status::OK();
26 } else if (bytes_per_elem == 2) {
27 auto array_16 = reinterpret_cast<uint16_t*>(array);
28 for (int i = 0; i < array_len; i++) {
29 array_16[i] = BYTE_SWAP_16(array_16[i]);
30 }
31 return Status::OK();
32 } else if (bytes_per_elem == 4) {
33 auto array_32 = reinterpret_cast<uint32_t*>(array);
34 for (int i = 0; i < array_len; i++) {
35 array_32[i] = BYTE_SWAP_32(array_32[i]);
36 }
37 return Status::OK();
38 } else if (bytes_per_elem == 8) {
39 auto array_64 = reinterpret_cast<uint64_t*>(array);
40 for (int i = 0; i < array_len; i++) {
41 array_64[i] = BYTE_SWAP_64(array_64[i]);
42 }
43 return Status::OK();
44 } else {
45 return errors::Unimplemented("Byte-swapping of ", bytes_per_elem,
46 "-byte values not supported.");
47 }
48}
49
50Status ByteSwapTensor(Tensor* t) {
51 size_t bytes_per_elem = 0;

Callers 2

ByteSwapTensorFunction · 0.85
TestByteSwapFunction · 0.85

Calls 1

UnimplementedFunction · 0.85

Tested by 1

TestByteSwapFunction · 0.68