Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ddef757d
提交
ddef757d
authored
5月 05, 2015
作者:
Dustin Webb
提交者:
Amjad Almahairi
9月 10, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added tests for optimization of inequalities comparing a variable with itself.
上级
10855815
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
46 行增加
和
19 行删除
+46
-19
opt.py
theano/tensor/opt.py
+1
-1
test_opt.py
theano/tensor/tests/test_opt.py
+45
-18
没有找到文件。
theano/tensor/opt.py
浏览文件 @
ddef757d
...
@@ -4295,7 +4295,7 @@ def local_useless_elemwise_comparison(node):
...
@@ -4295,7 +4295,7 @@ def local_useless_elemwise_comparison(node):
# Elemwise[{LT,GT}](X, X) -> Elemwise[zeros](X)
# Elemwise[{LT,GT}](X, X) -> Elemwise[zeros](X)
if
(
isinstance
(
node
.
op
.
scalar_op
,
(
scalar
.
LT
,
scalar
.
GT
))
and
if
(
isinstance
(
node
.
op
.
scalar_op
,
(
scalar
.
LT
,
scalar
.
GT
))
and
node
.
inputs
[
0
]
is
node
.
inputs
[
1
]):
node
.
inputs
[
0
]
is
node
.
inputs
[
1
]):
return
[
T
.
zeros_like
(
node
.
outputs
[
0
])]
return
[
T
.
zeros_like
(
node
.
outputs
[
0
]
,
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
)]
# Elemwise[{LE,GE}](X, X) -> Elemwise[ones](X)
# Elemwise[{LE,GE}](X, X) -> Elemwise[ones](X)
if
(
isinstance
(
node
.
op
.
scalar_op
,
(
scalar
.
LE
,
scalar
.
GE
))
and
if
(
isinstance
(
node
.
op
.
scalar_op
,
(
scalar
.
LE
,
scalar
.
GE
))
and
node
.
inputs
[
0
]
is
node
.
inputs
[
1
]):
node
.
inputs
[
0
]
is
node
.
inputs
[
1
]):
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
ddef757d
...
@@ -3136,7 +3136,17 @@ def test_local_fill_useless():
...
@@ -3136,7 +3136,17 @@ def test_local_fill_useless():
f
(
m_
,
x_
)
f
(
m_
,
x_
)
def
test_local_useless_elemwise_comparison
():
def
assert_eqs_const
(
topo
,
val
):
elem
=
topo
[
0
]
assert
len
(
topo
)
==
1
assert
elem
.
op
==
deep_copy_op
assert
len
(
elem
.
inputs
)
==
1
assert
isinstance
(
elem
.
inputs
[
0
],
T
.
TensorConstant
)
assert
T
.
extract_constant
(
elem
.
inputs
[
0
])
==
val
class
Test_local_useless_elemwise_comparison
(
unittest
.
TestCase
):
def
test_local_useless_elemwise_comparison
(
self
):
# TODO: test each case individually.
# TODO: test each case individually.
# The following case is what made me discover those cases.
# The following case is what made me discover those cases.
X
=
T
.
matrix
(
'X'
)
X
=
T
.
matrix
(
'X'
)
...
@@ -3151,6 +3161,21 @@ def test_local_useless_elemwise_comparison():
...
@@ -3151,6 +3161,21 @@ def test_local_useless_elemwise_comparison():
f
=
theano
.
function
([
X
,
Y
],
Z
,
mode
=
mode
)
f
=
theano
.
function
([
X
,
Y
],
Z
,
mode
=
mode
)
theano
.
printing
.
debugprint
(
f
,
print_type
=
True
)
theano
.
printing
.
debugprint
(
f
,
print_type
=
True
)
def
test_inequality_with_self
(
self
):
x
=
T
.
scalar
(
'x'
,
dtype
=
config
.
floatX
)
f
=
theano
.
function
([
x
],
T
.
lt
(
x
,
x
))
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
0
)
f
=
theano
.
function
([
x
],
T
.
le
(
x
,
x
))
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
1
)
f
=
theano
.
function
([
x
],
T
.
gt
(
x
,
x
))
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
0
)
f
=
theano
.
function
([
x
],
T
.
ge
(
x
,
x
))
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
1
)
class
Test_local_useless_alloc
(
unittest
.
TestCase
):
class
Test_local_useless_alloc
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -3924,28 +3949,30 @@ class T_useless_elemwise(unittest.TestCase):
...
@@ -3924,28 +3949,30 @@ class T_useless_elemwise(unittest.TestCase):
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
topo
[
0
]
.
op
==
deep_copy_op
assert
topo
[
0
]
.
op
==
deep_copy_op
def
assert_eqs_const
(
self
,
topo
,
val
):
elem
=
topo
[
0
]
assert
len
(
topo
)
==
1
assert
elem
.
op
==
deep_copy_op
assert
len
(
elem
.
inputs
)
==
1
assert
isinstance
(
elem
.
inputs
[
0
],
T
.
TensorConstant
)
assert
T
.
extract_constant
(
elem
.
inputs
[
0
])
==
val
def
assert_identity
(
self
,
f
):
def
assert_identity
(
self
,
f
):
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
topo
[
0
]
.
op
==
deep_copy_op
assert
topo
[
0
]
.
op
==
deep_copy_op
x_val
=
numpy
.
random
.
randint
(
256
)
x_val
=
-
128
assert
f
(
x_val
)
==
x_val
x_val
=
-
1
assert
f
(
x_val
)
==
x_val
x_val
=
0
assert
f
(
x_val
)
==
x_val
x_val
=
1
assert
f
(
x_val
)
==
x_val
x_val
=
127
assert
f
(
x_val
)
==
x_val
x_val
=
numpy
.
random
.
randint
(
255
)
-
128
assert
f
(
x_val
)
==
x_val
assert
f
(
x_val
)
==
x_val
def
test_and
(
self
):
def
test_and
(
self
):
x
=
T
.
scalar
(
'x'
,
dtype
=
'int
64
'
)
x
=
T
.
scalar
(
'x'
,
dtype
=
'int
8
'
)
f
=
theano
.
function
([
x
],
T
.
and_
(
x
,
0
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
T
.
and_
(
x
,
0
),
mode
=
self
.
mode
)
self
.
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
0
)
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
0
)
f
=
theano
.
function
([
x
],
T
.
and_
(
0
,
x
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
T
.
and_
(
0
,
x
),
mode
=
self
.
mode
)
self
.
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
0
)
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
0
)
f
=
theano
.
function
([
x
],
T
.
and_
(
x
,
1
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
T
.
and_
(
x
,
1
),
mode
=
self
.
mode
)
self
.
assert_identity
(
f
)
self
.
assert_identity
(
f
)
...
@@ -3954,13 +3981,13 @@ class T_useless_elemwise(unittest.TestCase):
...
@@ -3954,13 +3981,13 @@ class T_useless_elemwise(unittest.TestCase):
self
.
assert_identity
(
f
)
self
.
assert_identity
(
f
)
def
test_or
(
self
):
def
test_or
(
self
):
x
=
T
.
scalar
(
'x'
,
dtype
=
'int
64
'
)
x
=
T
.
scalar
(
'x'
,
dtype
=
'int
8
'
)
f
=
theano
.
function
([
x
],
T
.
or_
(
x
,
1
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
T
.
or_
(
x
,
1
),
mode
=
self
.
mode
)
self
.
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
1
)
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
1
)
f
=
theano
.
function
([
x
],
T
.
or_
(
1
,
x
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
T
.
or_
(
1
,
x
),
mode
=
self
.
mode
)
self
.
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
1
)
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
1
)
f
=
theano
.
function
([
x
],
T
.
or_
(
x
,
0
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
T
.
or_
(
x
,
0
),
mode
=
self
.
mode
)
self
.
assert_identity
(
f
)
self
.
assert_identity
(
f
)
...
@@ -3969,10 +3996,10 @@ class T_useless_elemwise(unittest.TestCase):
...
@@ -3969,10 +3996,10 @@ class T_useless_elemwise(unittest.TestCase):
self
.
assert_identity
(
f
)
self
.
assert_identity
(
f
)
def
test_xor
(
self
):
def
test_xor
(
self
):
x
=
T
.
scalar
(
'x'
,
dtype
=
'int
64
'
)
x
=
T
.
scalar
(
'x'
,
dtype
=
'int
8
'
)
f
=
theano
.
function
([
x
],
T
.
xor
(
x
,
x
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
T
.
xor
(
x
,
x
),
mode
=
self
.
mode
)
self
.
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
0
)
assert_eqs_const
(
f
.
maker
.
fgraph
.
toposort
(),
0
)
class
T_cast_cast
(
unittest
.
TestCase
):
class
T_cast_cast
(
unittest
.
TestCase
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论