diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-02-25 14:11:00 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-02-25 14:12:03 +0000 |
commit | 44fef3325d3e9bfa673d71b87721f0979f8404c8 (patch) | |
tree | 7f67a2fe14362cd0b31daf75333cad1e1ea83035 /eval/src/tests/ann/point-vector.h | |
parent | cc3c709d6278ebd699d4f4c67f8f769c9b6fa177 (diff) |
split out common subroutines
Diffstat (limited to 'eval/src/tests/ann/point-vector.h')
-rw-r--r-- | eval/src/tests/ann/point-vector.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/eval/src/tests/ann/point-vector.h b/eval/src/tests/ann/point-vector.h new file mode 100644 index 00000000000..eca60e11194 --- /dev/null +++ b/eval/src/tests/ann/point-vector.h @@ -0,0 +1,30 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +struct PointVector { + float v[NUM_DIMS]; + using ConstArr = vespalib::ConstArrayRef<float>; + operator ConstArr() const { return ConstArr(v, NUM_DIMS); } +}; + +static PointVector *aligned_alloc(size_t num) { + size_t num_bytes = num * sizeof(PointVector); + double mega_bytes = num_bytes / (1024.0*1024.0); + fprintf(stderr, "allocate %.2f MB of vectors\n", mega_bytes); + char *mem = (char *)malloc(num_bytes + 512); + mem += 512; + size_t val = (size_t)mem; + size_t unalign = val % 512; + mem -= unalign; + return reinterpret_cast<PointVector *>(mem); +} + +static PointVector *generatedQueries = aligned_alloc(NUM_Q); +static PointVector *generatedDocs = aligned_alloc(NUM_DOCS); + +struct DocVectorAdapter : public DocVectorAccess<float> +{ + vespalib::ConstArrayRef<float> get(uint32_t docid) const override { + ASSERT_TRUE(docid < NUM_DOCS); + return generatedDocs[docid]; + } +}; |