pytorch

Форк
0
/
sequential.cpp 
48 строк · 1.2 Кб
1
#include <torch/csrc/jit/mobile/train/sequential.h>
2
#include <torch/types.h>
3

4
#include <algorithm>
5
#include <cstddef>
6
#include <vector>
7

8
namespace torch {
9
namespace jit {
10
namespace mobile {
11
SequentialSampler::SequentialSampler(size_t size) : size_(size) {}
12

13
void SequentialSampler::reset(optional<size_t> new_size) {
14
  if (new_size.has_value()) {
15
    size_ = *new_size;
16
  }
17
  index_ = 0;
18
}
19

20
optional<std::vector<size_t>> SequentialSampler::next(size_t batch_size) {
21
  const auto remaining_indices = size_ - index_;
22
  if (remaining_indices == 0) {
23
    return nullopt;
24
  }
25
  std::vector<size_t> index_batch(std::min(batch_size, remaining_indices));
26
  for (auto& i : index_batch) {
27
    i = index_++;
28
  }
29
  return index_batch;
30
}
31

32
void SequentialSampler::save(serialize::OutputArchive& archive) const {
33
  TORCH_CHECK(
34
      false, "Serialization of SequentialSampler not supported on mobile.");
35
}
36

37
void SequentialSampler::load(serialize::InputArchive& archive) {
38
  TORCH_CHECK(
39
      false, "Serialization of SequentialSampler not supported on mobile.");
40
}
41

42
size_t SequentialSampler::index() const noexcept {
43
  return index_;
44
}
45

46
} // namespace mobile
47
} // namespace jit
48
} // namespace torch
49

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

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

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

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