xref: /aosp_15_r20/external/pytorch/aten/src/ATen/native/NegateFallback.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #define TORCH_ASSERT_ONLY_METHOD_OPERATORS
2 #include <ATen/native/MathBitsFallback.h>
3 #include <ATen/native/MathBitFallThroughLists.h>
4 
5 namespace at::native {
6 struct NegFallback : MathOpFallback {
NegFallbackat::native::NegFallback7   NegFallback() : MathOpFallback(DispatchKey::Negative, "negation") {}
is_bit_setat::native::NegFallback8   bool is_bit_set(const Tensor& tensor) override {
9     return tensor.is_neg();
10   }
11 };
12 
negationFallback(const c10::OperatorHandle & op,DispatchKeySet dispatch_keys,torch::jit::Stack * stack)13 static void negationFallback(const c10::OperatorHandle& op, DispatchKeySet dispatch_keys, torch::jit::Stack* stack) {
14   NegFallback object;
15   object.fallback_impl(op, dispatch_keys, stack);
16 }
17 
TORCH_LIBRARY_IMPL(_,Negative,m)18 TORCH_LIBRARY_IMPL(_, Negative, m) {
19   m.fallback(torch::CppFunction::makeFromBoxedFunction<&negationFallback>());
20 }
21 
TORCH_LIBRARY_IMPL(aten,Negative,m)22 TORCH_LIBRARY_IMPL(aten, Negative, m) {
23   m.impl("set_.source_Storage_storage_offset", torch::CppFunction::makeFallthrough());
24   m.impl("set_.source_Tensor", torch::CppFunction::makeFallthrough());
25   m.impl("set_", torch::CppFunction::makeFallthrough());
26   m.impl("copy_", torch::CppFunction::makeFallthrough());
27   m.impl("clone", torch::CppFunction::makeFallthrough());
28   m.impl("neg_", torch::CppFunction::makeFallthrough());
29   m.impl("resolve_neg", torch::CppFunction::makeFallthrough());
30   m.impl("resolve_conj", torch::CppFunction::makeFallthrough());
31   m.impl("repeat_interleave.Tensor", torch::CppFunction::makeFallthrough());
32   m.impl("repeat_interleave.self_Tensor", torch::CppFunction::makeFallthrough());
33   m.impl("repeat_interleave.self_int", torch::CppFunction::makeFallthrough());
34 
35   // See test_metadata_check_when_primal_has_neg_bit in test_autograd.py
36   m.impl("_has_same_storage_numel", torch::CppFunction::makeFallthrough());
37   m.impl("_new_zeros_with_same_feature_meta", torch::CppFunction::makeFallthrough());
38 
39   // linear algebra functions
40   m.impl("linalg_solve_triangular", torch::CppFunction::makeFallthrough());
41   m.impl("linalg_solve_triangular.out", torch::CppFunction::makeFallthrough());
42   m.impl("linalg_svd", torch::CppFunction::makeFallthrough());
43   m.impl("linalg_svd.U", torch::CppFunction::makeFallthrough());
44 
45   TORCH_VIEW_FNS(m)
46   TENSOR_UTILITIES_AND_CONSTRUCTORS(m)
47   TORCH_VIEW_FNS_NATIVE_FN_REGISTRATION(m)
48 }
49 
50 } // namespace at::native
51