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

Function check_border_element

tests/validation/Validation.cpp:90–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90void check_border_element(const IAccessor &tensor,
91 const Coordinates &id,
92 const BorderMode &border_mode,
93 const void *border_value,
94 int64_t &num_elements,
95 int64_t &num_mismatches)
96{
97 const size_t channel_size = element_size_from_data_type(tensor.data_type());
98 const auto ptr = static_cast<const uint8_t *>(tensor(id));
99
100 if (border_mode == BorderMode::REPLICATE)
101 {
102 Coordinates border_id{id};
103
104 if (id.x() < 0)
105 {
106 border_id.set(0, 0);
107 }
108 else if (static_cast<size_t>(id.x()) >= tensor.shape().x())
109 {
110 border_id.set(0, tensor.shape().x() - 1);
111 }
112
113 if (id.y() < 0)
114 {
115 border_id.set(1, 0);
116 }
117 else if (static_cast<size_t>(id.y()) >= tensor.shape().y())
118 {
119 border_id.set(1, tensor.shape().y() - 1);
120 }
121
122 border_value = tensor(border_id);
123 }
124
125 // Iterate over all channels within one element
126 for (int channel = 0; channel < tensor.num_channels(); ++channel)
127 {
128 const size_t channel_offset = channel * channel_size;
129 const double target = get_double_data(ptr + channel_offset, tensor.data_type());
130 const double reference =
131 get_double_data(static_cast<const uint8_t *>(border_value) + channel_offset, tensor.data_type());
132
133 if (!compare<AbsoluteTolerance<double>>(target, reference))
134 {
135 ARM_COMPUTE_TEST_INFO("id = " << id);
136 ARM_COMPUTE_TEST_INFO("channel = " << channel);
137 ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << target);
138 ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << reference);
139 ARM_COMPUTE_EXPECT_EQUAL(target, reference, framework::LogLevel::DEBUG);
140
141 ++num_mismatches;
142 }
143
144 ++num_elements;
145 }
146}
147} // namespace

Callers 1

validateFunction · 0.85

Calls 8

get_double_dataFunction · 0.85
data_typeMethod · 0.45
xMethod · 0.45
setMethod · 0.45
shapeMethod · 0.45
yMethod · 0.45
num_channelsMethod · 0.45

Tested by

no test coverage detected