forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorch.cpp
29 lines (23 loc) · 986 Bytes
/
torch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <torch/csrc/variable_tensor_functions.h>
#include <torch/csrc/autograd/generated/VariableType.h>
#include <torch/csrc/autograd/variable.h>
namespace torch {
at::TypeExtendedInterface& getVariableType(at::Backend backend, at::ScalarType type) {
return *autograd::VariableType::getVariableTypeFromBaseType(at::getNonVariableType(backend, type));
}
at::TypeExtendedInterface& CPU(at::ScalarType type) {
return torch::getVariableType(at::Backend::CPU, type);
}
at::TypeExtendedInterface& CUDA(at::ScalarType type) {
return torch::getVariableType(at::Backend::CUDA, type);
}
at::Tensor toTensor(const at::Scalar& scalar) {
return autograd::make_variable(scalar_to_tensor(scalar));
}
void set_requires_grad(at::Tensor& tensor, bool requires_grad) noexcept {
autograd::as_variable_ref(tensor).set_requires_grad(requires_grad);
}
bool requires_grad(const at::Tensor& tensor) noexcept {
return autograd::as_variable_ref(tensor).requires_grad();
}
} // namespace torch