Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0b632bdb
Unverified
提交
0b632bdb
authored
3月 06, 2023
作者:
Sudarsan Mansingh
提交者:
GitHub
3月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename `sgn` to `sign` (#228)
* Rename sgn to sign
上级
c6a754d1
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
35 行增加
和
24 行删除
+35
-24
index.rst
doc/library/sparse/index.rst
+1
-1
basic.rst
doc/library/tensor/basic.rst
+1
-1
profiling.py
pytensor/compile/profiling.py
+1
-1
basic.py
pytensor/scalar/basic.py
+4
-4
basic.py
pytensor/sparse/basic.py
+3
-3
inplace.py
pytensor/tensor/inplace.py
+1
-1
math.py
pytensor/tensor/math.py
+12
-1
math.py
pytensor/tensor/rewriting/math.py
+2
-2
subtensor.py
pytensor/tensor/subtensor.py
+2
-2
test_basic.py
tests/sparse/test_basic.py
+1
-1
test_math.py
tests/tensor/rewriting/test_math.py
+3
-3
test_inplace.py
tests/tensor/test_inplace.py
+2
-2
test_math.py
tests/tensor/test_math.py
+2
-2
没有找到文件。
doc/library/sparse/index.rst
浏览文件 @
0b632bdb
...
...
@@ -196,7 +196,7 @@ List of Implemented Operations
- ``ceil``
- ``floor``
- ``trunc``
- ``sgn``
- ``s
i
gn``
- ``log1p``
- ``expm1``
- ``sqr``
...
...
doc/library/tensor/basic.rst
浏览文件 @
0b632bdb
...
...
@@ -1462,7 +1462,7 @@ Mathematical
Returns a variable representing the base e, 2 or 10 logarithm of a.
.. function:: sgn(a)
.. function:: s
i
gn(a)
Returns a variable representing the sign of a.
...
...
pytensor/compile/profiling.py
浏览文件 @
0b632bdb
...
...
@@ -1509,7 +1509,7 @@ class ProfileStats:
aes
.
Second
,
aes
.
Identity
,
aes
.
Cast
,
aes
.
Sgn
,
aes
.
S
i
gn
,
aes
.
Neg
,
aes
.
Reciprocal
,
aes
.
Sqr
,
...
...
pytensor/scalar/basic.py
浏览文件 @
0b632bdb
...
...
@@ -2566,7 +2566,7 @@ class Abs(UnaryScalarOp):
return
[
x
.
zeros_like
()]
if
x
.
type
in
float_types
:
return
(
gz
*
sgn
(
x
),)
return
(
gz
*
s
i
gn
(
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
S
i
gn
(
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 s
i
gn"
)
def
c_code_cache_version
(
self
):
s
=
super
()
.
c_code_cache_version
()
...
...
@@ -2635,7 +2635,7 @@ class Sgn(UnaryScalarOp):
return
s
s
gn
=
Sgn
(
name
=
"s
gn"
)
s
ign
=
Sign
(
name
=
"si
gn"
)
class
Ceil
(
UnaryScalarOp
):
...
...
pytensor/sparse/basic.py
浏览文件 @
0b632bdb
...
...
@@ -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
(
s
i
gn
)
# type: ignore[no-redef]
def
s
i
gn
(
x
):
"""
Elemwise signe of `x`.
...
...
pytensor/tensor/inplace.py
浏览文件 @
0b632bdb
...
...
@@ -104,7 +104,7 @@ def log10_inplace(a):
@scalar_elemwise
def
sgn_inplace
(
a
):
def
s
i
gn_inplace
(
a
):
"""sign of `a` (inplace on `a`)"""
...
...
pytensor/tensor/math.py
浏览文件 @
0b632bdb
...
...
@@ -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
*
s
gn
(
a
),
b_inf
*
s
gn
(
b
))
inf_signs_eq
=
eq
(
a_inf
*
s
ign
(
a
),
b_inf
*
si
gn
(
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"
,
...
...
pytensor/tensor/rewriting/math.py
浏览文件 @
0b632bdb
...
...
@@ -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
(
s
i
gn
(
den
.
owner
.
inputs
[
0
]))
return
numerators
,
denominators
...
...
pytensor/tensor/subtensor.py
浏览文件 @
0b632bdb
...
...
@@ -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
,
s
i
gn
,
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
=
s
i
gn
(
step
)
defstart
=
switch_neg_step
(
length
-
1
,
0
)
defstop
=
switch_neg_step
(
-
1
,
length
)
...
...
tests/sparse/test_basic.py
浏览文件 @
0b632bdb
...
...
@@ -3111,7 +3111,7 @@ RintTester = elemwise_checker(
)
SgnTester
=
elemwise_checker
(
sparse
.
sgn
,
sparse
.
s
i
gn
,
np
.
sign
,
grad_test
=
False
,
test_dtypes
=
[
...
...
tests/tensor/rewriting/test_math.py
浏览文件 @
0b632bdb
...
...
@@ -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
==
s
i
gn
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
==
s
i
gn
@pytest.mark.skip
(
reason
=
"Current implementation of AlgebraicCanonizer does not "
...
...
tests/tensor/test_inplace.py
浏览文件 @
0b632bdb
...
...
@@ -38,7 +38,7 @@ from pytensor.tensor.inplace import (
reciprocal_inplace
,
round_half_away_from_zero_inplace
,
round_half_to_even_inplace
,
sgn_inplace
,
s
i
gn_inplace
,
sin_inplace
,
sinh_inplace
,
sqr_inplace
,
...
...
@@ -177,7 +177,7 @@ TestNegInplaceBroadcast = makeBroadcastTester(
)
TestSgnInplaceBroadcast
=
makeBroadcastTester
(
op
=
sgn_inplace
,
op
=
s
i
gn_inplace
,
expected
=
np
.
sign
,
good
=
_good_broadcast_unary_normal_no_complex
,
inplace
=
True
,
...
...
tests/tensor/test_math.py
浏览文件 @
0b632bdb
...
...
@@ -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
=
s
i
gn
,
expected
=
np
.
sign
,
good
=
_good_broadcast_unary_normal_no_complex
,
grad
=
_grad_broadcast_unary_normal
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论