fix algorithms bazel build

This commit is contained in:
Corentin Le Molgat
2024-02-15 09:59:54 +01:00
parent 78c8eca8cc
commit 9889686c9e
5 changed files with 842 additions and 13 deletions

View File

@@ -21,6 +21,7 @@
#include <utility>
#include <vector>
#include "ortools/base/murmur.h"
#include "absl/numeric/int128.h"
#include "absl/random/distributions.h"
#include "absl/random/random.h"
@@ -207,12 +208,10 @@ TEST(BinarySearchTest, NonMonoticPredicateReachesLocalInflexionPoint_Double) {
constexpr double kEps = std::numeric_limits<double>::epsilon();
const int kNumAttempts = 100000;
for (int attempt = 0; attempt < kNumAttempts; ++attempt) {
const uint64_t hash_seed = random();
std::function<bool(double)> non_monotonic_predicate =
[hash_seed](double x) {
return util_hash::CityHash64WithSeed(
reinterpret_cast<const char*>(&x), sizeof(x), hash_seed) &
1;
[](double x) {
return util_hash::MurmurHash64(
reinterpret_cast<const char*>(&x), sizeof(x)) & 1;
};
// Pick a random [x_true, x_false] interval which verifies f(x_true) = true
// and f(x_false) = false.
@@ -297,10 +296,10 @@ template <typename T>
void BM_BinarySearch(benchmark::State& state) {
auto functor = [](T x) { return x > std::numeric_limits<T>::max() / 2; };
for (const auto s : state) {
testing::DoNotOptimize(functor);
benchmark::DoNotOptimize(functor);
auto result = BinarySearch<T>(std::numeric_limits<T>::max(),
std::numeric_limits<T>::min(), functor);
testing::DoNotOptimize(result);
benchmark::DoNotOptimize(result);
}
}
BENCHMARK(BM_BinarySearch<float>);