mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Summary: This makes a few changes wrt Type, with the ultimate goal of removing Type from the public Methods/Functions. In particular: 1) Removes factory functions from Type, into TypeExtendedInterface. 2) sparse_coo_tensor is now a first class at:: namespace function, with TensorOptions overloads. 3) We move from Type-based sparse_coo_tensor dispatch to function-based. Note we still require a number of changes to get rid of tType in the public interface, in particular TensorOptions needs to support CUDA vs non-CUDA dispatch. That is coming in a future patch. Pull Request resolved: https://github.com/pytorch/pytorch/pull/12025 Reviewed By: ezyang Differential Revision: D10017205 Pulled By: gchanan fbshipit-source-id: 00807a37b09ed33f0656aaa165bb925abb026320
30 lines
986 B
C++
30 lines
986 B
C++
#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
|