forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointwiseOps.cpp
99 lines (88 loc) · 2.74 KB
/
PointwiseOps.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
98
99
// Ternary and higher-order pointwise operations
#include <ATen/native/PointwiseOps.h>
#include <ATen/ATen.h>
#include <ATen/NativeFunctions.h>
#include <ATen/MemoryOverlap.h>
#include <ATen/native/TensorIterator.h>
#include <ATen/NamedTensorUtils.h>
namespace at {
namespace native {
Tensor addcmul(
const Tensor& self,
const Tensor& tensor1,
const Tensor& tensor2,
Scalar value) {
Tensor result = at::empty({0}, self.options());
return at::addcmul_out(result, self, tensor1, tensor2, value);
}
Tensor& addcmul_(
Tensor& self,
const Tensor& tensor1,
const Tensor& tensor2,
Scalar value) {
return at::addcmul_out(self, self, tensor1, tensor2, value);
}
Tensor& addcmul_out(
Tensor& result,
const Tensor& self,
const Tensor& tensor1,
const Tensor& tensor2,
Scalar value) {
checkBackend("addcmul_cpu", result, self.options().backend());
auto iter = at::TensorIterator();
iter.set_check_mem_overlap(true);
iter.add_output(result);
iter.add_input(self);
iter.add_input(tensor1);
iter.add_input(tensor2);
iter.build();
addcmul_stub(iter.device_type(), iter, value);
return result;
}
Tensor addcdiv(
const Tensor& self,
const Tensor& tensor1,
const Tensor& tensor2,
Scalar value) {
Tensor result = at::empty({0}, self.options());
return at::addcdiv_out(result, self, tensor1, tensor2, value);
}
Tensor& addcdiv_(
Tensor& self,
const Tensor& tensor1,
const Tensor& tensor2,
Scalar value) {
return at::addcdiv_out(self, self, tensor1, tensor2, value);
}
Tensor& addcdiv_out(
Tensor& result,
const Tensor& self,
const Tensor& tensor1,
const Tensor& tensor2,
Scalar value) {
if (isIntegralType(tensor1.scalar_type(), /*includeBool=*/ true)
&& isIntegralType(tensor2.scalar_type(), /*includeBool=*/ true)) {
TORCH_WARN_ONCE(
"Integer division with addcdiv is deprecated, and in a future ",
"release addcdiv will perform a true division of tensor1 and tensor2. ",
"The current addcdiv behavior can be replicated using floor_divide ",
"for integral inputs (self + value * tensor1 // tensor2) and ",
"division for float inputs (self + value * tensor1 / tensor2). ",
"The new addcdiv behavior can be implemented with true_divide ",
"(self + value * torch.true_divide(tensor1, tensor2).");
}
checkBackend("addcdiv_cpu", result, self.options().backend());
auto iter = at::TensorIterator();
iter.set_check_mem_overlap(true);
iter.add_output(result);
iter.add_input(self);
iter.add_input(tensor1);
iter.add_input(tensor2);
iter.build();
addcdiv_stub(iter.device_type(), iter, value);
return result;
}
DEFINE_DISPATCH(addcmul_stub);
DEFINE_DISPATCH(addcdiv_stub);
} // namespace native
} // namespace at