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

Method collapse

arm_compute/core/Dimensions.h:162–182  ·  view source on GitHub ↗

Collapse dimensions. * * @param[in] n Number of dimensions to collapse into @p first. * @param[in] first Dimensions into which the following @p n are collapsed. */

Source from the content-addressed store, hash-verified

160 * @param[in] first Dimensions into which the following @p n are collapsed.
161 */
162 void collapse(const size_t n, const size_t first = 0)
163 {
164 ARM_COMPUTE_ERROR_ON(first + n > _id.size());
165
166 const size_t last = std::min(_num_dimensions, first + n);
167
168 if (last > (first + 1))
169 {
170 auto it_first = _id.begin() + first;
171 auto it_last = _id.begin() + last;
172 // Collapse dimensions into the first
173 _id[first] = std::accumulate(it_first, it_last, T(1), std::multiplies<T>());
174 // Shift the remaining dimensions down
175 std::copy(it_last, _id.begin() + _num_dimensions, it_first + 1);
176 // Reduce the number of dimensions
177 const size_t old_num_dimensions = _num_dimensions;
178 _num_dimensions -= last - first - 1;
179 // Fill the now empty dimensions with zero
180 std::fill(_id.begin() + _num_dimensions, _id.begin() + old_num_dimensions, 0);
181 }
182 }
183
184 /** Collapse dimensions starting from a given point
185 *

Callers 15

compute_flatten_shapeFunction · 0.45
compute_softmax_shapeFunction · 0.45
configureMethod · 0.45
configureMethod · 0.45
run_opMethod · 0.45
configureMethod · 0.45
run_opMethod · 0.45

Calls 5

accumulateFunction · 0.85
fillFunction · 0.85
copyFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected