Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b55d3697
提交
b55d3697
authored
3月 21, 2011
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix opt failure for the new switch opt and better test it.
上级
5628b044
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
71 行增加
和
15 行删除
+71
-15
opt.py
theano/tensor/opt.py
+3
-0
test_opt.py
theano/tensor/tests/test_opt.py
+68
-15
没有找到文件。
theano/tensor/opt.py
浏览文件 @
b55d3697
...
@@ -1469,6 +1469,9 @@ def local_remove_switch_const_cond(node):
...
@@ -1469,6 +1469,9 @@ def local_remove_switch_const_cond(node):
return
False
return
False
if
out
.
dtype
!=
node
.
outputs
[
0
]
.
dtype
:
if
out
.
dtype
!=
node
.
outputs
[
0
]
.
dtype
:
out
=
T
.
cast
(
out
,
node
.
outputs
[
0
]
.
dtype
)
out
=
T
.
cast
(
out
,
node
.
outputs
[
0
]
.
dtype
)
if
out
.
type
.
broadcastable
!=
node
.
outputs
[
0
]
.
type
.
broadcastable
:
# We need to copy data to the new dimensions during execution
out
=
T
.
alloc
(
out
,
*
[
node
.
outputs
[
0
]
.
shape
[
i
]
for
i
in
range
(
out
.
ndim
)])
return
[
out
]
return
[
out
]
return
False
return
False
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
b55d3697
...
@@ -2272,31 +2272,84 @@ class T_local_erfc(unittest.TestCase):
...
@@ -2272,31 +2272,84 @@ class T_local_erfc(unittest.TestCase):
class
test_local_remove_switch_const_cond
(
unittest
.
TestCase
):
class
test_local_remove_switch_const_cond
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
excluding
(
'constant_folding'
)
def
test_const0
(
self
):
def
test_const0
(
self
):
x
=
theano
.
tensor
.
matrix
(
'x'
,
dtype
=
'int64'
)
for
dtype1
in
[
'int32'
,
'int64'
]:
y
=
theano
.
tensor
.
matrix
(
'y'
,
dtype
=
'int64'
)
for
dtype2
in
[
'int32'
,
'int64'
]:
z
=
theano
.
tensor
.
switch
(
0
,
x
,
y
)
x
=
theano
.
tensor
.
matrix
(
'x'
,
dtype
=
dtype1
)
f
=
theano
.
function
([
x
,
y
],
z
)
y
=
theano
.
tensor
.
matrix
(
'y'
,
dtype
=
dtype2
)
assert
len
([
x
for
x
in
f
.
maker
.
env
.
toposort
()
if
z
=
theano
.
tensor
.
switch
(
0
,
x
,
y
)
isinstance
(
x
,
theano
.
tensor
.
Elemwise
)
])
==
0
f
=
theano
.
function
([
x
,
y
],
z
,
mode
=
self
.
mode
)
vx
=
numpy
.
array
([[
1
,
2
,
3
],[
4
,
5
,
6
]],
dtype
=
'int64'
)
assert
len
([
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()
if
vy
=
numpy
.
array
([[
7
,
8
,
9
],[
10
,
11
,
12
]],
dtype
=
'int64'
)
isinstance
(
node
.
op
,
theano
.
tensor
.
Elemwise
)
])
==
0
assert
numpy
.
all
(
f
(
vx
,
vy
)
==
vy
)
vx
=
numpy
.
array
([[
1
,
2
,
3
],[
4
,
5
,
6
]],
dtype
=
dtype1
)
vy
=
numpy
.
array
([[
7
,
8
,
9
],[
10
,
11
,
12
]],
dtype
=
dtype2
)
assert
numpy
.
all
(
f
(
vx
,
vy
)
==
vy
)
def
test_const1
(
self
):
def
test_const1
(
self
):
x
=
theano
.
tensor
.
matrix
(
'x'
,
dtype
=
'int64'
)
for
dtype1
in
[
'int32'
,
'int64'
]:
for
dtype2
in
[
'int32'
,
'int64'
]:
x
=
theano
.
tensor
.
matrix
(
'x'
,
dtype
=
dtype1
)
y
=
theano
.
tensor
.
matrix
(
'y'
,
dtype
=
dtype2
)
z
=
theano
.
tensor
.
switch
(
1
,
x
,
y
)
f
=
theano
.
function
([
x
,
y
],
z
,
mode
=
self
.
mode
)
assert
len
([
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
node
.
op
,
theano
.
tensor
.
Elemwise
)
])
==
0
vx
=
numpy
.
array
([[
1
,
2
,
3
],[
4
,
5
,
6
]],
dtype
=
dtype1
)
vy
=
numpy
.
array
([[
7
,
8
,
9
],[
10
,
11
,
12
]],
dtype
=
dtype2
)
assert
numpy
.
all
(
f
(
vx
,
vy
)
==
vx
)
def
test_broadcast1
(
self
):
#test switch(cst, matrix, row)
x
=
theano
.
tensor
.
matrix
(
'x'
,
dtype
=
'int32'
)
y
=
theano
.
tensor
.
vector
(
'y'
,
dtype
=
'int64'
)
z
=
theano
.
tensor
.
switch
(
1
,
x
,
y
)
f
=
theano
.
function
([
x
,
y
],
z
,
mode
=
self
.
mode
)
#theano.printing.debugprint(f)
assert
len
([
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
node
.
op
,
theano
.
tensor
.
Elemwise
)
and
not
isinstance
(
node
.
op
.
scalar_op
,
theano
.
scalar
.
basic
.
Cast
)])
==
0
vx
=
numpy
.
array
([[
1
,
2
,
3
],[
4
,
5
,
6
]],
dtype
=
'int32'
)
vy
=
numpy
.
array
([
10
,
11
,
12
],
dtype
=
'int64'
)
assert
numpy
.
all
(
f
(
vx
,
vy
)
==
vx
)
z
=
theano
.
tensor
.
switch
(
0
,
x
,
y
)
f
=
theano
.
function
([
x
,
y
],
z
,
mode
=
self
.
mode
)
#theano.printing.debugprint(f)
assert
len
([
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
node
.
op
,
theano
.
tensor
.
Elemwise
)
])
==
0
vx
=
numpy
.
array
([[
1
,
2
,
3
],[
4
,
5
,
6
]],
dtype
=
'int32'
)
vy
=
numpy
.
array
([
10
,
11
,
12
],
dtype
=
'int64'
)
assert
numpy
.
all
(
f
(
vx
,
vy
)
==
vy
)
def
test_broadcast2
(
self
):
#test switch(cst, vector, matrix)
#This case is not optimized for now.
x
=
theano
.
tensor
.
vector
(
'x'
,
dtype
=
'int32'
)
y
=
theano
.
tensor
.
matrix
(
'y'
,
dtype
=
'int64'
)
y
=
theano
.
tensor
.
matrix
(
'y'
,
dtype
=
'int64'
)
z
=
theano
.
tensor
.
switch
(
1
,
x
,
y
)
z
=
theano
.
tensor
.
switch
(
1
,
x
,
y
)
f
=
theano
.
function
([
x
,
y
],
z
)
f
=
theano
.
function
([
x
,
y
],
z
,
mode
=
self
.
mode
)
assert
len
([
x
for
x
in
f
.
maker
.
env
.
toposort
()
if
assert
len
([
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
x
,
theano
.
tensor
.
Elemwise
)
])
==
0
isinstance
(
node
.
op
,
theano
.
tensor
.
Elemwise
)
and
vx
=
numpy
.
array
([[
1
,
2
,
3
],[
4
,
5
,
6
]],
dtype
=
'int64'
)
not
isinstance
(
node
.
op
.
scalar_op
,
theano
.
scalar
.
basic
.
Cast
)])
==
0
vx
=
numpy
.
array
([
4
,
5
,
6
],
dtype
=
'int32'
)
vy
=
numpy
.
array
([[
7
,
8
,
9
],[
10
,
11
,
12
]],
dtype
=
'int64'
)
vy
=
numpy
.
array
([[
7
,
8
,
9
],[
10
,
11
,
12
]],
dtype
=
'int64'
)
assert
numpy
.
all
(
f
(
vx
,
vy
)
==
vx
)
assert
numpy
.
all
(
f
(
vx
,
vy
)
==
vx
)
z
=
theano
.
tensor
.
switch
(
0
,
x
,
y
)
f
=
theano
.
function
([
x
,
y
],
z
,
mode
=
self
.
mode
)
assert
len
([
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
node
.
op
,
theano
.
tensor
.
Elemwise
)
])
==
0
vx
=
numpy
.
array
([
4
,
5
,
6
],
dtype
=
'int32'
)
vy
=
numpy
.
array
([[
7
,
8
,
9
],[
10
,
11
,
12
]],
dtype
=
'int64'
)
assert
numpy
.
all
(
f
(
vx
,
vy
)
==
vy
)
class
T_local_sum
(
unittest
.
TestCase
):
class
T_local_sum
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论