forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLegacyDefinitions.cpp
97 lines (86 loc) · 3.7 KB
/
LegacyDefinitions.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <ATen/ATen.h>
#include <ATen/NativeFunctions.h>
#include <ATen/LegacyTHFunctionsCPU.h>
#include <ATen/NamedTensorUtils.h>
#include <ATen/core/EnableNamedTensor.h>
namespace at { namespace native {
// Methods
Tensor & masked_fill__cpu(Tensor& self, const Tensor & mask, Scalar value) {
#ifdef BUILD_NAMEDTENSOR
auto outnames = namedinference::broadcast_to_outnames(self, mask, "masked_fill_");
#endif
// As we dispatch on self and TH is type-checked, we need different definitions.
// This can be fixed by moving to ATen.
if (mask.dtype() == at::ScalarType::Byte) {
AT_WARN("masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated," \
"please use a mask with dtype torch.bool instead.");
legacy::cpu::_th_masked_fill_(self, mask, value);
} else {
legacy::cpu::_th_masked_fill_bool_(self, mask, value);
}
#ifdef BUILD_NAMEDTENSOR
namedinference::propagate_names(self, std::move(outnames), /*validate_names=*/false);
#endif
return self;
}
Tensor & masked_fill__cpu(Tensor& self, const Tensor & mask, const Tensor & value) {
#ifdef BUILD_NAMEDTENSOR
auto outnames = namedinference::broadcast_to_outnames(self, mask, "masked_fill_");
#endif
// As we dispatch on self and TH is type-checked, we need different definitions.
// This can be fixed by moving to ATen.
if (mask.dtype() == at::ScalarType::Byte) {
AT_WARN("masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated," \
"please use a mask with dtype torch.bool instead.");
legacy::cpu::_th_masked_fill_(self, mask, value);
} else {
legacy::cpu::_th_masked_fill_bool_(self, mask, value);
}
#ifdef BUILD_NAMEDTENSOR
namedinference::propagate_names(self, std::move(outnames), /*validate_names=*/false);
#endif
return self;
}
Tensor & masked_scatter__cpu(Tensor& self, const Tensor & mask, const Tensor & source) {
// As we dispatch on self and TH is type-checked, we need different definitions.
// This can be fixed by moving to ATen.
if (mask.dtype() == at::ScalarType::Byte) {
AT_WARN("masked_scatter_ received a mask with dtype torch.uint8, this behavior is now deprecated," \
"please use a mask with dtype torch.bool instead.");
return legacy::cpu::_th_masked_scatter_(self, mask, source);
} else {
return legacy::cpu::_th_masked_scatter_bool_(self, mask, source);
}
}
Tensor masked_select_cpu(const Tensor & self, const Tensor & mask) {
#ifdef BUILD_NAMEDTENSOR
namedinference::compute_broadcast_outnames(self, mask);
#endif
if (mask.dtype() == at::ScalarType::Byte) {
AT_WARN("masked_select received a mask with dtype torch.uint8, this behavior is now deprecated," \
"please use a mask with dtype torch.bool instead.");
return legacy::cpu::_th_masked_select(self, mask);
} else {
return legacy::cpu::_th_masked_select_bool(self, mask);
}
}
Tensor & masked_select_out_cpu(Tensor & result, const Tensor & self, const Tensor & mask) {
#ifdef BUILD_NAMEDTENSOR
namedinference::compute_broadcast_outnames(self, mask);
#endif
if (mask.dtype() == at::ScalarType::Bool) {
return legacy::cpu::_th_masked_select_bool_out(result, self, mask);
} else {
return legacy::cpu::_th_masked_select_out(result, self, mask);
}
}
Tensor argsort(const Tensor & self, int64_t dim, bool descending) {
return std::get<1>(at::sort(self, dim, descending));
}
Tensor & gather_out_cpu(Tensor & result, const Tensor & self, int64_t dim, const Tensor & index, bool sparse_grad) {
return legacy::cpu::_th_gather_out(result, self, dim, index);
}
Tensor gather_cpu(const Tensor & self, int64_t dim, const Tensor & index, bool sparse_grad) {
return legacy::cpu::_th_gather(self, dim, index);
}
}} // namespace at::native