Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c12038e
Added degrees, radians, ldexp
Chillee May 30, 2019
29b5e9a
Update on "Added degrees, radians, ldexp"
Chillee May 30, 2019
ddb0321
Update on "Added degrees, radians, ldexp"
Chillee May 30, 2019
91e8c53
Update on "Added degrees, radians, ldexp"
Chillee May 30, 2019
784bded
Update on "Added degrees, radians, ldexp"
Chillee May 30, 2019
754d92a
Update on "Added degrees, radians, ldexp"
Chillee May 30, 2019
87382a5
Update on "Added degrees, radians, ldexp"
Chillee May 30, 2019
e6b5f2f
Update on "Added degrees, radians, ldexp"
Chillee May 30, 2019
8c28b29
Update on "Added degrees, radians, ldexp"
Chillee May 31, 2019
51ca60d
Update on "Added degrees, radians, ldexp"
Chillee May 31, 2019
44ce861
Update on "Added degrees, radians, ldexp"
Chillee May 31, 2019
47deb03
Update on "Added degrees, radians, ldexp"
Chillee May 31, 2019
06bf8cf
Update on "Added degrees, radians, ldexp"
Chillee May 31, 2019
274ef0b
Update on "Added degrees, radians, ldexp"
Chillee May 31, 2019
132074b
Update on "Added degrees, radians, ldexp"
Chillee May 31, 2019
4f24179
Update on "Added degrees, radians, ldexp"
Chillee Jun 3, 2019
73ea11a
Update on "Added degrees, radians, ldexp"
Chillee Jun 3, 2019
594c8c2
Update on "Added degrees, radians, ldexp"
Chillee Jun 3, 2019
7ce4785
Update on "Added degrees, radians, ldexp"
Chillee Jun 3, 2019
fd1e58c
Update on "Added degrees, radians, ldexp"
Chillee Jun 3, 2019
7cc79f9
Update on "Added degrees, radians, ldexp"
Chillee Jun 3, 2019
57d1fce
Update on "Added degrees, radians, ldexp"
Chillee Jun 4, 2019
6a685c6
Update on "Added degrees, radians, ldexp"
Chillee Jun 4, 2019
b8f5e91
Update on "Added degrees, radians, ldexp"
Chillee Jun 4, 2019
2c4d408
Update on "Added degrees, radians, ldexp"
Chillee Jun 5, 2019
980fd1d
Update on "Added degrees, radians, ldexp"
Chillee Jun 5, 2019
1f38b01
Update on "Added degrees, radians, ldexp"
Chillee Jun 5, 2019
1dfc14e
Update on "Added degrees, radians, ldexp"
Chillee Jun 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions test/test_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6122,7 +6122,7 @@ def func(a, b):

unary_float_ops = ["log", "log1p", "log10", "exp", "sqrt", "gamma", "lgamma", "erf",
"erfc", "expm1", "fabs", "acos", "asin", "atan", "cos", "sin", "tan",
"asinh", "atanh", "acosh", "sinh", "cosh", "tanh"]
"asinh", "atanh", "acosh", "sinh", "cosh", "tanh", "degrees", "radians"]
binary_float_ops = ["atan2", "fmod", "copysign"]
for op in unary_float_ops:
checkMathWrap(op, 1)
Expand All @@ -6133,6 +6133,8 @@ def func(a, b):
checkMath("frexp", 1, ret_type="Tuple[float, int]")
checkMath("isnan", 1, ret_type="bool")
checkMath("isinf", 1, ret_type="bool")
checkMath("ldexp", 2, is_float=False, ret_type="float", args_type="(float, int)",
vals=[(i, j) for i in float_vals for j in range(-10, 10)])
checkMath("pow", 2, is_float=False, ret_type="int")
checkMath("pow", 2, is_float=True, ret_type="float")
if not PY2:
Expand All @@ -6142,20 +6144,7 @@ def func(a, b):
checkMath("isfinite", 1, ret_type="bool")
if PY37:
checkMathWrap("remainder", 2)
checkMathWrap("factorial", 1, is_float=False, ret_type="int", vals=[(i, i) for i in range(-2, 10)])

@unittest.skipIf(PY2, "Requires python 3")
def test_math_gcd(self):
def test_gcd(x, y):
# type: (int, int) -> int
return math.gcd(x, y)

max_int = 2147483647
min_int = -2147483647 - 1
int_vals = list(range(-5, 5, 1)) + [max_int + 5, max_int * 2, min_int - 5, min_int * 2]
vals = [(i, j) for i in int_vals for j in int_vals]
for inputs in vals:
self.checkScript(test_gcd, inputs)
checkMathWrap("factorial", 1, is_float=False, ret_type="int", vals=[(i, 0) for i in range(-2, 10)])

def test_if_nest_while(self):
def func(a, b):
Expand Down
19 changes: 19 additions & 0 deletions torch/csrc/jit/register_prim_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ int64_t factorial(int n) {
loop(n, p, r);
return r << nminussumofbits(n);
}
static const double degToRad = std::acos(-1.0) / 180.0;
static const double radToDeg = 180.0 / std::acos(-1.0);
double degrees(double x) {
return x * radToDeg;
}
double radians(double x) {
return x * degToRad;
}

// reference function THPVariable_to in python_variable_methods.cpp
static at::Tensor to_dispatch(
Expand Down Expand Up @@ -2208,6 +2216,8 @@ RegisterOperators reg2({
DEFINE_UNARY_OP(aten::sinh, std::sinh(a), float, float),
DEFINE_UNARY_OP(aten::cosh, std::cosh(a), float, float),
DEFINE_UNARY_OP(aten::tanh, std::tanh(a), float, float),
DEFINE_UNARY_OP(aten::degrees, degrees(a), float, float),
DEFINE_UNARY_OP(aten::radians, radians(a), float, float),
DEFINE_BINARY_FLOAT_OP(aten::fmod, std::fmod(a, b)),
DEFINE_UNARY_INT_OP(aten::factorial, factorial(a), int),
DEFINE_UNARY_FLOAT_OP(aten::isnan, std::isnan(a), bool),
Expand All @@ -2234,6 +2244,15 @@ RegisterOperators reg2({
push(stack, m, e);
return 0;
}),
Operator(
"aten::ldexp(float x, int i) -> float",
[](Stack& stack) {
double a;
int64_t b;
pop(stack, a, b);
push(stack, std::ldexp(a, b));
return 0;
}),
DEFINE_BINARY_FLOAT_OP(aten::mathremainder, std::remainder(a, b)),

// TODO: move abs to aten namespace because it's schematized!
Expand Down
3 changes: 3 additions & 0 deletions torch/jit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,9 @@ def register_all(mod):
(math.frexp, "aten::frexp"),
(math.isnan, "aten::isnan"),
(math.isinf, "aten::isinf"),
(math.degrees, "aten::degrees"),
(math.radians, "aten::radians"),
(math.ldexp, "aten::ldexp"),
(torch._C._infer_size, "aten::_infer_size"),
(torch.nn.functional._no_grad_embedding_renorm_, "aten::_no_grad_embedding_renorm_"),
(torch.nn.functional.assert_int_or_pair, "aten::_assert_int_or_pair"),
Expand Down