#include #include #include #include namespace torch { namespace jit { namespace { struct Foo : torch::jit::CustomClassHolder { int x, y; Foo() : x(0), y(0) {} Foo(int x_, int y_) : x(x_), y(y_) {} int64_t info() { return this->x * this->y; } int64_t add(int64_t z) { return (x + y) * z; } void increment(int64_t z) { this->x += z; this->y += z; } int64_t combine(c10::intrusive_ptr b) { return this->info() + b->info(); } ~Foo() { // std::cout<<"Destroying object with values: "< struct Stack : torch::jit::CustomClassHolder { std::vector stack_; Stack(std::vector init) : stack_(init.begin(), init.end()) {} void push(T x) { stack_.push_back(x); } T pop() { auto val = stack_.back(); stack_.pop_back(); return val; } c10::intrusive_ptr clone() { return c10::make_intrusive(stack_); } void merge(const c10::intrusive_ptr& c) { for (auto& elem : c->stack_) { push(elem); } } }; static auto test = torch::jit::class_("_TorchScriptTesting_Foo") .def(torch::jit::init()) // .def(torch::jit::init<>()) .def("info", &Foo::info) .def("increment", &Foo::increment) .def("add", &Foo::add) .def("combine", &Foo::combine); static auto testStack = torch::jit::class_>("_TorchScriptTesting_StackString") .def(torch::jit::init>()) .def("push", &Stack::push) .def("pop", &Stack::pop) .def("clone", &Stack::clone) .def("merge", &Stack::merge); } // namespace } // namespace jit } // namespace torch