in src/cc/actorpool.cc [239:275]
void set_outputs(TensorNest outputs) {
if (promises_.empty()) {
// Batch has been set before.
throw py::runtime_error("set_outputs called twice");
}
if (check_outputs_) {
const int64_t expected_batch_size = promises_.size();
outputs.for_each([this,
expected_batch_size](const torch::Tensor& tensor) {
if (tensor.dim() <= batch_dim_) {
std::stringstream ss;
ss << "With batch dimension " << batch_dim_
<< ", output shape must have at least " << batch_dim_ + 1
<< " dimensions, but got " << tensor.sizes();
throw py::value_error(ss.str());
}
if (tensor.sizes()[batch_dim_] != expected_batch_size) {
throw py::value_error(
"Output shape must have the same batch "
"dimension as the input batch size. Expected: " +
std::to_string(expected_batch_size) +
". Observed: " + std::to_string(tensor.sizes()[batch_dim_]));
}
});
}
auto shared_outputs = std::make_shared<TensorNest>(std::move(outputs));
int64_t b = 0;
for (auto& promise : promises_) {
promise.set_value(std::make_pair(shared_outputs, b));
++b;
}
promises_.clear();
}