-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements PartialScoreAccumulator concept (only under C++20), and introduces a slight refactoring of the accumulator API, including renaming methods and making some methods private. These changes are part of the effort to stabilize library API. Concepts not only help with debugging and compilation time using C+20-compatible compiler, but also serve as a programmatically verifiable API documentation. Thus, even if not always used, they are extremely useful.
- Loading branch information
Showing
11 changed files
with
181 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Score Accumulators | ||
|
||
Score accumulators are used to accumulate (and later aggregate) document | ||
scores. These are handy for term-at-a-time (TAAT) query processing. Two | ||
implementations are available: `SimpleAccumulator` and | ||
`LazyAccumulator`. They both satisfy the `PartialScoreAccumulator` | ||
concept (if using in C++20 mode). For the definition, see | ||
`partial_score_accumulator.hpp`. | ||
|
||
`SimpleAccumulator` is a simple wrapper over a `std::vector<float>`, | ||
while `LazyAccumulator` implements some optimizations as described in | ||
`lazy_accumulator.hpp`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2023 PISA developers | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// clang-format off | ||
|
||
#pragma once | ||
|
||
#ifdef PISA_ENABLE_CONCEPTS | ||
|
||
#include <concepts> | ||
#include <cstdint> | ||
#include <iterator> | ||
#include <vector> | ||
|
||
#include "topk_queue.hpp" | ||
|
||
namespace pisa { | ||
|
||
/** | ||
* Accumulator capable of accumulating partial scores. One document can be accumulated multiple | ||
* times, and the scores will be summed. Typically used for term-at-a-time (TAAT) processing. | ||
*/ | ||
template <typename T> | ||
concept PartialScoreAccumulator = requires(T a, std::uint32_t docid, float score) | ||
{ | ||
/** | ||
* Resets the accumulator. After a reset, it is ready to be used for the next query. | ||
*/ | ||
a.reset(); | ||
|
||
/** | ||
* Accumulates a partial score for the given document. | ||
*/ | ||
a.accumulate(docid, score); | ||
} | ||
&& requires(T const a, float score, pisa::topk_queue& topk) | ||
{ | ||
/** | ||
* Pushes results to the top-k priority queue. | ||
*/ | ||
a.collect(topk); | ||
{ a.size() } -> std::same_as<std::size_t>; | ||
}; | ||
|
||
}; // namespace pisa | ||
|
||
// clang-format on | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* Copyright 2023 PISA developers | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. */ | ||
|
||
#pragma once | ||
|
||
#ifdef PISA_ENABLE_CONCEPTS | ||
|
||
#define PISA_REQUIRES(x) \ | ||
requires (x) | ||
|
||
#define PISA_ASSERT_CONCEPT(x) \ | ||
static_assert(x) | ||
|
||
#else | ||
|
||
#define PISA_REQUIRES(x) /**/ | ||
|
||
#define PISA_ASSERT_CONCEPT(x) /**/ | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters