Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d3c8eb17
提交
d3c8eb17
authored
7月 31, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #801 from lamblin/fix_careduce_nan
Fix CAReduce for 0 shapes and NaNs
上级
555af254
3ecd6ebf
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
19 行增加
和
21 行删除
+19
-21
basic.py
theano/scalar/basic.py
+6
-3
elemwise.py
theano/tensor/elemwise.py
+6
-2
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+7
-16
没有找到文件。
theano/scalar/basic.py
浏览文件 @
d3c8eb17
...
@@ -753,7 +753,7 @@ class ScalarOp(Op):
...
@@ -753,7 +753,7 @@ class ScalarOp(Op):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
3
,)
return
(
4
,)
class
UnaryScalarOp
(
ScalarOp
):
class
UnaryScalarOp
(
ScalarOp
):
...
@@ -1078,7 +1078,9 @@ class Maximum(BinaryScalarOp):
...
@@ -1078,7 +1078,9 @@ class Maximum(BinaryScalarOp):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
if
any
([
i
.
type
in
complex_types
for
i
in
node
.
inputs
]):
if
any
([
i
.
type
in
complex_types
for
i
in
node
.
inputs
]):
raise
NotImplementedError
()
raise
NotImplementedError
()
return
"
%(z)
s = ((
%(y)
s)>(
%(x)
s)? (
%(y)
s):(
%(x)
s));"
%
locals
()
# Test for both y>x and x>=y to detect NaN
return
(
'
%(z)
s = ((
%(y)
s)>(
%(x)
s)? (
%(y)
s): '
'((
%(x)
s)>=(
%(y)
s)? (
%(x)
s): nan("")));'
%
locals
())
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
assert
gz
.
type
not
in
complex_types
assert
gz
.
type
not
in
complex_types
...
@@ -1103,7 +1105,8 @@ class Minimum(BinaryScalarOp):
...
@@ -1103,7 +1105,8 @@ class Minimum(BinaryScalarOp):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
if
any
([
i
.
type
in
complex_types
for
i
in
node
.
inputs
]):
if
any
([
i
.
type
in
complex_types
for
i
in
node
.
inputs
]):
raise
NotImplementedError
()
raise
NotImplementedError
()
return
"
%(z)
s = ((
%(y)
s)<(
%(x)
s)? (
%(y)
s):(
%(x)
s));"
%
locals
()
return
(
'
%(z)
s = ((
%(y)
s)<(
%(x)
s)? (
%(y)
s): '
'((
%(x)
s)<=(
%(y)
s)? (
%(x)
s): nan("")));'
%
locals
())
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
assert
gz
.
type
not
in
complex_types
assert
gz
.
type
not
in
complex_types
...
...
theano/tensor/elemwise.py
浏览文件 @
d3c8eb17
...
@@ -1209,8 +1209,12 @@ class CAReduce(Op):
...
@@ -1209,8 +1209,12 @@ class CAReduce(Op):
# if available
# if available
if
variable
.
shape
[
dimension
]
==
0
:
if
variable
.
shape
[
dimension
]
==
0
:
if
hasattr
(
self
.
scalar_op
,
'identity'
):
if
hasattr
(
self
.
scalar_op
,
'identity'
):
variable
=
numpy
.
array
(
self
.
scalar_op
.
identity
)
# Compute the shape of the output
break
v_shape
=
list
(
variable
.
shape
)
del
v_shape
[
dimension
]
variable
=
numpy
.
empty
(
tuple
(
v_shape
),
dtype
=
variable
.
dtype
)
variable
.
fill
(
self
.
scalar_op
.
identity
)
else
:
else
:
raise
ValueError
((
raise
ValueError
((
"Input (
%
s) has zero-size on axis
%
s, but "
"Input (
%
s) has zero-size on axis
%
s, but "
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
d3c8eb17
...
@@ -315,15 +315,18 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -315,15 +315,18 @@ class test_CAReduce(unittest_tools.InferShapeTester):
else
:
else
:
self
.
fail
()
self
.
fail
()
else
:
else
:
#numpy.{all,any} return bool type.
# numpy.{all,any} return bool type,
# but theano ops return an int8 array instead
if
scalar_op
in
[
scalar
.
and_
,
scalar
.
or_
]:
if
scalar_op
in
[
scalar
.
and_
,
scalar
.
or_
]:
zv
=
numpy
.
asarray
(
zv
,
dtype
=
dtype
)
zv
=
numpy
.
asarray
(
zv
,
dtype
=
'int8'
)
if
test_nan
:
if
test_nan
:
self
.
assertTrue
(
theano
.
tensor
.
TensorType
.
values_eq
(
f
(
xv
),
self
.
assertTrue
(
theano
.
tensor
.
TensorType
.
values_eq
(
f
(
xv
),
zv
),
zv
),
(
f
(
xv
),
zv
))
(
f
(
xv
),
zv
))
else
:
else
:
self
.
assertTrue
(
numpy
.
allclose
(
f
(
xv
),
zv
),
(
f
(
xv
),
zv
))
f_xv
=
f
(
xv
)
self
.
assertTrue
((
f_xv
.
shape
==
zv
.
shape
),
(
f_xv
,
zv
))
self
.
assertTrue
(
numpy
.
allclose
(
f_xv
,
zv
),
(
f_xv
,
zv
))
#test CAReduce.infer_shape
#test CAReduce.infer_shape
#the Shape op don't implement c_code!
#the Shape op don't implement c_code!
...
@@ -355,10 +358,6 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -355,10 +358,6 @@ class test_CAReduce(unittest_tools.InferShapeTester):
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
xor
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
xor
,
dtype
=
dtype
)
@dec.knownfailureif
(
True
,
(
"When there is nan in the input of CAReduce,"
" we don't have a good output. "
))
def
test_perform_nan
(
self
):
def
test_perform_nan
(
self
):
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
]:
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
]:
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
add
,
dtype
=
dtype
,
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
add
,
dtype
=
dtype
,
...
@@ -370,12 +369,8 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -370,12 +369,8 @@ class test_CAReduce(unittest_tools.InferShapeTester):
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
minimum
,
dtype
=
dtype
,
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
minimum
,
dtype
=
dtype
,
test_nan
=
True
)
test_nan
=
True
)
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
or_
,
dtype
=
dtype
,
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
or_
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
and_
,
dtype
=
dtype
,
test_nan
=
True
)
self
.
with_linker
(
gof
.
PerformLinker
(),
or_
,
dtype
=
dtype
,
test_nan
=
True
,
tensor_op
=
tensor
.
any
)
test_nan
=
True
,
tensor_op
=
tensor
.
any
)
self
.
with_linker
(
gof
.
PerformLinker
(),
and_
,
dtype
=
dtype
,
self
.
with_linker
(
gof
.
PerformLinker
(),
scalar
.
and_
,
dtype
=
dtype
,
test_nan
=
True
,
tensor_op
=
tensor
.
all
)
test_nan
=
True
,
tensor_op
=
tensor
.
all
)
def
test_c
(
self
):
def
test_c
(
self
):
...
@@ -394,10 +389,6 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -394,10 +389,6 @@ class test_CAReduce(unittest_tools.InferShapeTester):
self
.
with_linker
(
gof
.
CLinker
(),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
CLinker
(),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
CLinker
(),
scalar
.
xor
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
CLinker
(),
scalar
.
xor
,
dtype
=
dtype
)
@dec.knownfailureif
(
True
,
(
"When there is nan in the input of CAReduce,"
" we don't have a good output. "
))
def
test_c_nan
(
self
):
def
test_c_nan
(
self
):
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
]:
for
dtype
in
[
"floatX"
,
"complex64"
,
"complex128"
]:
self
.
with_linker
(
gof
.
CLinker
(),
scalar
.
add
,
dtype
=
dtype
,
self
.
with_linker
(
gof
.
CLinker
(),
scalar
.
add
,
dtype
=
dtype
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论