Better tests/support for Python/C++ inter-op (#15193)

Summary:
Methods like `module.named_modules()` returns a container of `shared_ptr<nn::Module>`. Currently the `nn::Module` base class does  not have Python bindings. This PR fixes this, and adds more unit tests.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15193

Differential Revision: D13458713

Pulled By: goldsborough

fbshipit-source-id: 4091fe1b96a1be8db14c6a4307fbacc2b41ff6fe
This commit is contained in:
Peter Goldsborough
2018-12-14 08:29:15 -08:00
committed by Facebook Github Bot
parent fb8487d708
commit 4327a2d70a
4 changed files with 46 additions and 12 deletions
@@ -3,9 +3,13 @@
#include <cstddef>
#include <string>
struct Net : torch::nn::Module {
Net(int64_t in, int64_t out) : fc(in, out) {
register_module("fc", fc);
struct Net : torch::nn::Cloneable<Net> {
Net(int64_t in, int64_t out) : in_(in), out_(out) {
reset();
}
void reset() override {
fc = register_module("fc", torch::nn::Linear(in_, out_));
buffer = register_buffer("buf", torch::eye(5));
}
@@ -34,7 +38,8 @@ struct Net : torch::nn::Module {
register_module(name, torch::nn::Linear(fc->options));
}
torch::nn::Linear fc;
int64_t in_, out_;
torch::nn::Linear fc{nullptr};
torch::Tensor buffer;
};