MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / prettify_tensor

Function prettify_tensor

tests/SimpleTensorPrinter.h:41–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39{
40template <typename T>
41inline std::string prettify_tensor(const SimpleTensor<T> &input,
42 const IOFormatInfo &io_fmt = IOFormatInfo{IOFormatInfo::PrintRegion::NoPadding})
43{
44 ARM_COMPUTE_ERROR_ON(input.data() == nullptr);
45
46 RawTensor tensor(std::move(SimpleTensor<T>(input)));
47
48 TensorInfo info(tensor.shape(), tensor.num_channels(), tensor.data_type());
49
50 const DataType dt = info.data_type();
51 const size_t slices2D = info.tensor_shape().total_size_upper(2);
52 const Strides strides = info.strides_in_bytes();
53 const PaddingSize padding = info.padding();
54 const size_t num_channels = info.num_channels();
55
56 std::ostringstream os;
57
58 // Set precision
59 if (is_data_type_float(dt) && (io_fmt.precision_type != IOFormatInfo::PrecisionType::Default))
60 {
61 int precision = io_fmt.precision;
62 if (io_fmt.precision_type == IOFormatInfo::PrecisionType::Full)
63 {
64 precision = std::numeric_limits<float>().max_digits10;
65 }
66 os.precision(precision);
67 }
68
69 // Define region to print
70 size_t print_width = 0;
71 size_t print_height = 0;
72 int start_offset = 0;
73 switch (io_fmt.print_region)
74 {
75 case IOFormatInfo::PrintRegion::NoPadding:
76 print_width = info.dimension(0);
77 print_height = info.dimension(1);
78 start_offset = info.offset_first_element_in_bytes();
79 break;
80 case IOFormatInfo::PrintRegion::ValidRegion:
81 print_width = info.valid_region().shape.x();
82 print_height = info.valid_region().shape.y();
83 start_offset = info.offset_element_in_bytes(
84 Coordinates(info.valid_region().anchor.x(), info.valid_region().anchor.y()));
85 break;
86 case IOFormatInfo::PrintRegion::Full:
87 print_width = padding.left + info.dimension(0) + padding.right;
88 print_height = padding.top + info.dimension(1) + padding.bottom;
89 start_offset = static_cast<int>(info.offset_first_element_in_bytes()) - padding.top * strides[1] -
90 padding.left * strides[0];
91 break;
92 default:
93 break;
94 }
95
96 print_width = print_width * num_channels;
97
98 // Set pointer to start

Callers 2

print_simpletensorFunction · 0.85

Calls 15

is_data_type_floatFunction · 0.85
total_size_upperMethod · 0.80
strMethod · 0.80
CoordinatesClass · 0.50
dataMethod · 0.45
shapeMethod · 0.45
num_channelsMethod · 0.45
data_typeMethod · 0.45
paddingMethod · 0.45
dimensionMethod · 0.45

Tested by

no test coverage detected