Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
674e90ca
提交
674e90ca
authored
10月 14, 2009
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
better test for the canonizer. skip test that are know to fail because they are…
better test for the canonizer. skip test that are know to fail because they are not implemented. They are not real error or failure.
上级
eedc7263
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
107 行增加
和
9 行删除
+107
-9
test_opt.py
theano/tensor/tests/test_opt.py
+107
-9
没有找到文件。
theano/tensor/tests/test_opt.py
浏览文件 @
674e90ca
...
@@ -14,6 +14,7 @@ import numpy
...
@@ -14,6 +14,7 @@ import numpy
#import scalar_opt
#import scalar_opt
from
theano
import
function
,
compile
from
theano
import
function
,
compile
from
nose.plugins.skip
import
SkipTest
def
inputs
(
xbc
=
(
0
,
0
),
ybc
=
(
0
,
0
),
zbc
=
(
0
,
0
)):
def
inputs
(
xbc
=
(
0
,
0
),
ybc
=
(
0
,
0
),
zbc
=
(
0
,
0
)):
...
@@ -183,9 +184,87 @@ class test_canonize(unittest.TestCase):
...
@@ -183,9 +184,87 @@ class test_canonize(unittest.TestCase):
def
test_elemwise_multiple_inputs_optimisation
(
self
):
def
test_elemwise_multiple_inputs_optimisation
(
self
):
"""
"""
verify that the Canonizer merge sequential Elemwise({mul,add})
verify that the Canonizer merge sequential Elemwise({mul,add}) part 1
This part are that case that is done, but don't include case that are not implemented but are suposed to be.
Test with and without DimShuffle
Test with and without DimShuffle
"""
"""
shp
=
(
5
,
5
)
fx
,
fy
,
fz
=
fmatrices
(
'xyz'
)
dx
,
dy
,
dz
=
dmatrices
(
'xyz'
)
fv
=
fvector
(
'r'
)
.
dimshuffle
(
'x'
,
0
)
dv
=
dvector
(
's'
)
.
dimshuffle
(
'x'
,
0
)
fxv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float32'
)
fyv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float32'
)
fzv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float32'
)
fvv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
shp
[
0
]),
dtype
=
'float32'
)
.
reshape
(
1
,
shp
[
0
])
dxv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float64'
)
dyv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float64'
)
dzv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float64'
)
dvv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
shp
[
0
]),
dtype
=
'float64'
)
.
reshape
(
1
,
shp
[
0
])
cases
=
[
(
fx
+
fy
,(
fx
,
fy
),(
fxv
,
fyv
),
1
,
'float32'
),
(
fx
*
fy
,(
fx
,
fy
),(
fxv
,
fyv
),
1
,
'float32'
),
# (fx+fy+fz,(fx,fy,fz),(fxv,fyv,fzv),1,'float32'),
# (dx+dy+dz,(dx,dy,dz),(dxv,dyv,dzv),1,'float64'),
# (fx*fy*fz,(fx,fy,fz),(fxv,fyv,fzv),1,'float32'),
# (dx*dy*dz,(dx,dy,dz),(dxv,dyv,dzv),1,'float64'),
# (fx*fy*(fx+fy+fz),(fx,fy,fz),(fxv,fyv,fzv),2,'float32'),
# (dx*dy*(dx+dy+dz),(dx,dy,dz),(dxv,dyv,dzv),2,'float64'),
# (fx*fy*(fx+fy+dz),(fx,fy,dz),(dxv,dyv,dzv),2,'float64'),#check mixed type add
# (dz*fy*(fx+fy),(fx,fy,dz),(dxv,dyv,dzv),2,'float64'),#check mixed type mul
#check with dimshuffle of constant
(
fx
+
fy
+
fz
+
2
,(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
'float32'
),
(
fx
*
fy
*
fz
*
2
,(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
'float32'
),
# (2+fx+fy+fz,(fx,fy,fz),(fxv,fyv,fzv),1,'float32'),
# (2*fx*fy*fz,(fx,fy,fz),(fxv,fyv,fzv),1,'float32'),
(
2
+
fx
+
fy
+
fz
+
2
,(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
'float32'
),
(
2
*
fx
*
fy
*
fz
*
2
,(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
1
,
'float32'
),
# (fx*fy*2*(fx+fy+fz),(fx,fy,fz),(fxv,fyv,fzv),2,'float32'),
# (fx*fy*(2+fx+fy+fz),(fx,fy,fz),(fxv,fyv,fzv),2,'float32'),
(
fx
*
fy
*
2
*
(
fx
+
fy
+
fz
+
2
),(
fx
,
fy
,
fz
),(
fxv
,
fyv
,
fzv
),
2
,
'float32'
),
#check with broadcast of row
# (fx+fy+fz+fv,(fx,fy,fz,fv),(fxv,fyv,fzv,fvv),1,'float32'),
# (fx*fy*fz*fv,(fx,fy,fz,fv),(fxv,fyv,fzv,fvv),1,'float32'),
# (fv+fx+fy+fz,(fx,fy,fz,fv),(fxv,fyv,fzv,fvv),1,'float32'),
# (fv*fx*fy*fz,(fx,fy,fz,fv),(fxv,fyv,fzv,fvv),1,'float32'),
# (fx*fy*fv*(fx+fy+fz),(fx,fy,fz,fv),(fxv,fyv,fzv,fvv),2,'float32'),
# (fx*fy*(fv+fx+fy+fz),(fx,fy,fz,fv),(fxv,fyv,fzv,fvv),2,'float32'),
# (fx*fy*fv*(fv+fx+fy+fz),(fx,fy,fz,fv),(fxv,fyv,fzv,fvv),2,'float32'),
# (dx+dy+dz+dv,(dx,dy,dz,dv),(dxv,dyv,dzv,dvv),1,'float64'),
# (dx*dy*dz*dv,(dx,dy,dz,dv),(dxv,dyv,dzv,dvv),1,'float64'),
# (dv+dx+dy+dz,(dx,dy,dz,dv),(dxv,dyv,dzv,dvv),1,'float64'),
# (dv*dx*dy*dz,(dx,dy,dz,dv),(dxv,dyv,dzv,dvv),1,'float64'),
# (dx*dy*dv*(dx+dy+dz),(dx,dy,dz,dv),(dxv,dyv,dzv,dvv),2,'float64'),
# (dx*dy*(dv+dx+dy+dz),(dx,dy,dz,dv),(dxv,dyv,dzv,dvv),2,'float64'),
# (dx*dy*dv*(dv+dx+dy+dz),(dx,dy,dz,dv),(dxv,dyv,dzv,dvv),2,'float64'),
]
#[10:11]
# print cases
#We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode
=
compile
.
mode
.
predefined_modes
[
compile
.
mode
.
default_mode
]
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
for
id
,
[
g
,
sym_inputs
,
val_inputs
,
nb_elemwise
,
out_dtype
]
in
enumerate
(
cases
):
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
#we need the optimisation enabled, debug do this.
mode
=
mode
)
out
=
f
(
*
val_inputs
)
assert
(
len
(
f
.
maker
.
env
.
toposort
())
==
nb_elemwise
)
assert
(
out_dtype
==
out
.
dtype
)
def
test_elemwise_multiple_inputs_optimisation2
(
self
):
"""
verify that the Canonizer merge sequential Elemwise({mul,add}) part 2.
This part are that case that should have been done, but that are not implemented.
Test with and without DimShuffle
"""
raise
SkipTest
(
"Current implementation of Canonizer don't implement all case. Skip the corresponding test"
)
shp
=
(
5
,
5
)
shp
=
(
5
,
5
)
fx
,
fy
,
fz
=
fmatrices
(
'xyz'
)
fx
,
fy
,
fz
=
fmatrices
(
'xyz'
)
dx
,
dy
,
dz
=
dmatrices
(
'xyz'
)
dx
,
dy
,
dz
=
dmatrices
(
'xyz'
)
...
@@ -240,13 +319,20 @@ class test_canonize(unittest.TestCase):
...
@@ -240,13 +319,20 @@ class test_canonize(unittest.TestCase):
]
#[10:11]
]
#[10:11]
# print cases
# print cases
for
id
,
[
g
,
sym_inputs
,
val_inputs
,
expected_out_nb_elemwise
,
out_dtype
]
in
enumerate
(
cases
):
#We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode
=
compile
.
mode
.
predefined_modes
[
compile
.
mode
.
default_mode
]
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
for
id
,
[
g
,
sym_inputs
,
val_inputs
,
nb_elemwise
,
out_dtype
]
in
enumerate
(
cases
):
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
#we need the optimisation enabled, debug do this.
#we need the optimisation enabled, debug do this.
mode
=
compile
.
mode
.
predefined_modes
[
'DEBUG_MODE'
])
mode
=
mode
)
out
=
f
(
*
val_inputs
)
out
=
f
(
*
val_inputs
)
assert
(
len
(
f
.
maker
.
env
.
toposort
())
==
expected_out_
nb_elemwise
)
assert
(
len
(
f
.
maker
.
env
.
toposort
())
==
nb_elemwise
)
assert
(
out_dtype
==
out
.
dtype
)
assert
(
out_dtype
==
out
.
dtype
)
def
test_multiple_case
(
self
):
def
test_multiple_case
(
self
):
""" test those case take from the comment in Canonizer
""" test those case take from the comment in Canonizer
x / x -> 1
x / x -> 1
...
@@ -278,8 +364,11 @@ class test_canonize(unittest.TestCase):
...
@@ -278,8 +364,11 @@ class test_canonize(unittest.TestCase):
dwv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float64'
)
dwv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float64'
)
dvv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
shp
[
0
]),
dtype
=
'float64'
)
.
reshape
(
1
,
shp
[
0
])
dvv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
shp
[
0
]),
dtype
=
'float64'
)
.
reshape
(
1
,
shp
[
0
])
#we need the optimisation enabled, debug do this.
#We must be sure that the Canonizer is working, but that we don't have other
mode
=
compile
.
mode
.
predefined_modes
[
'DEBUG_MODE'
]
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode
=
compile
.
mode
.
predefined_modes
[
compile
.
mode
.
default_mode
]
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
#test x / x -> 1
#test x / x -> 1
for
id
,
(
g
,
sym_inputs
,
val_inputs
,
out_dtype
)
in
enumerate
([(
fx
/
fx
,[
fx
],[
fxv
],
'float32'
),
for
id
,
(
g
,
sym_inputs
,
val_inputs
,
out_dtype
)
in
enumerate
([(
fx
/
fx
,[
fx
],[
fxv
],
'float32'
),
...
@@ -338,8 +427,7 @@ class test_canonize(unittest.TestCase):
...
@@ -338,8 +427,7 @@ class test_canonize(unittest.TestCase):
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
nb_elemwise
assert
len
(
topo
)
==
nb_elemwise
assert
isinstance
(
topo
[
0
]
.
op
,(
T
.
Elemwise
,))
assert
isinstance
(
topo
[
0
]
.
op
,(
T
.
Elemwise
,))
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
scalar
.
basic
.
Inv
)
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,(
theano
.
scalar
.
basic
.
Inv
,
theano
.
scalar
.
basic
.
TrueDiv
))
assert
len
(
topo
[
0
]
.
inputs
)
==
1
assert
(
out_dtype
==
out
.
dtype
)
assert
(
out_dtype
==
out
.
dtype
)
#test (a / b) * (b / c) * (c / d) -> a / d
#test (a / b) * (b / c) * (c / d) -> a / d
...
@@ -407,6 +495,7 @@ class test_canonize(unittest.TestCase):
...
@@ -407,6 +495,7 @@ class test_canonize(unittest.TestCase):
def
test_multiple_case_that_fail
(
self
):
def
test_multiple_case_that_fail
(
self
):
import
theano.tensor
,
theano
.
compile
import
theano.tensor
,
theano
.
compile
raise
SkipTest
(
"Current implementation of Canonizer don't implement all case. Skip the corresponding test"
)
shp
=
(
4
,
4
)
shp
=
(
4
,
4
)
fx
,
fy
,
fz
=
fmatrices
(
'xyz'
)
fx
,
fy
,
fz
=
fmatrices
(
'xyz'
)
...
@@ -418,7 +507,11 @@ class test_canonize(unittest.TestCase):
...
@@ -418,7 +507,11 @@ class test_canonize(unittest.TestCase):
dyv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float32'
)
dyv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float32'
)
dzv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float32'
)
dzv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shp
),
dtype
=
'float32'
)
fvv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
shp
[
0
]),
dtype
=
'float32'
)
.
reshape
(
1
,
shp
[
0
])
fvv
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
shp
[
0
]),
dtype
=
'float32'
)
.
reshape
(
1
,
shp
[
0
])
mode
=
compile
.
mode
.
predefined_modes
[
'DEBUG_MODE'
]
#We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode
=
compile
.
mode
.
predefined_modes
[
compile
.
mode
.
default_mode
]
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
#test fail!
#test fail!
#test x / y / z -> x / (y * z)
#test x / y / z -> x / (y * z)
...
@@ -455,6 +548,11 @@ class test_canonize(unittest.TestCase):
...
@@ -455,6 +548,11 @@ class test_canonize(unittest.TestCase):
assert
len
(
topo
[
0
]
.
inputs
)
==
1
assert
len
(
topo
[
0
]
.
inputs
)
==
1
assert
(
out_dtype
==
out
.
dtype
)
assert
(
out_dtype
==
out
.
dtype
)
def
test_dont_merge_if_multiple_client
(
self
):
""" test those case take from the comment in Canonizer
"""
raise
SkipTest
(
"Not implemented"
)
def
test_mixeddiv
():
def
test_mixeddiv
():
"""Test that int division is preserved"""
"""Test that int division is preserved"""
i
=
iscalar
()
i
=
iscalar
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论