1 #include <torch/csrc/jit/api/object.h>
2
3 #include <ATen/core/jit_type.h>
4 #include <torch/csrc/jit/api/compilation_unit.h>
5 #include <torch/csrc/jit/frontend/resolver.h>
6 #include <torch/csrc/jit/frontend/sugared_value.h>
7
8 namespace torch::jit {
9
Object(std::shared_ptr<CompilationUnit> cu,const c10::ClassTypePtr & type)10 Object::Object(
11 std::shared_ptr<CompilationUnit> cu,
12 const c10::ClassTypePtr& type)
13 : Object(c10::ivalue::Object::create(
14 c10::StrongTypePtr(std::move(cu), type),
15 type->numAttributes())) {}
16
find_method(const std::string & basename) const17 std::optional<Method> Object::find_method(const std::string& basename) const {
18 for (Function* fn : type()->methods()) {
19 if (fn->name() == basename) {
20 return Method(_ivalue(), fn);
21 }
22 }
23 return std::nullopt;
24 }
25
define(const std::string & src,const ResolverPtr & resolver)26 void Object::define(const std::string& src, const ResolverPtr& resolver) {
27 const auto self = SimpleSelf(type());
28 _ivalue()->compilation_unit()->define(
29 *type()->name(), src, resolver ? resolver : nativeResolver(), &self);
30 }
31
copy() const32 Object Object::copy() const {
33 return Object(_ivalue()->copy());
34 }
35
deepcopy() const36 Object Object::deepcopy() const {
37 return Object(_ivalue()->deepcopy());
38 }
39
40 } // namespace torch::jit
41