forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPointwiseOps.cpp
68 lines (58 loc) · 1.86 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
// 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 meta {
TORCH_META_FUNC(addcmul)
(const Tensor& self,
const Tensor& tensor1,
const Tensor& tensor2,
const Scalar& value) {
build_ternary_op(maybe_get_output(), self, tensor1, tensor2);
}
TORCH_META_FUNC(addcdiv)
(const Tensor& self,
const Tensor& tensor1,
const Tensor& tensor2,
const Scalar& value) {
if (isIntegralType(tensor1.scalar_type(), /*includeBool=*/true) &&
isIntegralType(tensor2.scalar_type(), /*includeBool=*/true)) {
TORCH_CHECK(
false,
"Integer division with addcdiv is no longer supported, and in a future ",
"release addcdiv will perform a true division of tensor1 and tensor2. ",
"The historic addcdiv behavior can be implemented as ",
"(input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype) ",
"for integer inputs and as ",
"(input + value * tensor1 / tensor2) for float inputs. ",
"The future addcdiv behavior is just the latter implementation: ",
"(input + value * tensor1 / tensor2), for all dtypes.");
}
build_ternary_op(maybe_get_output(), self, tensor1, tensor2);
}
} // namespace meta
namespace native {
TORCH_IMPL_FUNC(addcmul_out)
(const Tensor& self,
const Tensor& tensor1,
const Tensor& tensor2,
const Scalar& value,
const Tensor& result) {
addcmul_stub(device_type(), *this, value);
}
TORCH_IMPL_FUNC(addcdiv_out)
(const Tensor& self,
const Tensor& tensor1,
const Tensor& tensor2,
const Scalar& value,
const Tensor& result) {
addcdiv_stub(device_type(), *this, value);
}
DEFINE_DISPATCH(addcmul_stub);
DEFINE_DISPATCH(addcdiv_stub);
} // namespace native
} // namespace at