Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
818985b0
提交
818985b0
authored
3月 23, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
b8d2d3ee
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
79 行增加
和
79 行删除
+79
-79
test_ifelse.py
theano/tests/test_ifelse.py
+79
-79
没有找到文件。
theano/tests/test_ifelse.py
浏览文件 @
818985b0
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
unittest
import
unittest
import
numpy
import
numpy
as
np
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
six.moves
import
reduce
from
six.moves
import
reduce
...
@@ -42,16 +42,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -42,16 +42,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
c
=
tensor
.
iscalar
(
'c'
)
c
=
tensor
.
iscalar
(
'c'
)
f
=
theano
.
function
([
c
,
x
,
y
],
ifelse
(
c
,
x
,
y
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
c
,
x
,
y
],
ifelse
(
c
,
x
,
y
),
mode
=
self
.
mode
)
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
1
))
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
1
))
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
xlen
=
rng
.
randint
(
200
)
xlen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
vx
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vx
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vy
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
vy
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
assert
n
umpy
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
n
p
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
n
umpy
.
allclose
(
vy
,
f
(
0
,
vx
,
vy
))
assert
n
p
.
allclose
(
vy
,
f
(
0
,
vx
,
vy
))
def
test_not_lazy_if_inplace
(
self
):
def
test_not_lazy_if_inplace
(
self
):
# Tests that if the outputs are scalars and the graph is big,
# Tests that if the outputs are scalars and the graph is big,
...
@@ -71,16 +71,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -71,16 +71,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
if
isinstance
(
n
.
op
,
IfElse
)]
if
isinstance
(
n
.
op
,
IfElse
)]
assert
len
(
ifnode
)
==
1
assert
len
(
ifnode
)
==
1
assert
not
ifnode
[
0
]
.
op
.
as_view
assert
not
ifnode
[
0
]
.
op
.
as_view
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
xlen
=
rng
.
randint
(
200
)
xlen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
vx
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vx
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vy
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
vy
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
assert
n
umpy
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
n
p
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
n
umpy
.
allclose
(
vy
+
sum
(
range
(
200
)),
f
(
0
,
vx
,
vy
))
assert
n
p
.
allclose
(
vy
+
sum
(
range
(
200
)),
f
(
0
,
vx
,
vy
))
def
test_mixed_dtype
(
self
):
def
test_mixed_dtype
(
self
):
x1
=
tensor
.
vector
(
'x1'
,
dtype
=
'int32'
)
x1
=
tensor
.
vector
(
'x1'
,
dtype
=
'int32'
)
...
@@ -91,23 +91,23 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -91,23 +91,23 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
f
=
theano
.
function
([
c
,
x1
,
x2
,
y1
,
y2
],
f
=
theano
.
function
([
c
,
x1
,
x2
,
y1
,
y2
],
ifelse
(
c
,
(
x1
,
x2
),
(
y1
,
y2
)),
mode
=
self
.
mode
)
ifelse
(
c
,
(
x1
,
x2
),
(
y1
,
y2
)),
mode
=
self
.
mode
)
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
2
))
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
2
))
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
xlen
=
rng
.
randint
(
200
)
xlen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
vx1
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,))
*
3
,
'int32'
)
vx1
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,))
*
3
,
'int32'
)
vx2
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vx2
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vy1
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,))
*
3
,
'int32'
)
vy1
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,))
*
3
,
'int32'
)
vy2
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
vy2
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
o1
,
o2
=
f
(
1
,
vx1
,
vx2
,
vy1
,
vy2
)
o1
,
o2
=
f
(
1
,
vx1
,
vx2
,
vy1
,
vy2
)
assert
n
umpy
.
allclose
(
vx1
,
o1
)
assert
n
p
.
allclose
(
vx1
,
o1
)
assert
n
umpy
.
allclose
(
vx2
,
o2
)
assert
n
p
.
allclose
(
vx2
,
o2
)
o1
,
o2
=
f
(
0
,
vx1
,
vx2
,
vy1
,
vy2
)
o1
,
o2
=
f
(
0
,
vx1
,
vx2
,
vy1
,
vy2
)
assert
n
umpy
.
allclose
(
vy1
,
o1
)
assert
n
p
.
allclose
(
vy1
,
o1
)
assert
n
umpy
.
allclose
(
vy2
,
o2
)
assert
n
p
.
allclose
(
vy2
,
o2
)
def
test_lazy_if_on_generics
(
self
):
def
test_lazy_if_on_generics
(
self
):
x
=
theano
.
generic
()
x
=
theano
.
generic
()
...
@@ -134,24 +134,24 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -134,24 +134,24 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
# There is only 2 of the 3 ifelse that are moved on the GPU.
# There is only 2 of the 3 ifelse that are moved on the GPU.
# The one that stay on the CPU is for the shape.
# The one that stay on the CPU is for the shape.
self
.
assertFunctionContains
(
f
,
self
.
get_ifelse
(
1
),
min
=
2
,
max
=
3
)
self
.
assertFunctionContains
(
f
,
self
.
get_ifelse
(
1
),
min
=
2
,
max
=
3
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
xlen
=
rng
.
randint
(
200
)
xlen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
vx
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vx
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vy
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
vy
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
gx0
,
gy0
=
f
(
1
,
vx
,
vy
)
gx0
,
gy0
=
f
(
1
,
vx
,
vy
)
assert
n
umpy
.
allclose
(
gx0
.
shape
,
vx
.
shape
)
assert
n
p
.
allclose
(
gx0
.
shape
,
vx
.
shape
)
assert
n
umpy
.
allclose
(
gy0
.
shape
,
vy
.
shape
)
assert
n
p
.
allclose
(
gy0
.
shape
,
vy
.
shape
)
assert
n
umpy
.
all
(
numpy
.
asarray
(
gx0
)
==
1.
)
assert
n
p
.
all
(
np
.
asarray
(
gx0
)
==
1.
)
assert
n
umpy
.
all
(
numpy
.
asarray
(
gy0
)
==
0.
)
assert
n
p
.
all
(
np
.
asarray
(
gy0
)
==
0.
)
gx0
,
gy0
=
f
(
0
,
vx
,
vy
)
gx0
,
gy0
=
f
(
0
,
vx
,
vy
)
assert
n
umpy
.
allclose
(
gx0
.
shape
,
vx
.
shape
)
assert
n
p
.
allclose
(
gx0
.
shape
,
vx
.
shape
)
assert
n
umpy
.
allclose
(
gy0
.
shape
,
vy
.
shape
)
assert
n
p
.
allclose
(
gy0
.
shape
,
vy
.
shape
)
assert
n
umpy
.
all
(
numpy
.
asarray
(
gx0
)
==
0.
)
assert
n
p
.
all
(
np
.
asarray
(
gx0
)
==
0.
)
assert
n
umpy
.
all
(
numpy
.
asarray
(
gy0
)
==
1.
)
assert
n
p
.
all
(
np
.
asarray
(
gy0
)
==
1.
)
def
test_grad_cast_input
(
self
):
def
test_grad_cast_input
(
self
):
# Tests the gradient when both inputs are on the GPU.
# Tests the gradient when both inputs are on the GPU.
...
@@ -178,24 +178,24 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -178,24 +178,24 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
if
isinstance
(
x
.
op
,
IfElse
)][
0
]
if
isinstance
(
x
.
op
,
IfElse
)][
0
]
assert
len
(
ifnode
.
outputs
)
==
2
assert
len
(
ifnode
.
outputs
)
==
2
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
x1len
=
rng
.
randint
(
200
)
x1len
=
rng
.
randint
(
200
)
x2len
=
rng
.
randint
(
200
)
x2len
=
rng
.
randint
(
200
)
y1len
=
rng
.
randint
(
200
)
y1len
=
rng
.
randint
(
200
)
y2len
=
rng
.
randint
(
200
)
y2len
=
rng
.
randint
(
200
)
vx1
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
x1len
,)),
self
.
dtype
)
vx1
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
x1len
,)),
self
.
dtype
)
vx2
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
x2len
,)),
self
.
dtype
)
vx2
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
x2len
,)),
self
.
dtype
)
vy1
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
y1len
,)),
self
.
dtype
)
vy1
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
y1len
,)),
self
.
dtype
)
vy2
=
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
y2len
,)),
self
.
dtype
)
vy2
=
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
y2len
,)),
self
.
dtype
)
ovx1
,
ovx2
=
f
(
1
,
vx1
,
vx2
,
vy1
,
vy2
)
ovx1
,
ovx2
=
f
(
1
,
vx1
,
vx2
,
vy1
,
vy2
)
ovy1
,
ovy2
=
f
(
0
,
vx1
,
vx2
,
vy1
,
vy2
)
ovy1
,
ovy2
=
f
(
0
,
vx1
,
vx2
,
vy1
,
vy2
)
assert
n
umpy
.
allclose
(
vx1
,
ovx1
)
assert
n
p
.
allclose
(
vx1
,
ovx1
)
assert
n
umpy
.
allclose
(
vy1
,
ovy1
)
assert
n
p
.
allclose
(
vy1
,
ovy1
)
assert
n
umpy
.
allclose
(
vx2
,
ovx2
)
assert
n
p
.
allclose
(
vx2
,
ovx2
)
assert
n
umpy
.
allclose
(
vy2
,
ovy2
)
assert
n
p
.
allclose
(
vy2
,
ovy2
)
def
test_multiple_out_grad
(
self
):
def
test_multiple_out_grad
(
self
):
# Tests that we can compute the gradients through lazy if
# Tests that we can compute the gradients through lazy if
...
@@ -209,34 +209,34 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -209,34 +209,34 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
[
x1
,
x2
,
y1
,
y2
])
[
x1
,
x2
,
y1
,
y2
])
f
=
theano
.
function
([
c
,
x1
,
x2
,
y1
,
y2
],
grads
)
f
=
theano
.
function
([
c
,
x1
,
x2
,
y1
,
y2
],
grads
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
lens
=
[
rng
.
randint
(
200
)
for
i
in
range
(
4
)]
lens
=
[
rng
.
randint
(
200
)
for
i
in
range
(
4
)]
values
=
[
n
umpy
.
asarray
(
rng
.
uniform
(
size
=
(
l
,)),
theano
.
config
.
floatX
)
values
=
[
n
p
.
asarray
(
rng
.
uniform
(
size
=
(
l
,)),
theano
.
config
.
floatX
)
for
l
in
lens
]
for
l
in
lens
]
outs_1
=
f
(
1
,
*
values
)
outs_1
=
f
(
1
,
*
values
)
assert
all
([
x
.
shape
[
0
]
==
y
for
x
,
y
in
zip
(
outs_1
,
lens
)])
assert
all
([
x
.
shape
[
0
]
==
y
for
x
,
y
in
zip
(
outs_1
,
lens
)])
assert
n
umpy
.
all
(
outs_1
[
0
]
==
1.
)
assert
n
p
.
all
(
outs_1
[
0
]
==
1.
)
assert
n
umpy
.
all
(
outs_1
[
1
]
==
1.
)
assert
n
p
.
all
(
outs_1
[
1
]
==
1.
)
assert
n
umpy
.
all
(
outs_1
[
2
]
==
0.
)
assert
n
p
.
all
(
outs_1
[
2
]
==
0.
)
assert
n
umpy
.
all
(
outs_1
[
3
]
==
0.
)
assert
n
p
.
all
(
outs_1
[
3
]
==
0.
)
outs_0
=
f
(
0
,
*
values
)
outs_0
=
f
(
0
,
*
values
)
assert
all
([
x
.
shape
[
0
]
==
y
for
x
,
y
in
zip
(
outs_1
,
lens
)])
assert
all
([
x
.
shape
[
0
]
==
y
for
x
,
y
in
zip
(
outs_1
,
lens
)])
assert
n
umpy
.
all
(
outs_0
[
0
]
==
0.
)
assert
n
p
.
all
(
outs_0
[
0
]
==
0.
)
assert
n
umpy
.
all
(
outs_0
[
1
]
==
0.
)
assert
n
p
.
all
(
outs_0
[
1
]
==
0.
)
assert
n
umpy
.
all
(
outs_0
[
2
]
==
1.
)
assert
n
p
.
all
(
outs_0
[
2
]
==
1.
)
assert
n
umpy
.
all
(
outs_0
[
3
]
==
1.
)
assert
n
p
.
all
(
outs_0
[
3
]
==
1.
)
def
test_multiple_out_crash
(
self
):
def
test_multiple_out_crash
(
self
):
# This test failed up to commit 2faeb62c38
# This test failed up to commit 2faeb62c38
p0
=
self
.
shared
(
n
umpy
.
asarray
(
numpy
.
random
.
random
([
4
,
8
]),
p0
=
self
.
shared
(
n
p
.
asarray
(
np
.
random
.
random
([
4
,
8
]),
dtype
=
self
.
dtype
))
dtype
=
self
.
dtype
))
p1
=
self
.
shared
(
n
umpy
.
asarray
(
numpy
.
random
.
random
(
8
),
p1
=
self
.
shared
(
n
p
.
asarray
(
np
.
random
.
random
(
8
),
dtype
=
self
.
dtype
))
dtype
=
self
.
dtype
))
p2
=
self
.
shared
(
n
umpy
.
asarray
(
numpy
.
random
.
random
([
8
,
3
]),
p2
=
self
.
shared
(
n
p
.
asarray
(
np
.
random
.
random
([
8
,
3
]),
dtype
=
self
.
dtype
))
dtype
=
self
.
dtype
))
p3
=
self
.
shared
(
n
umpy
.
asarray
(
numpy
.
random
.
random
(
3
),
p3
=
self
.
shared
(
n
p
.
asarray
(
np
.
random
.
random
(
3
),
dtype
=
self
.
dtype
))
dtype
=
self
.
dtype
))
p
=
[
p0
,
p1
,
p2
,
p3
]
p
=
[
p0
,
p1
,
p2
,
p3
]
...
@@ -264,15 +264,15 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -264,15 +264,15 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
updates
=
new_updates
,
mode
=
self
.
mode
)
updates
=
new_updates
,
mode
=
self
.
mode
)
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
4
))
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
4
))
i1
=
n
umpy
.
asarray
(
numpy
.
random
.
random
([
19
,
4
,
8
]),
dtype
=
self
.
dtype
)
i1
=
n
p
.
asarray
(
np
.
random
.
random
([
19
,
4
,
8
]),
dtype
=
self
.
dtype
)
i2
=
n
umpy
.
asarray
(
numpy
.
random
.
random
([
19
,
8
]),
dtype
=
self
.
dtype
)
i2
=
n
p
.
asarray
(
np
.
random
.
random
([
19
,
8
]),
dtype
=
self
.
dtype
)
i3
=
n
umpy
.
asarray
(
numpy
.
random
.
random
([
19
,
8
,
3
]),
dtype
=
self
.
dtype
)
i3
=
n
p
.
asarray
(
np
.
random
.
random
([
19
,
8
,
3
]),
dtype
=
self
.
dtype
)
i4
=
n
umpy
.
asarray
(
numpy
.
random
.
random
([
19
,
3
]),
dtype
=
self
.
dtype
)
i4
=
n
p
.
asarray
(
np
.
random
.
random
([
19
,
3
]),
dtype
=
self
.
dtype
)
f
(
i1
,
i2
,
i3
,
i4
)
f
(
i1
,
i2
,
i3
,
i4
)
def
test_dtype_mismatch
(
self
):
def
test_dtype_mismatch
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
x
=
self
.
shared
(
data
)
x
=
self
.
shared
(
data
)
y
=
tensor
.
cast
(
x
*
10
,
'int8'
)
y
=
tensor
.
cast
(
x
*
10
,
'int8'
)
...
@@ -282,7 +282,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -282,7 +282,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
self
.
assertRaises
(
TypeError
,
ifelse
,
cond
,
y
,
x
)
self
.
assertRaises
(
TypeError
,
ifelse
,
cond
,
y
,
x
)
def
test_ndim_mismatch
(
self
):
def
test_ndim_mismatch
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
x
=
self
.
shared
(
data
)
x
=
self
.
shared
(
data
)
y
=
tensor
.
col
(
'y'
,
self
.
dtype
)
y
=
tensor
.
col
(
'y'
,
self
.
dtype
)
...
@@ -292,7 +292,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -292,7 +292,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
self
.
assertRaises
(
TypeError
,
ifelse
,
cond
,
y
,
x
)
self
.
assertRaises
(
TypeError
,
ifelse
,
cond
,
y
,
x
)
def
test_broadcast_mismatch
(
self
):
def
test_broadcast_mismatch
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
data
=
rng
.
rand
(
5
)
.
astype
(
self
.
dtype
)
x
=
self
.
shared
(
data
)
x
=
self
.
shared
(
data
)
# print x.broadcastable
# print x.broadcastable
...
@@ -307,7 +307,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -307,7 +307,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
import
theano.sparse
import
theano.sparse
if
not
theano
.
sparse
.
enable_sparse
:
if
not
theano
.
sparse
.
enable_sparse
:
raise
SkipTest
(
"Optimization temporarily disabled"
)
raise
SkipTest
(
"Optimization temporarily disabled"
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
data
=
rng
.
rand
(
2
,
3
)
.
astype
(
self
.
dtype
)
data
=
rng
.
rand
(
2
,
3
)
.
astype
(
self
.
dtype
)
x
=
self
.
shared
(
data
)
x
=
self
.
shared
(
data
)
y
=
theano
.
sparse
.
matrix
(
'csc'
,
dtype
=
self
.
dtype
,
name
=
'y'
)
y
=
theano
.
sparse
.
matrix
(
'csc'
,
dtype
=
self
.
dtype
,
name
=
'y'
)
...
@@ -375,7 +375,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -375,7 +375,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
f
=
theano
.
function
([
x1
,
x2
,
y1
,
y2
,
w1
,
w2
,
c
],
out
,
f
=
theano
.
function
([
x1
,
x2
,
y1
,
y2
,
w1
,
w2
,
c
],
out
,
allow_input_downcast
=
True
)
allow_input_downcast
=
True
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
vx1
=
rng
.
uniform
()
vx1
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
...
@@ -383,9 +383,9 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -383,9 +383,9 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
vw1
=
rng
.
uniform
()
vw1
=
rng
.
uniform
()
vw2
=
rng
.
uniform
()
vw2
=
rng
.
uniform
()
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
vx1
*
vy1
*
vw1
)
vx1
*
vy1
*
vw1
)
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
vx2
*
vy2
*
vw2
)
vx2
*
vy2
*
vw2
)
def
test_pushout3
(
self
):
def
test_pushout3
(
self
):
...
@@ -394,23 +394,23 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -394,23 +394,23 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
y1
=
tensor
.
scalar
(
'x2'
)
y1
=
tensor
.
scalar
(
'x2'
)
y2
=
tensor
.
scalar
(
'y2'
)
y2
=
tensor
.
scalar
(
'y2'
)
c
=
tensor
.
iscalar
(
'c'
)
c
=
tensor
.
iscalar
(
'c'
)
two
=
n
umpy
.
asarray
(
2
,
dtype
=
theano
.
config
.
floatX
)
two
=
n
p
.
asarray
(
2
,
dtype
=
theano
.
config
.
floatX
)
x
,
y
=
ifelse
(
c
,
(
x1
,
y1
),
(
two
,
y2
),
name
=
'f1'
)
x
,
y
=
ifelse
(
c
,
(
x1
,
y1
),
(
two
,
y2
),
name
=
'f1'
)
o3
=
n
umpy
.
asarray
(
0.3
,
dtype
=
theano
.
config
.
floatX
)
o3
=
n
p
.
asarray
(
0.3
,
dtype
=
theano
.
config
.
floatX
)
o2
=
n
umpy
.
asarray
(
0.2
,
dtype
=
theano
.
config
.
floatX
)
o2
=
n
p
.
asarray
(
0.2
,
dtype
=
theano
.
config
.
floatX
)
z
=
ifelse
(
c
,
o3
,
o2
,
name
=
'f2'
)
z
=
ifelse
(
c
,
o3
,
o2
,
name
=
'f2'
)
out
=
x
*
z
*
y
out
=
x
*
z
*
y
f
=
theano
.
function
([
x1
,
y1
,
y2
,
c
],
out
,
f
=
theano
.
function
([
x1
,
y1
,
y2
,
c
],
out
,
allow_input_downcast
=
True
)
allow_input_downcast
=
True
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
vx1
=
rng
.
uniform
()
vx1
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy2
=
rng
.
uniform
()
vy2
=
rng
.
uniform
()
assert
n
umpy
.
allclose
(
f
(
vx1
,
vy1
,
vy2
,
1
),
vx1
*
vy1
*
0.3
)
assert
n
p
.
allclose
(
f
(
vx1
,
vy1
,
vy2
,
1
),
vx1
*
vy1
*
0.3
)
assert
n
umpy
.
allclose
(
f
(
vx1
,
vy1
,
vy2
,
0
),
2
*
vy2
*
0.2
)
assert
n
p
.
allclose
(
f
(
vx1
,
vy1
,
vy2
,
0
),
2
*
vy2
*
0.2
)
def
test_pushout2
(
self
):
def
test_pushout2
(
self
):
raise
SkipTest
(
"Optimization temporarily disabled"
)
raise
SkipTest
(
"Optimization temporarily disabled"
)
...
@@ -428,7 +428,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -428,7 +428,7 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
f
=
theano
.
function
([
x1
,
x2
,
y1
,
y2
,
w1
,
w2
,
c
],
out
,
f
=
theano
.
function
([
x1
,
x2
,
y1
,
y2
,
w1
,
w2
,
c
],
out
,
allow_input_downcast
=
True
)
allow_input_downcast
=
True
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
IfElse
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
vx1
=
rng
.
uniform
()
vx1
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
...
@@ -439,14 +439,14 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -439,14 +439,14 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
vw
=
vw1
vw
=
vw1
else
:
else
:
vw
=
vw2
vw
=
vw2
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
vx1
*
vy1
*
vw
)
vx1
*
vy1
*
vw
)
if
vx2
>
vy2
:
if
vx2
>
vy2
:
vw
=
vw1
vw
=
vw1
else
:
else
:
vw
=
vw2
vw
=
vw2
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
vx2
*
vy2
*
vw
)
vx2
*
vy2
*
vw
)
def
test_merge_ifs_true_false
(
self
):
def
test_merge_ifs_true_false
(
self
):
...
@@ -467,16 +467,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -467,16 +467,16 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
assert
len
([
x
for
x
in
f
.
maker
.
fgraph
.
toposort
()
assert
len
([
x
for
x
in
f
.
maker
.
fgraph
.
toposort
()
if
isinstance
(
x
.
op
,
IfElse
)])
==
1
if
isinstance
(
x
.
op
,
IfElse
)])
==
1
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
vx1
=
rng
.
uniform
()
vx1
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vx2
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy1
=
rng
.
uniform
()
vy2
=
rng
.
uniform
()
vy2
=
rng
.
uniform
()
vw1
=
rng
.
uniform
()
vw1
=
rng
.
uniform
()
vw2
=
rng
.
uniform
()
vw2
=
rng
.
uniform
()
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
1
),
vx1
+
vy1
+
vw1
)
vx1
+
vy1
+
vw1
)
assert
n
umpy
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
assert
n
p
.
allclose
(
f
(
vx1
,
vx2
,
vy1
,
vy2
,
vw1
,
vw2
,
0
),
vx2
+
vy2
+
vw2
)
vx2
+
vy2
+
vw2
)
def
test_grad_test_values
(
self
):
def
test_grad_test_values
(
self
):
...
@@ -494,8 +494,8 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -494,8 +494,8 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
theano
.
config
.
compute_test_value
=
backup
theano
.
config
.
compute_test_value
=
backup
def
test_grad_int_value
(
self
):
def
test_grad_int_value
(
self
):
w
=
theano
.
shared
(
n
umpy
.
random
.
rand
(
10
))
w
=
theano
.
shared
(
n
p
.
random
.
rand
(
10
))
b
=
theano
.
shared
(
n
umpy
.
random
.
rand
())
b
=
theano
.
shared
(
n
p
.
random
.
rand
())
params
=
[
w
,
b
]
params
=
[
w
,
b
]
x
=
tensor
.
vector
()
x
=
tensor
.
vector
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论