Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2153cabf
提交
2153cabf
authored
2月 18, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Changes in tensor/tests/test_opt to go along with new ShapeFeature.
上级
13a50c35
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
35 行增加
和
41 行删除
+35
-41
test_opt.py
theano/tensor/tests/test_opt.py
+35
-41
没有找到文件。
theano/tensor/tests/test_opt.py
浏览文件 @
2153cabf
...
@@ -89,7 +89,6 @@ class test_greedy_distribute(unittest.TestCase):
...
@@ -89,7 +89,6 @@ class test_greedy_distribute(unittest.TestCase):
g
=
Env
([
a
,
b
,
c
,
d
,
x
,
y
,
z
],
[
e
])
g
=
Env
([
a
,
b
,
c
,
d
,
x
,
y
,
z
],
[
e
])
##print pprint(g.outputs[0])
##print pprint(g.outputs[0])
mul_canonizer
.
optimize
(
g
)
mul_canonizer
.
optimize
(
g
)
gof
.
TopoOptimizer
(
gof
.
LocalOptGroup
(
local_fill_cut
,
local_fill_lift
),
order
=
'out_to_in'
)
.
optimize
(
g
)
gof
.
TopoOptimizer
(
gof
.
LocalOptGroup
(
local_greedy_distributor
),
order
=
'out_to_in'
)
.
optimize
(
g
)
gof
.
TopoOptimizer
(
gof
.
LocalOptGroup
(
local_greedy_distributor
),
order
=
'out_to_in'
)
.
optimize
(
g
)
##print pprint(g.outputs[0])
##print pprint(g.outputs[0])
...
@@ -136,7 +135,6 @@ class test_canonize(unittest.TestCase):
...
@@ -136,7 +135,6 @@ class test_canonize(unittest.TestCase):
g
=
Env
([
x
,
y
,
z
,
a
,
b
,
c
,
d
],
[
e
])
g
=
Env
([
x
,
y
,
z
,
a
,
b
,
c
,
d
],
[
e
])
print
pprint
(
g
.
outputs
[
0
])
print
pprint
(
g
.
outputs
[
0
])
mul_canonizer
.
optimize
(
g
)
mul_canonizer
.
optimize
(
g
)
gof
.
TopoOptimizer
(
gof
.
LocalOptGroup
(
local_fill_cut
,
local_fill_lift
),
order
=
'out_to_in'
)
.
optimize
(
g
)
print
pprint
(
g
.
outputs
[
0
])
print
pprint
(
g
.
outputs
[
0
])
def
test_elemwise_multiple_inputs_optimisation
(
self
):
def
test_elemwise_multiple_inputs_optimisation
(
self
):
...
@@ -331,6 +329,7 @@ class test_canonize(unittest.TestCase):
...
@@ -331,6 +329,7 @@ class test_canonize(unittest.TestCase):
old_optimizer
=
mode
.
_optimizer
old_optimizer
=
mode
.
_optimizer
try
:
try
:
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
mode
.
_optimizer
.
including
(
'ShapeOpt'
)
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
#test x / x -> 1
#test x / x -> 1
...
@@ -344,10 +343,15 @@ class test_canonize(unittest.TestCase):
...
@@ -344,10 +343,15 @@ class test_canonize(unittest.TestCase):
out
=
f
(
*
val_inputs
)
out
=
f
(
*
val_inputs
)
assert
(
out
==
numpy
.
ones
(
shp
,
dtype
=
out_dtype
))
.
all
()
assert
(
out
==
numpy
.
ones
(
shp
,
dtype
=
out_dtype
))
.
all
()
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
1
if
sym_inputs
[
0
]
.
broadcastable
[
0
]:
assert
isinstance
(
topo
[
0
]
.
op
,(
T
.
Elemwise
,))
assert
len
(
topo
)
==
2
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
scalar
.
basic
.
Second
)
assert
isinstance
(
topo
[
0
]
.
op
,
Shape_i
)
assert
len
(
topo
[
0
]
.
inputs
)
==
2
assert
isinstance
(
topo
[
1
]
.
op
,
TT
.
Alloc
)
else
:
assert
len
(
topo
)
==
3
assert
isinstance
(
topo
[
0
]
.
op
,
Shape_i
)
assert
isinstance
(
topo
[
1
]
.
op
,
Shape_i
)
assert
isinstance
(
topo
[
2
]
.
op
,
TT
.
Alloc
)
assert
(
out_dtype
==
out
.
dtype
)
assert
(
out_dtype
==
out
.
dtype
)
#test (x * y) / x -> y
#test (x * y) / x -> y
...
@@ -365,10 +369,16 @@ class test_canonize(unittest.TestCase):
...
@@ -365,10 +369,16 @@ class test_canonize(unittest.TestCase):
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
mode
=
mode
)
mode
=
mode
)
out
=
f
(
*
val_inputs
)
out
=
f
(
*
val_inputs
)
assert
(
out_dtype
==
out
.
dtype
)
assert
numpy
.
allclose
(
out
,
val_inputs
[
1
])
assert
numpy
.
allclose
(
out
,
val_inputs
[
1
])
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
nb_elemwise
print
"ID TOPO"
,
id
,
topo
,
sym_inputs
assert
(
out_dtype
==
out
.
dtype
)
for
r
,
t
in
f
.
maker
.
env
.
shape_feature
.
shape_of
.
items
():
print
' '
,
r
,
t
if
topo
:
for
node
in
topo
[:
-
1
]:
assert
isinstance
(
node
.
op
,
Shape_i
)
assert
isinstance
(
topo
[
-
1
]
.
op
,
TT
.
Alloc
)
#test x / y / x -> 1 / y
#test x / y / x -> 1 / y
for
id
,(
g
,
sym_inputs
,
val_inputs
,
nb_elemwise
,
out_dtype
)
in
enumerate
([
for
id
,(
g
,
sym_inputs
,
val_inputs
,
nb_elemwise
,
out_dtype
)
in
enumerate
([
...
@@ -378,19 +388,21 @@ class test_canonize(unittest.TestCase):
...
@@ -378,19 +388,21 @@ class test_canonize(unittest.TestCase):
((
fv
/
fy
)
/
fv
,[
fv
,
fy
],[
fvv
,
fyv
],
1
,
'float32'
),
((
fv
/
fy
)
/
fv
,[
fv
,
fy
],[
fvv
,
fyv
],
1
,
'float32'
),
#must broadcast as their is a dimshuffle in the computation
#must broadcast as their is a dimshuffle in the computation
((
dx
/
dv
)
/
dx
,[
dx
,
dv
],[
dxv
,
dvv
],
2
,
'float64'
),
((
dx
/
dv
)
/
dx
,[
dx
,
dv
],[
dxv
,
dvv
],
1
,
'float64'
),
#topo: [
Elemwise{inv,no_inplace}(<TensorType(float64, row)>), Elemwise{second,no_inplace}(x, Elemwise{inv,no_inplace}.0
)]
#topo: [
Shape_i, Shape_i, Elemwise{inv,no_inplace}(<TensorType(float64, row)>), Alloc(...
)]
((
fx
/
fv
)
/
fx
,[
fx
,
fv
],[
fxv
,
fvv
],
2
,
'float32'
),
((
fx
/
fv
)
/
fx
,[
fx
,
fv
],[
fxv
,
fvv
],
1
,
'float32'
),
#topo:[
Elemwise{inv,no_inplace}(<TensorType(float32, row)>), Elemwise{second,no_inplace}(x, Elemwise{inv,no_inplace}.0
)]
#topo:[
Shape_i, Shape_i, Elemwise{inv,no_inplace}(<TensorType(float32, row)>), Alloc(...
)]
]):
]):
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
mode
=
mode
)
mode
=
mode
)
out
=
f
(
*
val_inputs
)
out
=
f
(
*
val_inputs
)
assert
numpy
.
allclose
(
out
,(
1
/
val_inputs
[
1
]))
assert
numpy
.
allclose
(
out
,(
1
/
val_inputs
[
1
]))
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
nb_elemwise
print
topo
assert
isinstance
(
topo
[
0
]
.
op
,(
T
.
Elemwise
,))
elem
=
[
t
for
t
in
topo
if
isinstance
(
t
.
op
,
T
.
Elemwise
)]
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,(
theano
.
scalar
.
basic
.
Inv
,
theano
.
scalar
.
basic
.
TrueDiv
))
assert
len
(
elem
)
==
nb_elemwise
assert
isinstance
(
elem
[
0
]
.
op
,(
T
.
Elemwise
,))
assert
isinstance
(
elem
[
0
]
.
op
.
scalar_op
,(
theano
.
scalar
.
basic
.
Inv
,
theano
.
scalar
.
basic
.
TrueDiv
))
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
...
@@ -529,29 +541,6 @@ def test_mixeddiv():
...
@@ -529,29 +541,6 @@ def test_mixeddiv():
d
=
dscalar
()
d
=
dscalar
()
assert
0
==
function
([
i
,
d
],
d
*
(
i
/
(
i
+
1
)))(
3
,
1.0
)
assert
0
==
function
([
i
,
d
],
d
*
(
i
/
(
i
+
1
)))(
3
,
1.0
)
def
test_local_shape_lift_dot
():
args_to_result
=
{
(
fvector
,
fvector
):
"[]"
,
(
fvector
,
fmatrix
):
"[<TensorType(float32, matrix)>.shape[1]]"
,
(
fmatrix
,
fvector
):
"[<TensorType(float32, matrix)>.shape[0]]"
,
(
fmatrix
,
fmatrix
):
"[<TensorType(float32, matrix)>.shape[0], <TensorType(float32, matrix)>.shape[1]]"
,
}
for
x
in
[
fvector
,
fmatrix
]:
for
y
in
[
fvector
,
fmatrix
]:
i
=
x
()
j
=
y
()
print
'I SHAPE'
,
i
.
type
.
shape
print
'J SHAPE'
,
j
.
type
.
shape
d
=
shape
(
dot
(
i
,
j
))
if
x
is
fvector
and
y
is
fvector
:
assert
d
==
()
else
:
g
=
Env
([
i
,
j
],
[
d
])
gof
.
TopoOptimizer
(
gof
.
LocalOptGroup
(
local_shape_lift_dot
),
order
=
'out_to_in'
)
.
optimize
(
g
)
print
pprint
(
g
.
outputs
[
0
]),
args_to_result
[(
x
,
y
)]
assert
pprint
(
g
.
outputs
[
0
])
==
args_to_result
[(
x
,
y
)]
def
test_const_type_in_mul_canonizer
():
def
test_const_type_in_mul_canonizer
():
input
=
dmatrix
()
input
=
dmatrix
()
w
=
dmatrix
()
w
=
dmatrix
()
...
@@ -915,11 +904,16 @@ def test_log1p():
...
@@ -915,11 +904,16 @@ def test_log1p():
# check trickier cases (and use different dtype)
# check trickier cases (and use different dtype)
y
=
fmatrix
()
y
=
fmatrix
()
f
=
function
([
x
,
y
],
T
.
log
(
fill
(
y
,
1
)
+
(
x
)),
mode
=
m
)
f
=
function
([
x
,
y
],
T
.
log
(
fill
(
y
,
1
)
+
(
x
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
T
.
DimShuffle
([
False
],
[
'x'
,
0
],
True
),
T
.
log1p
,
T
.
fill
]
print
f
.
maker
.
env
.
toposort
()
# the first three ops are Shape_i, Shape_i, and Dimshuffle
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()][
3
:]
\
==
[
T
.
log1p
,
Alloc
(
'float64'
)]
f
=
function
([
x
,
y
],
T
.
log
(
0
+
(
x
)
+
fill
(
y
,
1.0
)),
mode
=
m
)
f
=
function
([
x
,
y
],
T
.
log
(
0
+
(
x
)
+
fill
(
y
,
1.0
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
T
.
DimShuffle
([
False
],
[
'x'
,
0
],
True
),
T
.
log1p
,
T
.
fill
]
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()][
3
:]
\
==
[
T
.
log1p
,
Alloc
(
'float64'
)]
f
=
function
([
x
,
y
],
T
.
log
(
2
+
(
x
)
-
fill
(
y
,
1.0
)),
mode
=
m
)
f
=
function
([
x
,
y
],
T
.
log
(
2
+
(
x
)
-
fill
(
y
,
1.0
)),
mode
=
m
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
T
.
DimShuffle
([
False
],
[
'x'
,
0
],
True
),
T
.
log1p
,
T
.
fill
]
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()][
3
:]
\
==
[
T
.
log1p
,
Alloc
(
'float64'
)]
f
([
1e-7
,
10
],
[[
0
,
0
],
[
0
,
0
]])
#debugmode will verify values
f
([
1e-7
,
10
],
[[
0
,
0
],
[
0
,
0
]])
#debugmode will verify values
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论