Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e642052b
提交
e642052b
authored
8月 06, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #811 from bouchnic/new_elemwise
New elemwise NEWS.txt: NB added elemwise Trunc, Deg2Rad, Rad2Deg and Expm1
上级
c8460fbb
b95bea68
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
164 行增加
和
0 行删除
+164
-0
basic.py
theano/scalar/basic.py
+69
-0
basic.py
theano/tensor/basic.py
+20
-0
inplace.py
theano/tensor/inplace.py
+16
-0
test_basic.py
theano/tensor/tests/test_basic.py
+59
-0
没有找到文件。
theano/scalar/basic.py
浏览文件 @
e642052b
...
...
@@ -1722,6 +1722,18 @@ class Floor(UnaryScalarOp):
floor
=
Floor
(
same_out_nocomplex
,
name
=
'floor'
)
class
Trunc
(
UnaryScalarOp
):
def
impl
(
self
,
x
):
return
numpy
.
trunc
(
x
)
def
grad
(
self
,
(
x
,),
(
gz
,)):
return
None
,
def
c_code
(
self
,
node
,
name
,
(
x
,),
(
z
,),
sub
):
return
"
%(z)
s =
%(x)
s >= 0? floor(
%(x)
s): -floor(-
%(x)
s);"
%
locals
()
trunc
=
Trunc
(
same_out_nocomplex
,
name
=
'trunc'
)
class
RoundHalfToEven
(
UnaryScalarOp
):
"""
This function implement the same rounding than numpy: Round half to even
...
...
@@ -1978,6 +1990,25 @@ class Exp2(UnaryScalarOp):
exp2
=
Exp2
(
upgrade_to_float
,
name
=
'exp2'
)
class
Expm1
(
UnaryScalarOp
):
def
impl
(
self
,
x
):
return
numpy
.
expm1
(
x
)
def
grad
(
self
,
(
x
,
),
(
gz
,
)):
if
x
.
type
in
complex_types
:
raise
NotImplementedError
()
elif
x
.
type
in
float_types
:
return
gz
*
exp
(
x
),
else
:
return
None
,
def
c_code
(
self
,
node
,
name
,
(
x
,
),
(
z
,
),
sub
):
if
node
.
inputs
[
0
]
.
type
in
complex_types
:
raise
NotImplementedError
(
'type not supported'
,
type
)
return
"
%(z)
s = exp(
%(x)
s) - 1;"
%
locals
()
expm1
=
Expm1
(
upgrade_to_float
,
name
=
'expm1'
)
class
Sqr
(
UnaryScalarOp
):
def
impl
(
self
,
x
):
return
x
*
x
...
...
@@ -2014,6 +2045,44 @@ class Sqrt(UnaryScalarOp):
sqrt
=
Sqrt
(
upgrade_to_float
,
name
=
'sqrt'
)
class
Deg2Rad
(
UnaryScalarOp
):
def
impl
(
self
,
x
):
return
numpy
.
deg2rad
(
x
)
def
grad
(
self
,
(
x
,),
(
gz
,)):
if
gz
.
type
in
complex_types
:
raise
NotImplementedError
()
if
x
.
type
in
float_types
:
return
gz
*
numpy
.
asarray
(
numpy
.
pi
/
180
,
gz
.
type
),
else
:
return
None
,
def
c_code
(
self
,
node
,
name
,
(
x
,),
(
z
,),
sub
):
if
node
.
inputs
[
0
]
.
type
in
complex_types
:
raise
NotImplementedError
(
'type not supported'
,
type
)
return
"
%(z)
s =
%(x)
s * (M_PI / 180.0);"
%
locals
()
deg2rad
=
Deg2Rad
(
upgrade_to_float
,
name
=
'deg2rad'
)
class
Rad2Deg
(
UnaryScalarOp
):
def
impl
(
self
,
x
):
return
numpy
.
rad2deg
(
x
)
def
grad
(
self
,
(
x
,),
(
gz
,)):
if
gz
.
type
in
complex_types
:
raise
NotImplementedError
()
if
x
.
type
in
float_types
:
return
gz
*
numpy
.
asarray
(
180.
/
numpy
.
pi
,
gz
.
type
),
else
:
return
None
,
def
c_code
(
self
,
node
,
name
,
(
x
,),
(
z
,),
sub
):
if
node
.
inputs
[
0
]
.
type
in
complex_types
:
raise
NotImplementedError
(
'type not supported'
,
type
)
return
"
%(z)
s =
%(x)
s * (180.0 / M_PI);"
%
locals
()
rad2deg
=
Rad2Deg
(
upgrade_to_float
,
name
=
'rad2deg'
)
class
Cos
(
UnaryScalarOp
):
def
impl
(
self
,
x
):
return
numpy
.
cos
(
x
)
...
...
theano/tensor/basic.py
浏览文件 @
e642052b
...
...
@@ -2585,6 +2585,11 @@ def exp2(a):
"""2^`a`"""
@_scal_elemwise_with_nfunc
(
'expm1'
,
1
,
1
)
def
expm1
(
a
):
"""e^`a` - 1"""
@_scal_elemwise_with_nfunc
(
'negative'
,
1
,
1
)
def
neg
(
a
):
"""-a"""
...
...
@@ -2632,6 +2637,11 @@ def floor(a):
"""floor of a"""
@_scal_elemwise_with_nfunc
(
'trunc'
,
1
,
1
)
def
trunc
(
a
):
"""trunc of a"""
@constructor
def
iround
(
a
,
mode
=
"half_away_from_zero"
):
"""cast(round(a,mode),'int64')"""
...
...
@@ -2673,6 +2683,16 @@ def sqrt(a):
"""square root of a"""
@_scal_elemwise_with_nfunc
(
'deg2rad'
,
1
,
1
)
def
deg2rad
(
a
):
"""convert degree a to radian"""
@_scal_elemwise_with_nfunc
(
'rad2deg'
,
1
,
1
)
def
rad2deg
(
a
):
"""convert radian a to degree"""
@_scal_elemwise_with_nfunc
(
'cos'
,
1
,
1
)
def
cos
(
a
):
"""cosine of a"""
...
...
theano/tensor/inplace.py
浏览文件 @
e642052b
...
...
@@ -91,6 +91,10 @@ def exp_inplace(a):
def
exp2_inplace
(
a
):
"""2^`a` (inplace on `a`)"""
@_scal_inplace
def
expm1_inplace
(
a
):
"""e^`a` - 1 (inplace on `a`)"""
@_scal_inplace
def
neg_inplace
(
a
):
"""-a (inplace on a)"""
...
...
@@ -127,6 +131,10 @@ def ceil_inplace(a):
def
floor_inplace
(
a
):
"""floor of `a` (inplace on `a`)"""
@_scal_inplace
def
trunc_inplace
(
a
):
"""trunc of `a` (inplace on `a`)"""
@_scal_inplace
def
round_half_to_even_inplace
(
a
):
"""round_half_to_even_inplace(a) (inplace on `a`)"""
...
...
@@ -143,6 +151,14 @@ def sqr_inplace(a):
def
sqrt_inplace
(
a
):
"""square root of `a` (inplace on `a`)"""
@_scal_inplace
def
deg2rad_inplace
(
a
):
"""convert degree `a` to radian(inplace on `a`)"""
@_scal_inplace
def
rad2deg_inplace
(
a
):
"""convert radian `a` to degree(inplace on `a`)"""
@_scal_inplace
def
cos_inplace
(
a
):
"""cosine of `a` (inplace on `a`)"""
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
e642052b
...
...
@@ -810,6 +810,10 @@ _good_broadcast_unary_normal_no_complex = dict(
empty
=
[
numpy
.
asarray
([])],
)
_grad_broadcast_unary_normal_no_complex
=
dict
(
normal
=
[
numpy
.
asarray
(
rand_ranged
(
-
5
,
5
,
(
2
,
3
)),
dtype
=
floatX
)],
corner_case
=
[
corner_case_grad
])
_grad_broadcast_unary_normal
=
dict
(
normal
=
[
numpy
.
asarray
(
rand_ranged
(
-
5
,
5
,
(
2
,
3
)),
dtype
=
floatX
)],
corner_case
=
[
corner_case_grad
],
...
...
@@ -905,6 +909,16 @@ FloorTester = makeBroadcastTester(op=tensor.floor,
# yet it does not...
grad
=
_grad_broadcast_unary_normal
)
TruncInplaceTester
=
makeBroadcastTester
(
op
=
inplace
.
floor_inplace
,
expected
=
lambda
a
:
numpy
.
asarray
(
numpy
.
floor
(
a
),
a
.
dtype
),
good
=
_good_broadcast_unary_normal_no_complex
,
inplace
=
True
)
TruncTester
=
makeBroadcastTester
(
op
=
tensor
.
floor
,
expected
=
lambda
a
:
numpy
.
asarray
(
numpy
.
floor
(
a
),
a
.
dtype
),
good
=
_good_broadcast_unary_normal_no_complex
)
FloorInplaceTester
=
makeBroadcastTester
(
op
=
inplace
.
floor_inplace
,
expected
=
lambda
a
:
numpy
.
asarray
(
numpy
.
floor
(
a
),
a
.
dtype
),
good
=
_good_broadcast_unary_normal_no_complex
,
...
...
@@ -966,6 +980,18 @@ Exp2InplaceTester = makeBroadcastTester(op=inplace.exp2_inplace,
grad
=
_grad_broadcast_unary_normal
,
inplace
=
True
)
Expm1Tester
=
makeBroadcastTester
(
op
=
tensor
.
expm1
,
expected
=
numpy
.
expm1
,
good
=
_good_broadcast_unary_normal
,
grad
=
_grad_broadcast_unary_normal
)
Expm1InplaceTester
=
makeBroadcastTester
(
op
=
inplace
.
expm1_inplace
,
expected
=
numpy
.
expm1
,
good
=
_good_broadcast_unary_normal
,
grad
=
_grad_broadcast_unary_normal
,
inplace
=
True
)
_good_broadcast_unary_positive
=
dict
(
normal
=
(
rand_ranged
(
0.001
,
5
,
(
2
,
3
)),),
integers
=
(
randint_ranged
(
1
,
5
,
(
2
,
3
)),),
complex
=
(
randc128_ranged
(
1
,
5
,
(
2
,
3
)),),
...
...
@@ -1031,6 +1057,39 @@ _good_broadcast_unary_wide = dict(
empty
=
(
numpy
.
asarray
([]),),)
_grad_broadcast_unary_wide
=
dict
(
normal
=
(
rand_ranged
(
-
1000
,
1000
,
(
2
,
3
)),),)
if
theano
.
config
.
floatX
==
'float32'
:
angle_eps
=
1e-4
else
:
angle_eps
=
1e-10
Deg2RadTester
=
makeBroadcastTester
(
op
=
tensor
.
deg2rad
,
expected
=
numpy
.
deg2rad
,
good
=
_good_broadcast_unary_normal_no_complex
,
grad
=
_grad_broadcast_unary_normal_no_complex
,
eps
=
angle_eps
)
Deg2RadInplaceTester
=
makeBroadcastTester
(
op
=
inplace
.
deg2rad_inplace
,
expected
=
numpy
.
deg2rad
,
good
=
_good_broadcast_unary_normal_no_complex
,
grad
=
_grad_broadcast_unary_normal_no_complex
,
inplace
=
True
,
eps
=
angle_eps
)
Rad2DegTester
=
makeBroadcastTester
(
op
=
tensor
.
rad2deg
,
expected
=
numpy
.
rad2deg
,
good
=
_good_broadcast_unary_normal_no_complex
,
grad
=
_grad_broadcast_unary_normal_no_complex
,
eps
=
angle_eps
)
Rad2DegInplaceTester
=
makeBroadcastTester
(
op
=
inplace
.
rad2deg_inplace
,
expected
=
numpy
.
rad2deg
,
good
=
_good_broadcast_unary_normal_no_complex
,
grad
=
_grad_broadcast_unary_normal_no_complex
,
inplace
=
True
,
eps
=
angle_eps
)
SinTester
=
makeBroadcastTester
(
op
=
tensor
.
sin
,
expected
=
numpy
.
sin
,
good
=
_good_broadcast_unary_wide
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论