Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6add7735
提交
6add7735
authored
4月 06, 2013
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed crash for unimplemented elemwise gradient
This bug was reported by Michael McNeil Forbes on the mailing-list.
上级
3478b646
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
43 行增加
和
13 行删除
+43
-13
elemwise.py
theano/tensor/elemwise.py
+1
-1
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+42
-12
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
6add7735
...
@@ -758,7 +758,7 @@ class Elemwise(Op):
...
@@ -758,7 +758,7 @@ class Elemwise(Op):
def
transform
(
r
):
def
transform
(
r
):
# From a graph of ScalarOps, make a graph of Broadcast ops.
# From a graph of ScalarOps, make a graph of Broadcast ops.
if
isinstance
(
r
.
type
,
DisconnectedType
):
if
isinstance
(
r
.
type
,
(
NullType
,
DisconnectedType
)
):
return
r
return
r
if
r
in
scalar_inputs
:
if
r
in
scalar_inputs
:
return
inputs
[
scalar_inputs
.
index
(
r
)]
return
inputs
[
scalar_inputs
.
index
(
r
)]
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
6add7735
...
@@ -97,7 +97,8 @@ class test_DimShuffle(unittest_tools.InferShapeTester):
...
@@ -97,7 +97,8 @@ class test_DimShuffle(unittest_tools.InferShapeTester):
x
=
tensor
.
dscalar
()
x
=
tensor
.
dscalar
()
y
=
x
.
dimshuffle
((
'x'
,)
*
(
numpy
.
MAXDIMS
+
1
))
y
=
x
.
dimshuffle
((
'x'
,)
*
(
numpy
.
MAXDIMS
+
1
))
self
.
assertRaises
(
ValueError
,
y
.
eval
,
{
x
:
0
})
self
.
assertRaises
(
ValueError
,
y
.
eval
,
{
x
:
0
})
class
test_Broadcast
(
unittest
.
TestCase
):
class
test_Broadcast
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
unittest_tools
.
seed_rng
()
unittest_tools
.
seed_rng
()
...
@@ -749,7 +750,8 @@ class T_mean_dtype(unittest.TestCase):
...
@@ -749,7 +750,8 @@ class T_mean_dtype(unittest.TestCase):
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
x
=
tensor
.
matrix
(
dtype
=
input_dtype
)
for
sum_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
for
sum_dtype
in
imap
(
str
,
theano
.
scalar
.
all_types
):
axis
=
axes
[
idx
%
len
(
axes
)]
axis
=
axes
[
idx
%
len
(
axes
)]
# If the inner sum cannot be created, it will raise a TypeError.
# If the inner sum cannot be created, it will raise a
# TypeError.
try
:
try
:
mean_var
=
x
.
mean
(
dtype
=
sum_dtype
,
axis
=
axis
)
mean_var
=
x
.
mean
(
dtype
=
sum_dtype
,
axis
=
axis
)
except
TypeError
:
except
TypeError
:
...
@@ -757,10 +759,11 @@ class T_mean_dtype(unittest.TestCase):
...
@@ -757,10 +759,11 @@ class T_mean_dtype(unittest.TestCase):
else
:
else
:
# Executed if no TypeError was raised
# Executed if no TypeError was raised
if
sum_dtype
in
tensor
.
discrete_dtypes
:
if
sum_dtype
in
tensor
.
discrete_dtypes
:
assert
mean_var
.
dtype
==
'float64'
,
(
mean_var
.
dtype
,
sum_dtype
)
assert
mean_var
.
dtype
==
'float64'
,
(
(
mean_var
.
dtype
,
sum_dtype
))
else
:
else
:
assert
mean_var
.
dtype
==
sum_dtype
,
(
mean_var
.
dtype
,
sum_dtype
)
assert
mean_var
.
dtype
==
sum_dtype
,
(
(
mean_var
.
dtype
,
sum_dtype
))
# Check that we can take the gradient, when implemented
# Check that we can take the gradient, when implemented
if
"complex"
in
mean_var
.
dtype
:
if
"complex"
in
mean_var
.
dtype
:
continue
continue
...
@@ -920,7 +923,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -920,7 +923,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
def
test_prod_without_zeros_custom_dtype
(
self
):
def
test_prod_without_zeros_custom_dtype
(
self
):
"""
"""
Test
the
ability to provide your own output dtype for a ProdWithoutZeros().
Test ability to provide your own output dtype for a ProdWithoutZeros().
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
...
@@ -936,7 +939,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
...
@@ -936,7 +939,7 @@ class T_prod_without_zeros_dtype(unittest.TestCase):
def
test_prod_without_zeros_custom_acc_dtype
(
self
):
def
test_prod_without_zeros_custom_acc_dtype
(
self
):
"""
"""
Test
the
ability to provide your own acc_dtype for a ProdWithoutZeros().
Test ability to provide your own acc_dtype for a ProdWithoutZeros().
"""
"""
# We try multiple axis combinations even though axis should not matter.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
axes
=
[
None
,
0
,
1
,
[
0
],
[
1
],
[
0
,
1
]]
...
@@ -1000,7 +1003,8 @@ def test_gt_grad():
...
@@ -1000,7 +1003,8 @@ def test_gt_grad():
T
=
theano
.
tensor
T
=
theano
.
tensor
input_
=
T
.
vector
(
dtype
=
floatX
)
input_
=
T
.
vector
(
dtype
=
floatX
)
random_values
=
numpy
.
random
.
RandomState
(
1234
)
.
uniform
(
low
=-
1
,
high
=
1
,
size
=
(
2
,
2
))
random_values
=
numpy
.
random
.
RandomState
(
1234
)
.
uniform
(
low
=-
1
,
high
=
1
,
size
=
(
2
,
2
))
W_values
=
numpy
.
asarray
(
random_values
,
dtype
=
floatX
)
W_values
=
numpy
.
asarray
(
random_values
,
dtype
=
floatX
)
W
=
theano
.
shared
(
value
=
W_values
,
name
=
'weights'
)
W
=
theano
.
shared
(
value
=
W_values
,
name
=
'weights'
)
correct_score
=
T
.
dot
(
input_
,
W
)
correct_score
=
T
.
dot
(
input_
,
W
)
...
@@ -1022,15 +1026,17 @@ if __name__ == '__main__':
...
@@ -1022,15 +1026,17 @@ if __name__ == '__main__':
unittest.TextTestRunner().run(suite)
unittest.TextTestRunner().run(suite)
"""
"""
def
test_clip_grad
():
def
test_clip_grad
():
# test the gradient of clip
# test the gradient of clip
def
func
(
x
,
y
,
z
):
def
func
(
x
,
y
,
z
):
return
theano
.
tensor
.
clip
(
x
,
y
,
z
)
return
theano
.
tensor
.
clip
(
x
,
y
,
z
)
# use an x value less than y, an x value between y and z, and an x value
# use an x value less than y, an x value between y and z, and an x value
# greater than z
# greater than z
unittest_tools
.
verify_grad
(
func
,
unittest_tools
.
verify_grad
(
func
,
[
numpy
.
asarray
([
-
1.
,
0.5
,
2.
]),
0.
,
1.
])
[
numpy
.
asarray
([
-
1.
,
0.5
,
2.
]),
0.
,
1.
])
def
test_clip_grad_int
():
def
test_clip_grad_int
():
...
@@ -1038,10 +1044,34 @@ def test_clip_grad_int():
...
@@ -1038,10 +1044,34 @@ def test_clip_grad_int():
x
=
tensor
.
iscalar
()
x
=
tensor
.
iscalar
()
y
=
tensor
.
iscalar
()
y
=
tensor
.
iscalar
()
z
=
tensor
.
iscalar
()
z
=
tensor
.
iscalar
()
c
=
tensor
.
clip
(
x
,
y
,
z
)
c
=
tensor
.
clip
(
x
,
y
,
z
)
tensor
.
grad
(
c
,
[
x
,
y
,
z
])
tensor
.
grad
(
c
,
[
x
,
y
,
z
])
def
test_not_implemented_elemwise_grad
():
"""
Regression test for unimplemented gradient in an Elemwise Op.
"""
class
TestOp
(
scalar
.
ScalarOp
):
def
__init__
(
self
):
self
.
output_types_preference
=
scalar
.
upgrade_to_float
def
impl
(
self
,
n
,
x
):
return
x
*
n
def
grad
(
self
,
(
n
,
x
),
(
gz
,)):
dy_dx
=
n
return
[
theano
.
gradient
.
grad_not_implemented
(
self
,
0
,
n
),
gz
*
dy_dx
]
test_op
=
tensor
.
Elemwise
(
TestOp
())
x
=
tensor
.
scalar
()
# The call to `grad` used to crash.
tensor
.
grad
(
test_op
(
2
,
x
),
x
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
t
=
TestElemwise
(
'setUp'
)
t
=
TestElemwise
(
'setUp'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论