Unverified 提交 0b632bdb authored 作者: Sudarsan Mansingh's avatar Sudarsan Mansingh 提交者: GitHub

Rename `sgn` to `sign` (#228)

* Rename sgn to sign
上级 c6a754d1
...@@ -196,7 +196,7 @@ List of Implemented Operations ...@@ -196,7 +196,7 @@ List of Implemented Operations
- ``ceil`` - ``ceil``
- ``floor`` - ``floor``
- ``trunc`` - ``trunc``
- ``sgn`` - ``sign``
- ``log1p`` - ``log1p``
- ``expm1`` - ``expm1``
- ``sqr`` - ``sqr``
......
...@@ -1462,7 +1462,7 @@ Mathematical ...@@ -1462,7 +1462,7 @@ Mathematical
Returns a variable representing the base e, 2 or 10 logarithm of a. Returns a variable representing the base e, 2 or 10 logarithm of a.
.. function:: sgn(a) .. function:: sign(a)
Returns a variable representing the sign of a. Returns a variable representing the sign of a.
......
...@@ -1509,7 +1509,7 @@ class ProfileStats: ...@@ -1509,7 +1509,7 @@ class ProfileStats:
aes.Second, aes.Second,
aes.Identity, aes.Identity,
aes.Cast, aes.Cast,
aes.Sgn, aes.Sign,
aes.Neg, aes.Neg,
aes.Reciprocal, aes.Reciprocal,
aes.Sqr, aes.Sqr,
......
...@@ -2566,7 +2566,7 @@ class Abs(UnaryScalarOp): ...@@ -2566,7 +2566,7 @@ class Abs(UnaryScalarOp):
return [x.zeros_like()] return [x.zeros_like()]
if x.type in float_types: if x.type in float_types:
return (gz * sgn(x),) return (gz * sign(x),)
return (gz * x / _abs(x),) # formula works for complex and real return (gz * x / _abs(x),) # formula works for complex and real
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
...@@ -2590,7 +2590,7 @@ class Abs(UnaryScalarOp): ...@@ -2590,7 +2590,7 @@ class Abs(UnaryScalarOp):
abs = Abs(same_out) abs = Abs(same_out)
class Sgn(UnaryScalarOp): class Sign(UnaryScalarOp):
nfunc_spec = ("sign", 1, 1) nfunc_spec = ("sign", 1, 1)
@staticmethod @staticmethod
...@@ -2625,7 +2625,7 @@ class Sgn(UnaryScalarOp): ...@@ -2625,7 +2625,7 @@ class Sgn(UnaryScalarOp):
) )
if type in int_types: if type in int_types:
return f"{z} = ({x} >= 0) ? ({x} == 0) ? 0 : 1 : -1;" return f"{z} = ({x} >= 0) ? ({x} == 0) ? 0 : 1 : -1;"
raise ComplexError("complex has no sgn") raise ComplexError("complex has no sign")
def c_code_cache_version(self): def c_code_cache_version(self):
s = super().c_code_cache_version() s = super().c_code_cache_version()
...@@ -2635,7 +2635,7 @@ class Sgn(UnaryScalarOp): ...@@ -2635,7 +2635,7 @@ class Sgn(UnaryScalarOp):
return s return s
sgn = Sgn(name="sgn") sign = Sign(name="sign")
class Ceil(UnaryScalarOp): class Ceil(UnaryScalarOp):
......
...@@ -36,8 +36,8 @@ from pytensor.tensor.math import pow as at_pow ...@@ -36,8 +36,8 @@ from pytensor.tensor.math import pow as at_pow
from pytensor.tensor.math import ( from pytensor.tensor.math import (
rad2deg, rad2deg,
round_half_to_even, round_half_to_even,
sgn,
sigmoid, sigmoid,
sign,
sin, sin,
sinh, sinh,
sqr, sqr,
...@@ -3184,8 +3184,8 @@ def rint(x): ...@@ -3184,8 +3184,8 @@ def rint(x):
rint.__name__ = "rint" rint.__name__ = "rint"
@structured_monoid(sgn) # type: ignore[no-redef] @structured_monoid(sign) # type: ignore[no-redef]
def sgn(x): def sign(x):
""" """
Elemwise signe of `x`. Elemwise signe of `x`.
......
...@@ -104,7 +104,7 @@ def log10_inplace(a): ...@@ -104,7 +104,7 @@ def log10_inplace(a):
@scalar_elemwise @scalar_elemwise
def sgn_inplace(a): def sign_inplace(a):
"""sign of `a` (inplace on `a`)""" """sign of `a` (inplace on `a`)"""
......
...@@ -982,7 +982,7 @@ def isclose(a, b, rtol=1.0e-5, atol=1.0e-8, equal_nan=False): ...@@ -982,7 +982,7 @@ def isclose(a, b, rtol=1.0e-5, atol=1.0e-8, equal_nan=False):
# deal with signed inf values. this will make an array inf_eq of 0's # deal with signed inf values. this will make an array inf_eq of 0's
# except where inf values have the same sign. # except where inf values have the same sign.
both_infs = bitwise_and(a_inf, b_inf) both_infs = bitwise_and(a_inf, b_inf)
inf_signs_eq = eq(a_inf * sgn(a), b_inf * sgn(b)) inf_signs_eq = eq(a_inf * sign(a), b_inf * sign(b))
inf_eq = bitwise_and(both_infs, inf_signs_eq) inf_eq = bitwise_and(both_infs, inf_signs_eq)
# now create the potential result combining close and inf_eq # now create the potential result combining close and inf_eq
...@@ -1092,9 +1092,19 @@ def log1p(a): ...@@ -1092,9 +1092,19 @@ def log1p(a):
@scalar_elemwise @scalar_elemwise
def sign(a):
"""sign of a"""
def sgn(a): def sgn(a):
"""sign of a""" """sign of a"""
warnings.warn(
"sgn is deprecated and will stop working in the future, use sign instead.",
FutureWarning,
)
return sign(a)
@scalar_elemwise @scalar_elemwise
def ceil(a): def ceil(a):
...@@ -3038,6 +3048,7 @@ __all__ = [ ...@@ -3038,6 +3048,7 @@ __all__ = [
"log10", "log10",
"log1p", "log1p",
"sgn", "sgn",
"sign",
"ceil", "ceil",
"floor", "floor",
"trunc", "trunc",
......
...@@ -72,8 +72,8 @@ from pytensor.tensor.math import pow as at_pow ...@@ -72,8 +72,8 @@ from pytensor.tensor.math import pow as at_pow
from pytensor.tensor.math import ( from pytensor.tensor.math import (
prod, prod,
reciprocal, reciprocal,
sgn,
sigmoid, sigmoid,
sign,
softplus, softplus,
sqr, sqr,
sqrt, sqrt,
...@@ -2289,7 +2289,7 @@ def check_for_x_over_absX(numerators, denominators): ...@@ -2289,7 +2289,7 @@ def check_for_x_over_absX(numerators, denominators):
else: else:
denominators.remove(den) denominators.remove(den)
numerators.remove(den.owner.inputs[0]) numerators.remove(den.owner.inputs[0])
numerators.append(sgn(den.owner.inputs[0])) numerators.append(sign(den.owner.inputs[0]))
return numerators, denominators return numerators, denominators
......
...@@ -199,7 +199,7 @@ def get_canonical_form_slice( ...@@ -199,7 +199,7 @@ def get_canonical_form_slice(
if the resulting set of numbers needs to be reversed or not. if the resulting set of numbers needs to be reversed or not.
""" """
from pytensor.tensor import ge, lt, sgn, switch from pytensor.tensor import ge, lt, sign, switch
if not isinstance(theslice, slice): if not isinstance(theslice, slice):
try: try:
...@@ -317,7 +317,7 @@ def get_canonical_form_slice( ...@@ -317,7 +317,7 @@ def get_canonical_form_slice(
return switch(is_step_neg, a, b) return switch(is_step_neg, a, b)
abs_step = abs(step) abs_step = abs(step)
sgn_step = sgn(step) sgn_step = sign(step)
defstart = switch_neg_step(length - 1, 0) defstart = switch_neg_step(length - 1, 0)
defstop = switch_neg_step(-1, length) defstop = switch_neg_step(-1, length)
......
...@@ -3111,7 +3111,7 @@ RintTester = elemwise_checker( ...@@ -3111,7 +3111,7 @@ RintTester = elemwise_checker(
) )
SgnTester = elemwise_checker( SgnTester = elemwise_checker(
sparse.sgn, sparse.sign,
np.sign, np.sign,
grad_test=False, grad_test=False,
test_dtypes=[ test_dtypes=[
......
...@@ -74,8 +74,8 @@ from pytensor.tensor.math import ( ...@@ -74,8 +74,8 @@ from pytensor.tensor.math import (
prod, prod,
rad2deg, rad2deg,
reciprocal, reciprocal,
sgn,
sigmoid, sigmoid,
sign,
sinh, sinh,
softplus, softplus,
sqr, sqr,
...@@ -877,7 +877,7 @@ class TestAlgebraicCanonizer: ...@@ -877,7 +877,7 @@ class TestAlgebraicCanonizer:
assert np.isfinite(f(0)) assert np.isfinite(f(0))
assert len(f.maker.fgraph.toposort()) == 2 assert len(f.maker.fgraph.toposort()) == 2
assert f.maker.fgraph.toposort()[0].op == sgn assert f.maker.fgraph.toposort()[0].op == sign
f = function([x], [(4 * x) / abs(x / 2)], mode=mode) f = function([x], [(4 * x) / abs(x / 2)], mode=mode)
f(0.1) f(0.1)
...@@ -886,7 +886,7 @@ class TestAlgebraicCanonizer: ...@@ -886,7 +886,7 @@ class TestAlgebraicCanonizer:
assert np.isfinite(f(0)) assert np.isfinite(f(0))
assert len(f.maker.fgraph.toposort()) == 2 assert len(f.maker.fgraph.toposort()) == 2
assert f.maker.fgraph.toposort()[0].op == sgn assert f.maker.fgraph.toposort()[0].op == sign
@pytest.mark.skip( @pytest.mark.skip(
reason="Current implementation of AlgebraicCanonizer does not " reason="Current implementation of AlgebraicCanonizer does not "
......
...@@ -38,7 +38,7 @@ from pytensor.tensor.inplace import ( ...@@ -38,7 +38,7 @@ from pytensor.tensor.inplace import (
reciprocal_inplace, reciprocal_inplace,
round_half_away_from_zero_inplace, round_half_away_from_zero_inplace,
round_half_to_even_inplace, round_half_to_even_inplace,
sgn_inplace, sign_inplace,
sin_inplace, sin_inplace,
sinh_inplace, sinh_inplace,
sqr_inplace, sqr_inplace,
...@@ -177,7 +177,7 @@ TestNegInplaceBroadcast = makeBroadcastTester( ...@@ -177,7 +177,7 @@ TestNegInplaceBroadcast = makeBroadcastTester(
) )
TestSgnInplaceBroadcast = makeBroadcastTester( TestSgnInplaceBroadcast = makeBroadcastTester(
op=sgn_inplace, op=sign_inplace,
expected=np.sign, expected=np.sign,
good=_good_broadcast_unary_normal_no_complex, good=_good_broadcast_unary_normal_no_complex,
inplace=True, inplace=True,
......
...@@ -99,8 +99,8 @@ from pytensor.tensor.math import ( ...@@ -99,8 +99,8 @@ from pytensor.tensor.math import (
reciprocal, reciprocal,
round_half_away_from_zero, round_half_away_from_zero,
round_half_to_even, round_half_to_even,
sgn,
sigmoid, sigmoid,
sign,
sin, sin,
sinh, sinh,
smallest, smallest,
...@@ -386,7 +386,7 @@ TestNegBroadcast = makeBroadcastTester( ...@@ -386,7 +386,7 @@ TestNegBroadcast = makeBroadcastTester(
) )
TestSgnBroadcast = makeBroadcastTester( TestSgnBroadcast = makeBroadcastTester(
op=sgn, op=sign,
expected=np.sign, expected=np.sign,
good=_good_broadcast_unary_normal_no_complex, good=_good_broadcast_unary_normal_no_complex,
grad=_grad_broadcast_unary_normal, grad=_grad_broadcast_unary_normal,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论