Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
07fa43dc
提交
07fa43dc
authored
6月 10, 2017
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update tests.
This also reflects the difference between bool and int8
上级
629fa735
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
41 行增加
和
18 行删除
+41
-18
test_opt.py
theano/tensor/tests/test_opt.py
+41
-18
没有找到文件。
theano/tensor/tests/test_opt.py
浏览文件 @
07fa43dc
...
@@ -3493,8 +3493,12 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
...
@@ -3493,8 +3493,12 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
topo
[
0
]
.
op
==
deep_copy_op
assert
topo
[
0
]
.
op
==
deep_copy_op
x_val
=
10
if
f
.
outputs
[
0
]
.
variable
.
dtype
==
'bool'
:
assert
f
(
x_val
)
==
x_val
x_vals
=
[
0
,
1
]
else
:
x_vals
=
[
0
,
1
,
10
]
for
x_val
in
x_vals
:
assert
f
(
x_val
)
==
x_val
def
test_inequality_with_self
(
self
):
def
test_inequality_with_self
(
self
):
x
=
T
.
scalar
(
'x'
,
dtype
=
config
.
floatX
)
x
=
T
.
scalar
(
'x'
,
dtype
=
config
.
floatX
)
...
@@ -3601,11 +3605,14 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
...
@@ -3601,11 +3605,14 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
assert
(
f
([
3
,
3
])
==
0
)
.
all
()
assert
(
f
([
3
,
3
])
==
0
)
.
all
()
def
test_and
(
self
):
def
test_and
(
self
):
# bitwise "and" with 0 should give 0 for both bool and int
# bitwise "and" with 1 should only simplify for bool
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
)
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
)
for
dtype
,
zero
,
one
in
[(
'bool'
,
np
.
array
(
False
),
np
.
array
(
True
)),
(
'int8'
,
np
.
int8
(
0
),
np
.
int8
(
1
)),
(
'int8'
,
0
,
1
)]:
x
=
T
.
scalar
(
'x'
,
dtype
=
dtype
)
x
=
T
.
scalar
(
'x'
,
dtype
=
'int8'
)
for
zero
,
one
in
[(
np
.
int8
(
0
),
np
.
int8
(
1
)),
(
0
,
1
)]:
f
=
theano
.
function
([
x
],
T
.
and_
(
x
,
zero
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
and_
(
x
,
zero
),
mode
=
mode
)
self
.
assert_eqs_const
(
f
,
0
)
self
.
assert_eqs_const
(
f
,
0
)
...
@@ -3613,38 +3620,54 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
...
@@ -3613,38 +3620,54 @@ class Test_local_useless_elemwise_comparison(unittest.TestCase):
self
.
assert_eqs_const
(
f
,
0
)
self
.
assert_eqs_const
(
f
,
0
)
f
=
theano
.
function
([
x
],
T
.
and_
(
x
,
one
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
and_
(
x
,
one
),
mode
=
mode
)
if
f
.
outputs
[
0
]
.
variable
.
dtype
==
x
.
dtype
:
if
dtype
==
'bool'
:
self
.
assert_identity
(
f
)
self
.
assert_identity
(
f
)
f
=
theano
.
function
([
x
],
T
.
and_
(
one
,
x
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
and_
(
one
,
x
),
mode
=
mode
)
if
f
.
outputs
[
0
]
.
variable
.
dtype
==
x
.
dtype
:
if
dtype
==
'bool'
:
self
.
assert_identity
(
f
)
self
.
assert_identity
(
f
)
def
test_and_int
(
self
):
# Test that bitwise "and" is correctly computed on int constants.
f
=
theano
.
function
([],
T
.
and_
(
5
,
6
))
assert
f
()
==
4
def
test_or
(
self
):
def
test_or
(
self
):
# bitwise "or" with 0 should simplify for both bool and int
# bitwise "or" with 1 should only give 1 for bool
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
)
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
)
x
=
T
.
scalar
(
'x'
,
dtype
=
'int8'
)
for
dtype
,
zero
,
one
in
[(
'bool'
,
np
.
array
(
False
),
np
.
array
(
True
)),
(
'int8'
,
np
.
int8
(
0
),
np
.
int8
(
1
)),
(
'int8'
,
0
,
1
)]:
x
=
T
.
scalar
(
'x'
,
dtype
=
dtype
)
for
zero
,
one
in
[(
np
.
int8
(
0
),
np
.
int8
(
1
)),
(
0
,
1
)]:
f
=
theano
.
function
([
x
],
T
.
or_
(
x
,
one
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
or_
(
x
,
one
),
mode
=
mode
)
self
.
assert_eqs_const
(
f
,
1
)
if
dtype
==
'bool'
:
self
.
assert_eqs_const
(
f
,
1
)
f
=
theano
.
function
([
x
],
T
.
or_
(
one
,
x
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
or_
(
one
,
x
),
mode
=
mode
)
self
.
assert_eqs_const
(
f
,
1
)
if
dtype
==
'bool'
:
self
.
assert_eqs_const
(
f
,
1
)
f
=
theano
.
function
([
x
],
T
.
or_
(
x
,
zero
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
or_
(
x
,
zero
),
mode
=
mode
)
if
f
.
outputs
[
0
]
.
variable
.
dtype
==
x
.
dtype
:
self
.
assert_identity
(
f
)
self
.
assert_identity
(
f
)
f
=
theano
.
function
([
x
],
T
.
or_
(
zero
,
x
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
or_
(
zero
,
x
),
mode
=
mode
)
if
f
.
outputs
[
0
]
.
variable
.
dtype
==
x
.
dtype
:
self
.
assert_identity
(
f
)
self
.
assert_identity
(
f
)
def
test_or_int
(
self
):
# Test that bitwise "or" is correctly computed on int constants.
f
=
theano
.
function
([],
T
.
or_
(
5
,
6
))
assert
f
()
==
7
def
test_xor
(
self
):
def
test_xor
(
self
):
# bitwise "xor" with itself should always give 0 for both bool and int.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
)
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
)
x
=
T
.
scalar
(
'x'
,
dtype
=
'int8'
)
for
dtype
in
(
'bool'
,
'int8'
):
x
=
T
.
scalar
(
'x'
,
dtype
=
dtype
)
f
=
theano
.
function
([
x
],
T
.
xor
(
x
,
x
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
xor
(
x
,
x
),
mode
=
mode
)
self
.
assert_eqs_const
(
f
,
0
)
self
.
assert_eqs_const
(
f
,
0
)
def
test_stacktrace
(
self
):
def
test_stacktrace
(
self
):
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论