ATLAS Offline Software
Loading...
Searching...
No Matches
GSFUtils Namespace Reference

Dynamic array fullfilling alignment requirements. More...

Classes

struct  AlignedDynArray
 A wrapper around std::aligned_alloc. More...
struct  Component1D
 struct representing 1D component More...
struct  Merge
 struct representing an array or the merges. More...

Typedefs

using Component1DArray = AlignedDynArray<Component1D, GSFConstants::alignment>
using MergeArray = std::vector<Merge>

Functions

MergeArray findMerges (Component1DArray &&componentsIn, const int reducedSize)
 Return which components need to be merged.

Detailed Description

Dynamic array fullfilling alignment requirements.

Author
Anthony Morley, Christos Anastopoulos

Typedef Documentation

◆ Component1DArray

◆ MergeArray

using GSFUtils::MergeArray = std::vector<Merge>

Definition at line 47 of file KLGaussianMixtureReduction.h.

Function Documentation

◆ findMerges()

MergeArray GSFUtils::findMerges ( Component1DArray && componentsIn,
const int reducedSize )

Return which components need to be merged.

Find the order in which the components need to be merged.

Returns an MergeArray with the merges (To,From). The index of the merged From is always smaller than the To (RHS is smaller than LHS)

Component1DArray : Array of simplified 1D components used to calculate the merge order using q/p.

reducedSize The size we want to reduce the mixture to. Needs to be smaller than the numComponents of the componentsIn array

Definition at line 305 of file KLGaussianMixtureReduction.cxx.

306{
307 const int n = componentsIn.size();
308 int nn = n * (n - 1) / 2;
309 int nnpadded = vAlgs::numPadded<STRIDEForKL>(nn);
310 Component1DArray components(std::move(componentsIn));
311 // Based on the inputSize n allocate enough space for the pairwise distances
312 AlignedDynArray<float, GSFConstants::alignment> distances(nnpadded, std::numeric_limits<float>::max());
313 // initial distance calculation
314 calculateAllDistances(components.buffer(), distances.buffer(), n);
315 // As we merge keep track where things moved
317 std::iota(mergingIndex.begin(), mergingIndex.end(), 0);
318 // Result to be returned
320 result.reserve(n);
321 int numberOfComponentsLeft = n;
322 // merge loop
323 while (numberOfComponentsLeft > reducedSize) {
324 // find pair with minimum distance
325 const int minIndex = KLReductionFMV::vIdxOfMin(distances.buffer(), nnpadded);
326 const triangularToIJ conversion = convert(minIndex);
327 int minTo = conversion.I;
328 int minFrom = conversion.J;
329 // This is the convention we had so retained.
330 if (mergingIndex[minTo] < mergingIndex[minFrom]) {
331 std::swap(minTo, minFrom);
332 }
333 // prepare what to return
334 const int miniToreturn = mergingIndex[minTo];
335 const int minjToreturn = mergingIndex[minFrom];
336 result.push_back({ miniToreturn, minjToreturn });
337 // Combine
338 combine(components[minTo], components[minFrom]);
339 // update distances
340 numberOfComponentsLeft = updateDistances(components.buffer(),
341 mergingIndex.buffer(),
342 distances.buffer(),
343 minFrom,
344 minTo,
345 numberOfComponentsLeft);
346
347 // number of remaining distances padded
348 nn = (numberOfComponentsLeft - 1) * numberOfComponentsLeft / 2;
349 nnpadded = numDistances(nn, distances.buffer());
350 } // end of merge while
351 return result;
352}
size_t combine(size_t lhs, size_t rhs)
Definition hash.h:21
AlignedDynArray< Component1D, GSFConstants::alignment > Component1DArray
std::vector< Merge > MergeArray
int vIdxOfMin(const float *distancesIn, int n)
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
constexpr int numPadded(const int n)
Given a number n returns a new n >= n that is padded to the required STRIDE.
A wrapper around std::aligned_alloc.
size_type size() const noexcept
number of elements/size