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
- ``ceil``
- ``floor``
- ``trunc``
- ``sgn``
- ``sign``
- ``log1p``
- ``expm1``
- ``sqr``
......
......@@ -1462,7 +1462,7 @@ Mathematical
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.
......
......@@ -1509,7 +1509,7 @@ class ProfileStats:
aes.Second,
aes.Identity,
aes.Cast,
aes.Sgn,
aes.Sign,
aes.Neg,
aes.Reciprocal,
aes.Sqr,
......
......@@ -2566,7 +2566,7 @@ class Abs(UnaryScalarOp):
return [x.zeros_like()]
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
def c_code(self, node, name, inputs, outputs, sub):
......@@ -2590,7 +2590,7 @@ class Abs(UnaryScalarOp):
abs = Abs(same_out)
class Sgn(UnaryScalarOp):
class Sign(UnaryScalarOp):
nfunc_spec = ("sign", 1, 1)
@staticmethod
......@@ -2625,7 +2625,7 @@ class Sgn(UnaryScalarOp):
)
if type in int_types:
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):
s = super().c_code_cache_version()
......@@ -2635,7 +2635,7 @@ class Sgn(UnaryScalarOp):
return s
sgn = Sgn(name="sgn")
sign = Sign(name="sign")
class Ceil(UnaryScalarOp):
......
......@@ -36,8 +36,8 @@ from pytensor.tensor.math import pow as at_pow
from pytensor.tensor.math import (
rad2deg,
round_half_to_even,
sgn,
sigmoid,
sign,
sin,
sinh,
sqr,
......@@ -3184,8 +3184,8 @@ def rint(x):
rint.__name__ = "rint"
@structured_monoid(sgn) # type: ignore[no-redef]
def sgn(x):
@structured_monoid(sign) # type: ignore[no-redef]
def sign(x):
"""
Elemwise signe of `x`.
......
......@@ -104,7 +104,7 @@ def log10_inplace(a):
@scalar_elemwise
def sgn_inplace(a):
def sign_inplace(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):
# deal with signed inf values. this will make an array inf_eq of 0's
# except where inf values have the same sign.
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)
# now create the potential result combining close and inf_eq
......@@ -1092,9 +1092,19 @@ def log1p(a):
@scalar_elemwise
def sign(a):
"""sign of a"""
def sgn(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
def ceil(a):
......@@ -3038,6 +3048,7 @@ __all__ = [
"log10",
"log1p",
"sgn",
"sign",
"ceil",
"floor",
"trunc",
......
......@@ -72,8 +72,8 @@ from pytensor.tensor.math import pow as at_pow
from pytensor.tensor.math import (
prod,
reciprocal,
sgn,
sigmoid,
sign,
softplus,
sqr,
sqrt,
......@@ -2289,7 +2289,7 @@ def check_for_x_over_absX(numerators, denominators):
else:
denominators.remove(den)
numerators.remove(den.owner.inputs[0])
numerators.append(sgn(den.owner.inputs[0]))
numerators.append(sign(den.owner.inputs[0]))
return numerators, denominators
......
......@@ -199,7 +199,7 @@ def get_canonical_form_slice(
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):
try:
......@@ -317,7 +317,7 @@ def get_canonical_form_slice(
return switch(is_step_neg, a, b)
abs_step = abs(step)
sgn_step = sgn(step)
sgn_step = sign(step)
defstart = switch_neg_step(length - 1, 0)
defstop = switch_neg_step(-1, length)
......
......@@ -3111,7 +3111,7 @@ RintTester = elemwise_checker(
)
SgnTester = elemwise_checker(
sparse.sgn,
sparse.sign,
np.sign,
grad_test=False,
test_dtypes=[
......
......@@ -74,8 +74,8 @@ from pytensor.tensor.math import (
prod,
rad2deg,
reciprocal,
sgn,
sigmoid,
sign,
sinh,
softplus,
sqr,
......@@ -877,7 +877,7 @@ class TestAlgebraicCanonizer:
assert np.isfinite(f(0))
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(0.1)
......@@ -886,7 +886,7 @@ class TestAlgebraicCanonizer:
assert np.isfinite(f(0))
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(
reason="Current implementation of AlgebraicCanonizer does not "
......
......@@ -38,7 +38,7 @@ from pytensor.tensor.inplace import (
reciprocal_inplace,
round_half_away_from_zero_inplace,
round_half_to_even_inplace,
sgn_inplace,
sign_inplace,
sin_inplace,
sinh_inplace,
sqr_inplace,
......@@ -177,7 +177,7 @@ TestNegInplaceBroadcast = makeBroadcastTester(
)
TestSgnInplaceBroadcast = makeBroadcastTester(
op=sgn_inplace,
op=sign_inplace,
expected=np.sign,
good=_good_broadcast_unary_normal_no_complex,
inplace=True,
......
......@@ -99,8 +99,8 @@ from pytensor.tensor.math import (
reciprocal,
round_half_away_from_zero,
round_half_to_even,
sgn,
sigmoid,
sign,
sin,
sinh,
smallest,
......@@ -386,7 +386,7 @@ TestNegBroadcast = makeBroadcastTester(
)
TestSgnBroadcast = makeBroadcastTester(
op=sgn,
op=sign,
expected=np.sign,
good=_good_broadcast_unary_normal_no_complex,
grad=_grad_broadcast_unary_normal,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论