Skip to content

Instantly share code, notes, and snippets.

@javierluraschi
Created January 16, 2020 23:50
Show Gist options
  • Save javierluraschi/b1f54ca678a6c82a9bc08384bd7d8a79 to your computer and use it in GitHub Desktop.
Save javierluraschi/b1f54ca678a6c82a9bc08384bd7d8a79 to your computer and use it in GitHub Desktop.
PyTorch 1.3.0 example with Visual Studio
#ifdef _MSC_VER
#pragma warning( disable : 4146 )
#endif
#include <iostream>
#include <torch/torch.h>
struct Net : torch::nn::Module {
Net(int64_t N, int64_t M) {
W = register_parameter("W", torch::randn({ N, M }));
b = register_parameter("b", torch::randn(M));
}
torch::Tensor forward(torch::Tensor input) {
return torch::addmm(b, input, W);
}
torch::Tensor W, b;
};
int main()
{
std::cout << "Hello World!\n";
Net net(4, 5);
for (const auto& p : net.parameters()) {
std::cout << p << std::endl;
}
torch::Tensor tensor = torch::eye(3);
std::cout << tensor << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment