41 : impl_(std::make_shared<VariableImpl>(data, requires_grad)) {}
45 std::weak_ptr<Function> grad_fn()
const noexcept;
46 bool requires_grad()
const noexcept;
50 void set_grad_fn(std::shared_ptr<Function> grad_fn);
53 void fill(tensor::Scalar item);
56 friend std::ostream& operator<<(std::ostream& os,
const Variable& obj);
59 explicit Variable(std::shared_ptr<VariableImpl> impl)
60 : impl_(std::move(impl)) {}
61 std::shared_ptr<VariableImpl> impl_;
62 std::vector<Variable> topological_sort();
63 void dfs(
const Variable& v, std::unordered_set<void*>& visited,
64 std::vector<Variable>& topo)
const;