3 #include <torch/types.h> 12 namespace sequencers {
14 template<
typename Result>
15 bool buffer_contains_result(
const std::vector<optional<Result>>& buffer) {
17 buffer.begin(), buffer.end(), [](
const optional<Result>& result) {
18 return result.has_value();
28 template <
typename Result>
30 using ResultProducer = std::function<optional<Result>()>;
37 template <
typename Result>
39 using typename Sequencer<Result>::ResultProducer;
62 template <
typename Result>
64 using typename Sequencer<Result>::ResultProducer;
73 if (
auto& maybe_result = buffer(next_sequence_number_)) {
74 auto result = std::move(*maybe_result);
75 buffer(next_sequence_number_++).reset();
80 auto result = next_result();
82 AT_ASSERT(!detail::buffer_contains_result(buffer_));
87 if (result->sequence_number == next_sequence_number_) {
88 ++next_sequence_number_;
92 AT_ASSERT(!buffer(result->sequence_number).has_value());
93 buffer(result->sequence_number) = std::move(result);
101 return buffer_.at(index % buffer_.size());
105 size_t next_sequence_number_ = 0;
A Sequencer accepts a function that yields the next result of a DataLoader and then has the opportuni...
A Sequencer that does not enforce any ordering.
optional< Result > next(ResultProducer next_result) override
Buffers results until the next one in the expected order is received.
OrderedSequencer(size_t max_jobs)
Constructs the OrderedSequencer with the maximum number of results it will ever hold at one point in ...
A Sequencer that buffers results and returns them in order of their sequence number.
optional< Result > & buffer(size_t index)
Accesses the buffer at the index modulo the buffer size.
std::vector< optional< Result > > buffer_
A fixed-size buffer (after construction).