Skip to content

Commit 0b632bd

Browse files
authored
Rename sgn to sign (#228)
* Rename sgn to sign
1 parent c6a754d commit 0b632bd

File tree

13 files changed

+35
-24
lines changed

13 files changed

+35
-24
lines changed

doc/library/sparse/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ List of Implemented Operations
196196
- ``ceil``
197197
- ``floor``
198198
- ``trunc``
199-
- ``sgn``
199+
- ``sign``
200200
- ``log1p``
201201
- ``expm1``
202202
- ``sqr``

doc/library/tensor/basic.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ Mathematical
14621462

14631463
Returns a variable representing the base e, 2 or 10 logarithm of a.
14641464

1465-
.. function:: sgn(a)
1465+
.. function:: sign(a)
14661466

14671467
Returns a variable representing the sign of a.
14681468

pytensor/compile/profiling.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ def print_tips(self, file):
15091509
aes.Second,
15101510
aes.Identity,
15111511
aes.Cast,
1512-
aes.Sgn,
1512+
aes.Sign,
15131513
aes.Neg,
15141514
aes.Reciprocal,
15151515
aes.Sqr,

pytensor/scalar/basic.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,7 @@ def L_op(self, inputs, outputs, gout):
25662566
return [x.zeros_like()]
25672567

25682568
if x.type in float_types:
2569-
return (gz * sgn(x),)
2569+
return (gz * sign(x),)
25702570
return (gz * x / _abs(x),) # formula works for complex and real
25712571

25722572
def c_code(self, node, name, inputs, outputs, sub):
@@ -2590,7 +2590,7 @@ def c_code(self, node, name, inputs, outputs, sub):
25902590
abs = Abs(same_out)
25912591

25922592

2593-
class Sgn(UnaryScalarOp):
2593+
class Sign(UnaryScalarOp):
25942594
nfunc_spec = ("sign", 1, 1)
25952595

25962596
@staticmethod
@@ -2625,7 +2625,7 @@ def c_code(self, node, name, inputs, outputs, sub):
26252625
)
26262626
if type in int_types:
26272627
return f"{z} = ({x} >= 0) ? ({x} == 0) ? 0 : 1 : -1;"
2628-
raise ComplexError("complex has no sgn")
2628+
raise ComplexError("complex has no sign")
26292629

26302630
def c_code_cache_version(self):
26312631
s = super().c_code_cache_version()
@@ -2635,7 +2635,7 @@ def c_code_cache_version(self):
26352635
return s
26362636

26372637

2638-
sgn = Sgn(name="sgn")
2638+
sign = Sign(name="sign")
26392639

26402640

26412641
class Ceil(UnaryScalarOp):

pytensor/sparse/basic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
from pytensor.tensor.math import (
3737
rad2deg,
3838
round_half_to_even,
39-
sgn,
4039
sigmoid,
40+
sign,
4141
sin,
4242
sinh,
4343
sqr,
@@ -3184,8 +3184,8 @@ def rint(x):
31843184
rint.__name__ = "rint"
31853185

31863186

3187-
@structured_monoid(sgn) # type: ignore[no-redef]
3188-
def sgn(x):
3187+
@structured_monoid(sign) # type: ignore[no-redef]
3188+
def sign(x):
31893189
"""
31903190
Elemwise signe of `x`.
31913191

pytensor/tensor/inplace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def log10_inplace(a):
104104

105105

106106
@scalar_elemwise
107-
def sgn_inplace(a):
107+
def sign_inplace(a):
108108
"""sign of `a` (inplace on `a`)"""
109109

110110

pytensor/tensor/math.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ def isclose(a, b, rtol=1.0e-5, atol=1.0e-8, equal_nan=False):
982982
# deal with signed inf values. this will make an array inf_eq of 0's
983983
# except where inf values have the same sign.
984984
both_infs = bitwise_and(a_inf, b_inf)
985-
inf_signs_eq = eq(a_inf * sgn(a), b_inf * sgn(b))
985+
inf_signs_eq = eq(a_inf * sign(a), b_inf * sign(b))
986986
inf_eq = bitwise_and(both_infs, inf_signs_eq)
987987

988988
# now create the potential result combining close and inf_eq
@@ -1092,9 +1092,19 @@ def log1p(a):
10921092

10931093

10941094
@scalar_elemwise
1095+
def sign(a):
1096+
"""sign of a"""
1097+
1098+
10951099
def sgn(a):
10961100
"""sign of a"""
10971101

1102+
warnings.warn(
1103+
"sgn is deprecated and will stop working in the future, use sign instead.",
1104+
FutureWarning,
1105+
)
1106+
return sign(a)
1107+
10981108

10991109
@scalar_elemwise
11001110
def ceil(a):
@@ -3038,6 +3048,7 @@ def matmul(x1: "ArrayLike", x2: "ArrayLike", dtype: Optional["DTypeLike"] = None
30383048
"log10",
30393049
"log1p",
30403050
"sgn",
3051+
"sign",
30413052
"ceil",
30423053
"floor",
30433054
"trunc",

pytensor/tensor/rewriting/math.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
from pytensor.tensor.math import (
7373
prod,
7474
reciprocal,
75-
sgn,
7675
sigmoid,
76+
sign,
7777
softplus,
7878
sqr,
7979
sqrt,
@@ -2289,7 +2289,7 @@ def check_for_x_over_absX(numerators, denominators):
22892289
else:
22902290
denominators.remove(den)
22912291
numerators.remove(den.owner.inputs[0])
2292-
numerators.append(sgn(den.owner.inputs[0]))
2292+
numerators.append(sign(den.owner.inputs[0]))
22932293
return numerators, denominators
22942294

22952295

pytensor/tensor/subtensor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def get_canonical_form_slice(
199199
if the resulting set of numbers needs to be reversed or not.
200200
201201
"""
202-
from pytensor.tensor import ge, lt, sgn, switch
202+
from pytensor.tensor import ge, lt, sign, switch
203203

204204
if not isinstance(theslice, slice):
205205
try:
@@ -317,7 +317,7 @@ def switch_neg_step(a, b):
317317
return switch(is_step_neg, a, b)
318318

319319
abs_step = abs(step)
320-
sgn_step = sgn(step)
320+
sgn_step = sign(step)
321321

322322
defstart = switch_neg_step(length - 1, 0)
323323
defstop = switch_neg_step(-1, length)

tests/sparse/test_basic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3111,7 +3111,7 @@ def structured_function(*args):
31113111
)
31123112

31133113
SgnTester = elemwise_checker(
3114-
sparse.sgn,
3114+
sparse.sign,
31153115
np.sign,
31163116
grad_test=False,
31173117
test_dtypes=[

tests/tensor/rewriting/test_math.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
prod,
7575
rad2deg,
7676
reciprocal,
77-
sgn,
7877
sigmoid,
78+
sign,
7979
sinh,
8080
softplus,
8181
sqr,
@@ -877,7 +877,7 @@ def test_abs_mul_div(self):
877877
assert np.isfinite(f(0))
878878

879879
assert len(f.maker.fgraph.toposort()) == 2
880-
assert f.maker.fgraph.toposort()[0].op == sgn
880+
assert f.maker.fgraph.toposort()[0].op == sign
881881

882882
f = function([x], [(4 * x) / abs(x / 2)], mode=mode)
883883
f(0.1)
@@ -886,7 +886,7 @@ def test_abs_mul_div(self):
886886
assert np.isfinite(f(0))
887887

888888
assert len(f.maker.fgraph.toposort()) == 2
889-
assert f.maker.fgraph.toposort()[0].op == sgn
889+
assert f.maker.fgraph.toposort()[0].op == sign
890890

891891
@pytest.mark.skip(
892892
reason="Current implementation of AlgebraicCanonizer does not "

tests/tensor/test_inplace.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
reciprocal_inplace,
3939
round_half_away_from_zero_inplace,
4040
round_half_to_even_inplace,
41-
sgn_inplace,
41+
sign_inplace,
4242
sin_inplace,
4343
sinh_inplace,
4444
sqr_inplace,
@@ -177,7 +177,7 @@
177177
)
178178

179179
TestSgnInplaceBroadcast = makeBroadcastTester(
180-
op=sgn_inplace,
180+
op=sign_inplace,
181181
expected=np.sign,
182182
good=_good_broadcast_unary_normal_no_complex,
183183
inplace=True,

tests/tensor/test_math.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
reciprocal,
100100
round_half_away_from_zero,
101101
round_half_to_even,
102-
sgn,
103102
sigmoid,
103+
sign,
104104
sin,
105105
sinh,
106106
smallest,
@@ -386,7 +386,7 @@ def test_maximum_minimum_grad():
386386
)
387387

388388
TestSgnBroadcast = makeBroadcastTester(
389-
op=sgn,
389+
op=sign,
390390
expected=np.sign,
391391
good=_good_broadcast_unary_normal_no_complex,
392392
grad=_grad_broadcast_unary_normal,

0 commit comments

Comments
 (0)