TensorOptions

See https://github.com/pytorch/pytorch/blob/master/c10/core/TensorOptions.h

Methods

./code/tensor-options/main.cc (Methods)
 1void TestMethods() {
 2  torch::TensorOptions opts = torch::dtype<float>();
 3  TORCH_CHECK(opts.device() == torch::Device(torch::kCPU));
 4  // It has not device_type()!
 5  TORCH_CHECK(opts.device() == torch::kCPU);
 6  TORCH_CHECK(opts.device().type() == torch::kCPU);
 7  TORCH_CHECK(opts.requires_grad() == false);
 8
 9  torch::TensorOptions opts2 =
10      opts.device("cuda:2").dtype(torch::kInt).requires_grad(false);
11
12  TORCH_CHECK(opts2.dtype() == caffe2::TypeMeta::Make<int32_t>());
13  TORCH_CHECK(opts2.dtype() == torch::kInt32);
14  TORCH_CHECK(opts2.requires_grad() == false);
15}