Beispiel #1
0
void InputBuffer::add(size_t pos, Variable var) {
  TORCH_ASSERT(pos < buffer.size());
  if (!var.defined()) {
    return;
  }
  auto& old_var = buffer[pos];
  if (!old_var.defined()) {
    buffer[pos] = std::move(var);
  } else {
    AutoGPU auto_gpu(var);
    // ATen doesn't route sparse additions correctly...
    if (old_var.type().is_sparse()) {
      buffer[pos] = var + old_var;
    } else {
      buffer[pos] = old_var + var;
    }
  }
}
// These definitions require Variable struct to be defined, so they can't be
// in tracer_state.h
VariableFlags VariableFlags::of(const Variable& var) {
  VariableFlags f;
  f.defined = var.defined();
  f.requires_grad = f.defined && var.requires_grad();
  return f;
}