6 #include <c10/util/ArrayRef.h> 7 #include <torch/csrc/autograd/variable.h> 8 #include <torch/csrc/jit/tracer.h> 11 #include <initializer_list> 16 #define TENSOR(T, S, _1) \ 17 inline at::Tensor tensor( \ 18 at::ArrayRef<T> values, const at::TensorOptions& options) { \ 20 at::tensor(values, at::TensorOptions(options).is_variable(false)); \ 21 return autograd::make_variable(result, options.requires_grad()); \ 23 inline at::Tensor tensor( \ 24 std::initializer_list<T> values, const at::TensorOptions& options) { \ 25 return torch::tensor(at::ArrayRef<T>(values), options); \ 27 inline at::Tensor tensor(T value, const at::TensorOptions& options) { \ 28 return torch::tensor(at::ArrayRef<T>(value), options); \ 30 inline at::Tensor tensor(at::ArrayRef<T> values) { \ 31 return torch::tensor(std::move(values), at::dtype(at::k##S)); \ 33 inline at::Tensor tensor(std::initializer_list<T> values) { \ 34 return torch::tensor(at::ArrayRef<T>(values)); \ 36 inline at::Tensor tensor(T value) { \ 37 return torch::tensor(at::ArrayRef<T>(value)); \ 39 AT_FORALL_SCALAR_TYPES_EXCEPT_HALF(TENSOR)
43 using Deleter = std::function<void(void*)>;
56 const Deleter& deleter,
59 at::from_blob(data, sizes, strides, deleter, options.is_variable(
false));
60 return autograd::make_variable(tensor, options.requires_grad());
73 return torch::from_blob(
90 const Deleter& deleter,
93 at::from_blob(data, sizes, deleter, options.is_variable(
false));
94 return autograd::make_variable(tensor, options.requires_grad());
105 return torch::from_blob(data, sizes, [](
void*) {}, options);
108 ${function_definitions}