@@ -29,9 +29,9 @@ This release adds a new API, `torch.CutomClassHolder`, for binding custom C++ c
29
29
30
30
``` python
31
31
template < class T>
32
- struct Stack : torch::CustomClassHolder {
32
+ struct MyStackClass : torch::CustomClassHolder {
33
33
std::vector< T> stack_;
34
- Stack (std::vector< T> init) : stack_(std::move(init)) {}
34
+ MyStackClass (std::vector< T> init) : stack_(std::move(init)) {}
35
35
36
36
void push(T x) {
37
37
stack_.push_back(x);
@@ -44,21 +44,21 @@ struct Stack : torch::CustomClassHolder {
44
44
};
45
45
46
46
static auto testStack =
47
- torch::class_< Stack < std::string>> (" Stack " )
47
+ torch::class_< MyStackClass < std::string>> (" myclasses " , " MyStackClass " )
48
48
.def (torch::init< std::vector< std::string>> ())
49
- .def (" push" , & Stack < std::string> ::push)
50
- .def (" pop" , & Stack < std::string> ::pop)
51
- .def (" size" , [](const c10::intrusive_ptr< Stack > & self ) {
49
+ .def (" push" , & MyStackClass < std::string> ::push)
50
+ .def (" pop" , & MyStackClass < std::string> ::pop)
51
+ .def (" size" , [](const c10::intrusive_ptr< MyStackClass > & self ) {
52
52
return self -> stack_.size();
53
53
});
54
54
```
55
55
56
56
Which exposes a class you can use in Python and TorchScript like so:
57
57
58
58
``` python
59
- @torch.jit.script
60
- def do_stacks (s : torch.classes.Stack ):
61
- s2 = torch.classes.Stack ([" hi" , " mom" ])
59
+ @torch.jit.script
60
+ def do_stacks (s : torch.classes.myclasses.MyStackClass ):
61
+ s2 = torch.classes.myclasses.MyStackClass ([" hi" , " mom" ])
62
62
print (s2.pop()) # "mom"
63
63
s2.push(" foobar" )
64
64
return s2 # ["hi", "foobar"]
0 commit comments