Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
755ba97a
提交
755ba97a
authored
7月 27, 2015
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3189 from nouiz/fix_nan
[BUG, TEST] Fix Sng handling of nan and fix related test
上级
e7d00def
08ac04b7
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
118 行增加
和
63 行删除
+118
-63
test_basic_ops.py
theano/sandbox/gpuarray/tests/test_basic_ops.py
+8
-0
type.py
theano/sandbox/gpuarray/type.py
+23
-2
basic.py
theano/scalar/basic.py
+2
-4
test_basic.py
theano/tensor/tests/test_basic.py
+85
-57
没有找到文件。
theano/sandbox/gpuarray/tests/test_basic_ops.py
浏览文件 @
755ba97a
...
...
@@ -384,6 +384,14 @@ class G_reshape(test_basic.T_reshape):
assert
self
.
op
==
GpuReshape
class
G_comparison
(
test_basic
.
test_comparison
):
def
setUp
(
self
):
utt
.
seed_rng
()
self
.
mode
=
mode_with_gpu
self
.
shared
=
gpuarray_shared_constructor
self
.
dtypes
=
[
'float64'
,
'float32'
]
class
G_Join_and_Split
(
test_basic
.
T_Join_and_Split
):
def
setUp
(
self
):
super
(
G_Join_and_Split
,
self
)
.
setUp
()
...
...
theano/sandbox/gpuarray/type.py
浏览文件 @
755ba97a
...
...
@@ -121,7 +121,20 @@ class GpuArrayType(Type):
return
False
if
a
.
typecode
!=
b
.
typecode
:
return
False
return
numpy
.
asarray
(
compare
(
a
,
'=='
,
b
))
.
all
()
a_eq_b
=
numpy
.
asarray
(
compare
(
a
,
'=='
,
b
))
if
a_eq_b
.
all
():
return
True
# maybe the trouble is that there are NaNs
a
=
numpy
.
asarray
(
a
)
b
=
numpy
.
asarray
(
b
)
a_missing
=
numpy
.
isnan
(
a
)
if
a_missing
.
any
():
b_missing
=
numpy
.
isnan
(
b
)
return
numpy
.
all
(
a_eq_b
+
(
a_missing
==
b_missing
))
else
:
return
False
@staticmethod
def
values_eq_approx
(
a
,
b
,
...
...
@@ -157,7 +170,15 @@ class GpuArrayType(Type):
op_tmpl
=
"res[i] = (fabs(
%%(a)
s -
%%(b)
s) <"
"(
%(atol_)
s +
%(rtol_)
s * fabs(
%%(b)
s)))"
%
locals
())
return
numpy
.
asarray
(
res
)
.
all
()
ret
=
numpy
.
asarray
(
res
)
.
all
()
if
ret
:
return
True
# maybe the trouble is that there are NaNs
an
=
numpy
.
asarray
(
a
)
bn
=
numpy
.
asarray
(
b
)
return
tensor
.
TensorType
.
values_eq_approx
(
an
,
bn
,
allow_remove_inf
=
allow_remove_inf
,
allow_remove_nan
=
allow_remove_nan
,
rtol
=
rtol
,
atol
=
atol
)
@staticmethod
def
may_share_memory
(
a
,
b
):
...
...
theano/scalar/basic.py
浏览文件 @
755ba97a
...
...
@@ -1096,8 +1096,6 @@ class EQ(LogicalComparison):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
(
x
,
y
)
=
inputs
(
z
,)
=
outputs
if
node
.
inputs
[
0
]
.
type
in
complex_types
:
raise
NotImplementedError
()
return
"
%(z)
s = (
%(x)
s ==
%(y)
s);"
%
locals
()
eq
=
EQ
()
...
...
@@ -2104,7 +2102,7 @@ class Sgn(UnaryScalarOp):
(
z
,)
=
outputs
type
=
node
.
inputs
[
0
]
.
type
if
type
in
float_types
:
return
"
%(z)
s = (
%(x)
s >= 0) ? (
%(x)
s == 0) ? 0.0 : 1.0 : -1.0;"
%
locals
()
return
'
%(z)
s = (
%(x)
s > 0) ? 1. : ((
%(x)
s < 0) ? -1. : (isnan(
%(x)
s) ? NAN : 0.));'
%
locals
()
if
type
in
int_types
:
return
"
%(z)
s = (
%(x)
s >= 0) ? (
%(x)
s == 0) ? 0 : 1 : -1;"
%
locals
()
raise
TypeError
()
# complex has no sgn
...
...
@@ -2112,7 +2110,7 @@ class Sgn(UnaryScalarOp):
def
c_code_cache_version
(
self
):
s
=
super
(
Sgn
,
self
)
.
c_code_cache_version
()
if
s
:
return
(
3
,)
+
s
return
(
4
,)
+
s
else
:
# if parent is unversioned, we are too
return
s
sgn
=
Sgn
(
same_out_nocomplex
,
name
=
'sgn'
)
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
755ba97a
...
...
@@ -4024,116 +4024,136 @@ class test_comparison(unittest.TestCase):
work(futur behavior) or raise an error(current NumPy release).
"""
def
setUp
(
self
):
utt
.
seed_rng
()
self
.
mode
=
None
self
.
shared
=
shared
self
.
dtypes
=
[
'float64'
,
'float32'
,
'complex64'
,
'complex128'
]
def
inplace_func
(
self
,
inputs
,
outputs
,
check_isfinite
=
None
):
mode
=
self
.
mode
if
check_isfinite
is
False
:
if
mode
is
None
:
mode
=
get_default_mode
()
mode
.
check_isfinite
=
False
f
=
inplace_func
(
inputs
,
outputs
,
mode
=
mode
)
return
f
def
test_gt
(
self
):
for
dtype
in
[
'float64'
,
'float32'
,
'complex64'
,
'complex128'
]
:
for
dtype
in
self
.
dtypes
:
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
],
dtype
=
dtype
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
],
dtype
=
dtype
)
for
x
,
y
,
err
in
[
(
shared
(
l
.
astype
(
dtype
)),
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
shared
(
r
.
astype
(
dtype
)),
False
),
(
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
self
.
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
]:
try
:
fn
=
inplace_func
([],
x
>
y
)
fn
=
self
.
inplace_func
([],
x
>
y
)
v
=
fn
()
self
.
assertTrue
(
numpy
.
all
(
v
==
(
l
>
r
)),
(
v
,
(
l
>
r
)))
except
TypeError
:
assert
err
def
test_lt
(
self
):
for
dtype
in
[
'float64'
,
'float32'
,
'complex64'
,
'complex128'
]
:
for
dtype
in
self
.
dtypes
:
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
],
dtype
=
dtype
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
],
dtype
=
dtype
)
for
x
,
y
,
err
in
[
(
s
hared
(
l
.
astype
(
dtype
)),
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
shared
(
r
.
astype
(
dtype
)),
False
),
(
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
(
s
elf
.
shared
(
l
.
astype
(
dtype
)),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
s
elf
.
s
hared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
s
elf
.
s
hared
(
r
.
astype
(
dtype
)),
False
),
(
s
elf
.
s
hared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
s
elf
.
s
hared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
]:
try
:
fn
=
inplace_func
([],
x
<
y
)
fn
=
self
.
inplace_func
([],
x
<
y
)
v
=
fn
()
self
.
assertTrue
(
numpy
.
all
(
v
==
(
l
<
r
)),
(
v
,
(
l
<
r
)))
except
TypeError
:
assert
err
def
test_le
(
self
):
for
dtype
in
[
'float64'
,
'float32'
,
'complex64'
,
'complex128'
]
:
for
dtype
in
self
.
dtypes
:
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
],
dtype
=
dtype
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
],
dtype
=
dtype
)
for
x
,
y
,
err
in
[
(
shared
(
l
.
astype
(
dtype
)),
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
shared
(
r
.
astype
(
dtype
)),
False
),
(
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
self
.
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
]:
try
:
fn
=
inplace_func
([],
x
<=
y
)
fn
=
self
.
inplace_func
([],
x
<=
y
)
v
=
fn
()
self
.
assertTrue
(
numpy
.
all
(
v
==
(
l
<=
r
)),
(
v
,
(
l
<=
r
)))
except
TypeError
:
assert
err
def
test_ge
(
self
):
for
dtype
in
[
'float64'
,
'float32'
,
'complex64'
,
'complex128'
]
:
for
dtype
in
self
.
dtypes
:
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
],
dtype
=
dtype
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
],
dtype
=
dtype
)
for
x
,
y
,
err
in
[
(
shared
(
l
.
astype
(
dtype
)),
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
shared
(
r
.
astype
(
dtype
)),
False
),
(
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
self
.
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
]:
try
:
fn
=
inplace_func
([],
x
>=
y
)
fn
=
self
.
inplace_func
([],
x
>=
y
)
v
=
fn
()
self
.
assertTrue
(
numpy
.
all
(
v
==
(
l
>=
r
)),
(
v
,
(
l
>=
r
)))
except
TypeError
:
assert
err
def
test_eq
(
self
):
for
dtype
in
[
'float64'
,
'float32'
,
'complex64'
,
'complex128'
]
:
for
dtype
in
self
.
dtypes
:
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
],
dtype
=
dtype
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
],
dtype
=
dtype
)
for
x
,
y
,
err
in
[
(
shared
(
l
.
astype
(
dtype
)),
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
shared
(
r
.
astype
(
dtype
)),
False
),
(
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
self
.
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
]:
try
:
fn
=
inplace_func
([],
eq
(
x
,
y
))
fn
=
self
.
inplace_func
([],
eq
(
x
,
y
))
v
=
fn
()
self
.
assertTrue
(
numpy
.
all
(
v
==
(
l
==
r
)),
(
v
,
(
l
==
r
)))
except
TypeError
:
assert
err
def
test_neq
(
self
):
for
dtype
in
[
'float64'
,
'float32'
,
'complex64'
,
'complex128'
]
:
for
dtype
in
self
.
dtypes
:
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
],
dtype
=
dtype
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
],
dtype
=
dtype
)
for
x
,
y
,
err
in
[
(
shared
(
l
.
astype
(
dtype
)),
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
shared
(
r
.
astype
(
dtype
)),
False
),
(
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
self
.
shared
(
r
.
astype
(
dtype
)),
True
),
(
tensor
.
constant
(
l
),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
tensor
.
constant
(
r
),
False
),
]:
try
:
fn
=
inplace_func
([],
neq
(
x
,
y
))
fn
=
self
.
inplace_func
([],
neq
(
x
,
y
))
v
=
fn
()
self
.
assertTrue
(
numpy
.
all
(
v
==
(
l
!=
r
)),
(
v
,
(
l
!=
r
)))
except
TypeError
:
assert
err
def
test_isclose
(
self
):
for
dtype
in
[
'float64'
,
'float32'
,
'complex64'
,
'complex128'
]
:
for
dtype
in
self
.
dtypes
:
l
=
numpy
.
asarray
(
[
0.
,
1.
,
-
1.
,
0.
,
numpy
.
nan
,
numpy
.
inf
,
-
numpy
.
inf
,
numpy
.
inf
],
...
...
@@ -4143,15 +4163,20 @@ class test_comparison(unittest.TestCase):
numpy
.
nan
,
numpy
.
inf
,
numpy
.
inf
,
0.
],
dtype
=
dtype
)
for
x
,
y
,
err
in
[
(
shared
(
l
.
astype
(
dtype
)),
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
shared
(
r
.
astype
(
dtype
)),
True
),
(
constant
(
l
),
shared
(
r
.
astype
(
dtype
)),
False
),
(
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
shared
(
l
.
astype
(
dtype
)),
constant
(
r
),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
self
.
shared
(
r
.
astype
(
dtype
)),
True
),
(
constant
(
l
),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
constant
(
r
),
False
),
]:
try
:
fn1
=
inplace_func
([],
isclose
(
x
,
y
,
equal_nan
=
False
))
fn2
=
inplace_func
([],
isclose
(
x
,
y
,
equal_nan
=
True
))
o1
=
isclose
(
x
,
y
,
equal_nan
=
False
)
fn1
=
self
.
inplace_func
([],
o1
,
check_isfinite
=
False
)
o2
=
isclose
(
x
,
y
,
equal_nan
=
True
)
fn2
=
self
.
inplace_func
([],
o2
,
check_isfinite
=
False
)
v1
=
fn1
()
v2
=
fn2
()
self
.
assertTrue
(
...
...
@@ -4172,12 +4197,13 @@ class test_comparison(unittest.TestCase):
)
except
TypeError
:
if
not
dtype
.
startswith
(
'complex'
):
raise
assert
err
def
test_allclose
(
self
):
# equal_nan argument not in current version of numpy allclose,
# force it to False.
for
dtype
in
[
'float64'
,
'float32'
,
'complex64'
,
'complex128'
]
:
for
dtype
in
self
.
dtypes
:
l
=
numpy
.
asarray
(
[
0.
,
1.
,
-
1.
,
0.
,
numpy
.
nan
,
numpy
.
inf
,
-
numpy
.
inf
,
numpy
.
inf
],
...
...
@@ -4187,14 +4213,16 @@ class test_comparison(unittest.TestCase):
numpy
.
nan
,
numpy
.
inf
,
numpy
.
inf
,
0.
],
dtype
=
dtype
)
for
x
,
y
,
err
in
[
(
shared
(
l
.
astype
(
dtype
)),
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
shared
(
r
.
astype
(
dtype
)),
True
),
(
constant
(
l
),
shared
(
r
.
astype
(
dtype
)),
False
),
(
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
shared
(
l
.
astype
(
dtype
)),
constant
(
r
),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
l
,
self
.
shared
(
r
.
astype
(
dtype
)),
True
),
(
constant
(
l
),
self
.
shared
(
r
.
astype
(
dtype
)),
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
r
,
False
),
(
self
.
shared
(
l
.
astype
(
dtype
)),
constant
(
r
),
False
),
]:
try
:
fn
=
inplace_func
([],
allclose
(
x
,
y
,
equal_nan
=
False
))
fn
=
self
.
inplace_func
([],
allclose
(
x
,
y
,
equal_nan
=
False
),
check_isfinite
=
False
)
v
=
fn
()
self
.
assertTrue
(
numpy
.
all
(
v
==
numpy
.
allclose
(
l
,
r
)))
except
TypeError
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论