Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
db922d3e
提交
db922d3e
authored
12月 20, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
white space fix.
上级
00b9905c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
11 行增加
和
13 行删除
+11
-13
elemwise.py
theano/tensor/elemwise.py
+6
-7
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+5
-6
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
db922d3e
...
@@ -1197,7 +1197,7 @@ class Prod(CAReduce):
...
@@ -1197,7 +1197,7 @@ class Prod(CAReduce):
With zeros, things get more complicated. For a given group, we have 3
With zeros, things get more complicated. For a given group, we have 3
cases:
cases:
* No zeros in the group. Use previous trick.
* No zeros in the group. Use previous trick.
* If only one zero is present, then the gradient for that element is
* If only one zero is present, then the gradient for that element is
non-zero, but is zero for all others.
non-zero, but is zero for all others.
* If more than one zero is present, then all the derivatives are zero.
* If more than one zero is present, then all the derivatives are zero.
...
@@ -1209,7 +1209,7 @@ class Prod(CAReduce):
...
@@ -1209,7 +1209,7 @@ class Prod(CAReduce):
case, there's a special Op that computes the product of the elements
case, there's a special Op that computes the product of the elements
in the group, minus the zero (see ProdWithoutZero). The trick is then
in the group, minus the zero (see ProdWithoutZero). The trick is then
to use the division trick for groups with no zero, to use the
to use the division trick for groups with no zero, to use the
ProdWithoutZeros op where there's only one zero, and to output a
ProdWithoutZeros op where there's only one zero, and to output a
derivative of zero for any element part of a group with more than
derivative of zero for any element part of a group with more than
one zero.
one zero.
...
@@ -1230,14 +1230,14 @@ class Prod(CAReduce):
...
@@ -1230,14 +1230,14 @@ class Prod(CAReduce):
axis
=
range
(
prod_in
.
type
.
ndim
)
axis
=
range
(
prod_in
.
type
.
ndim
)
if
axis
==
():
if
axis
==
():
return
gz
,
return
gz
,
new_dims
=
[]
new_dims
=
[]
i
=
0
i
=
0
for
j
,
_
in
enumerate
(
prod_in
.
type
.
broadcastable
):
for
j
,
_
in
enumerate
(
prod_in
.
type
.
broadcastable
):
if
j
in
axis
:
if
j
in
axis
:
new_dims
.
append
(
'x'
)
new_dims
.
append
(
'x'
)
else
:
else
:
new_dims
.
append
(
i
)
new_dims
.
append
(
i
)
i
+=
1
i
+=
1
# result of the product, broadcastable over groups
# result of the product, broadcastable over groups
prod_out
=
self
(
prod_in
)
.
dimshuffle
(
new_dims
)
prod_out
=
self
(
prod_in
)
.
dimshuffle
(
new_dims
)
...
@@ -1254,7 +1254,7 @@ class Prod(CAReduce):
...
@@ -1254,7 +1254,7 @@ class Prod(CAReduce):
else
:
else
:
T
=
theano
.
tensor
T
=
theano
.
tensor
where_zeros
=
T
.
eq
(
prod_in
,
0.0
)
where_zeros
=
T
.
eq
(
prod_in
,
0.0
)
sum_where_zeros
=
T
.
sum
(
where_zeros
,
axis
=
self
.
axis
)
sum_where_zeros
=
T
.
sum
(
where_zeros
,
axis
=
self
.
axis
)
groups_with_single_zero
=
T
.
eq
(
sum_where_zeros
,
1
)
.
dimshuffle
(
new_dims
)
groups_with_single_zero
=
T
.
eq
(
sum_where_zeros
,
1
)
.
dimshuffle
(
new_dims
)
# tensor with 0 everywhere except for those places where
# tensor with 0 everywhere except for those places where
...
@@ -1262,7 +1262,7 @@ class Prod(CAReduce):
...
@@ -1262,7 +1262,7 @@ class Prod(CAReduce):
where_single_zero
=
groups_with_single_zero
*
where_zeros
where_single_zero
=
groups_with_single_zero
*
where_zeros
# further optimization to avoid computing ProdWithoutZeros
# further optimization to avoid computing ProdWithoutZeros
# if the incoming gradient is 0
# if the incoming gradient is 0
where_gz_not_zero
=
T
.
neq
(
gz
,
0.0
)
where_gz_not_zero
=
T
.
neq
(
gz
,
0.0
)
# only take ProdWithoutZeros for the groups with single zeros
# only take ProdWithoutZeros for the groups with single zeros
# with non-null incoming gradient
# with non-null incoming gradient
where_to_take_prod_without_zeros
=
\
where_to_take_prod_without_zeros
=
\
...
@@ -1338,4 +1338,3 @@ class ProdWithoutZeros(CAReduce):
...
@@ -1338,4 +1338,3 @@ class ProdWithoutZeros(CAReduce):
return
"ProdWithoutZeros"
return
"ProdWithoutZeros"
else
:
else
:
return
"ProdWithoutZeros{
%
s}"
%
", "
.
join
(
map
(
str
,
self
.
axis
))
return
"ProdWithoutZeros{
%
s}"
%
", "
.
join
(
map
(
str
,
self
.
axis
))
theano/tensor/tests/test_elemwise.py
浏览文件 @
db922d3e
...
@@ -104,9 +104,9 @@ class test_Broadcast(unittest.TestCase):
...
@@ -104,9 +104,9 @@ class test_Broadcast(unittest.TestCase):
xv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
xsh
))
xv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
xsh
))
yv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
ysh
))
yv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
ysh
))
zv
=
xv
+
yv
zv
=
xv
+
yv
f
(
xv
,
yv
)
f
(
xv
,
yv
)
assert
xv
.
shape
==
zv
.
shape
assert
xv
.
shape
==
zv
.
shape
def
test_perform
(
self
):
def
test_perform
(
self
):
...
@@ -217,11 +217,11 @@ class test_CAReduce(unittest.TestCase):
...
@@ -217,11 +217,11 @@ class test_CAReduce(unittest.TestCase):
f
(
xv
)
f
(
xv
)
except
ValueError
:
except
ValueError
:
pass
pass
else
:
else
:
self
.
fail
()
self
.
fail
()
else
:
else
:
self
.
failUnless
((
numpy
.
abs
(
f
(
xv
)
-
zv
)
<
1e-10
)
.
all
())
self
.
failUnless
((
numpy
.
abs
(
f
(
xv
)
-
zv
)
<
1e-10
)
.
all
())
#test CAReduce.infer_shape
#test CAReduce.infer_shape
#the Shape op don't implement c_code!
#the Shape op don't implement c_code!
...
@@ -248,7 +248,7 @@ class test_CAReduce(unittest.TestCase):
...
@@ -248,7 +248,7 @@ class test_CAReduce(unittest.TestCase):
self
.
with_linker
(
gof
.
CLinker
(),
maximum
)
self
.
with_linker
(
gof
.
CLinker
(),
maximum
)
self
.
with_linker
(
gof
.
CLinker
(),
minimum
)
self
.
with_linker
(
gof
.
CLinker
(),
minimum
)
#need other dtype then real
#need other dtype then real
#no c_code for or_, and_
#no c_code for or_, and_
#self.with_linker(gof.CLinker(), or_)
#self.with_linker(gof.CLinker(), or_)
#self.with_linker(gof.CLinker(), and_)
#self.with_linker(gof.CLinker(), and_)
...
@@ -367,4 +367,3 @@ if __name__ == '__main__':
...
@@ -367,4 +367,3 @@ if __name__ == '__main__':
#suite.addTest(test_Prod('test_prod_without_zeros'))
#suite.addTest(test_Prod('test_prod_without_zeros'))
#suite.addTest(test_Prod('test_other_grad_tests'))
#suite.addTest(test_Prod('test_other_grad_tests'))
unittest
.
TextTestRunner
()
.
run
(
suite
)
unittest
.
TextTestRunner
()
.
run
(
suite
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论