Nearest Neighbor

Generate random values

Write a function producing a std::vector of random float values.

TIP

Use std::uniform_real_distribution<float>(0.f, 10.f).

Find nearest neighbor

Given another random value, find the closest neighbor in the random vector and return its index in the vector.

Vectorize

Copy the code (or generalize via template) and work with simd::vec<float> instead.

Two variants:

  1. Use simd::unchecked_load(range) to load from an array of float
  2. Use std::vector<simd::vec<float>>

Which is better, if at all? When?

Benchmark

Benchmark the three variants, over different sizes of the vector

TIP

One benchmark function, benchmarking different vector sizes

void name(benchmark::State& state) {
  const std::size_t n = state.range(0);
  std::vector<float> values(n);
  // ...
}

BENCHMARK(name)->Range(8, 8 << 20);

Extend to 3-D

Go from 1-dim to three dimensional.

  1. AoS
  2. SoA
  3. AoVS

Benchmark the results

Further Reading

Data-Structure Vectorization

results matching ""

    No results matching ""