google-research

Форк
0
58 строк · 1.7 Кб
1
// Copyright 2023 The Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
#include "utilities.h"
16

17
#include <stdint.h>
18

19
#include <algorithm>
20
#include <cassert>
21
#include <cmath>
22
#include <cstdlib>
23
#include <iostream>
24
#include <random>
25
#include <string>
26
#include <vector>
27

28
std::mt19937 RandomHandler::generator_;
29

30
std::string PrettyNum(int64_t number) {
31
  std::string pretty_number = std::to_string(number);
32
  for (int i = static_cast<int>(pretty_number.size()) - 3; i > 0; i -= 3) {
33
    pretty_number.insert(pretty_number.begin() + i, ',');
34
  }
35
  return pretty_number;
36
}
37

38
void Fail(const std::string& error) {
39
  std::cerr << error << std::endl;
40
  exit(1);
41
}
42

43
std::vector<double> LogSpace(double small, double large, double base) {
44
  if (small > large) {
45
    std::vector<double> log_space = LogSpace(large, small, base);
46
    std::reverse(log_space.begin(), log_space.end());
47
    return log_space;
48
  }
49
  assert(base > 1);
50
  int steps =
51
      static_cast<int>(ceil((log(large) - log(small)) / log(base) - 1e-6));
52
  double step = pow(large / small, 1.0 / steps);
53
  std::vector<double> log_space = {small};
54
  for (int i = 0; i < steps; ++i) {
55
    log_space.push_back(log_space.back() * step);
56
  }
57
  return log_space;
58
}
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.