Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cbceb887
提交
cbceb887
authored
3月 28, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make test execute more often on the GPU.
上级
de717450
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
69 行增加
和
41 行删除
+69
-41
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+2
-0
test_basic.py
theano/tensor/tests/test_basic.py
+67
-41
没有找到文件。
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
cbceb887
...
@@ -888,6 +888,8 @@ class T_subtensor(theano.tensor.tests.test_basic.T_subtensor):
...
@@ -888,6 +888,8 @@ class T_subtensor(theano.tensor.tests.test_basic.T_subtensor):
dtype
=
'float32'
dtype
=
'float32'
ignore_topo
=
(
B
.
HostFromGpu
,
B
.
GpuFromHost
)
ignore_topo
=
(
B
.
HostFromGpu
,
B
.
GpuFromHost
)
fast_compile
=
theano
.
config
.
mode
==
'FAST_COMPILE'
fast_compile
=
theano
.
config
.
mode
==
'FAST_COMPILE'
ops
=
(
cuda
.
GpuSubtensor
,
cuda
.
GpuIncSubtensor
,
cuda
.
GpuAdvancedSubtensor1
,
cuda
.
GpuAdvancedIncSubtensor1
)
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
return
super
(
theano
.
tensor
.
tests
.
test_basic
.
T_subtensor
,
return
super
(
theano
.
tensor
.
tests
.
test_basic
.
T_subtensor
,
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
cbceb887
...
@@ -2072,7 +2072,7 @@ class T_min_max(unittest.TestCase):
...
@@ -2072,7 +2072,7 @@ class T_min_max(unittest.TestCase):
#axis=1)[0], n)),axis=1)
#axis=1)[0], n)),axis=1)
class
T_subtensor
(
unittest
.
TestCase
):
class
T_subtensor
(
unittest
.
TestCase
,
utt
.
TestOptimizationMixin
):
"""
"""
This is build in a way that allow to reuse it to test the
This is build in a way that allow to reuse it to test the
equivalent gpu op.
equivalent gpu op.
...
@@ -2096,8 +2096,32 @@ class T_subtensor(unittest.TestCase):
...
@@ -2096,8 +2096,32 @@ class T_subtensor(unittest.TestCase):
self
.
dtype
=
dtype
self
.
dtype
=
dtype
self
.
ignore_topo
=
ignore_topo
self
.
ignore_topo
=
ignore_topo
self
.
fast_compile
=
theano
.
config
.
mode
==
'FAST_COMPILE'
self
.
fast_compile
=
theano
.
config
.
mode
==
'FAST_COMPILE'
self
.
ops
=
(
sub
,
inc_sub
,
adv_sub1
,
adv_incsub1
)
return
super
(
T_subtensor
,
self
)
.
__init__
(
name
)
return
super
(
T_subtensor
,
self
)
.
__init__
(
name
)
def
function
(
self
,
inputs
,
outputs
,
accept_inplace
=
False
,
op
=
None
,
mode
=
None
,
N
=
1
):
""" wrapper around theano.function that also check the output
:param N: the number of op expected in the toposort
if tuple of length 2, (expected if fast_compile,
if not fast_compile)
"""
if
isinstance
(
N
,
tuple
):
assert
len
(
N
)
==
2
if
self
.
fast_compile
:
N
=
N
[
0
]
else
:
N
=
N
[
1
]
if
mode
is
None
:
mode
=
self
.
mode
if
op
is
None
:
op
=
self
.
sub
f
=
theano
.
function
(
inputs
,
outputs
,
mode
=
mode
,
accept_inplace
=
accept_inplace
)
self
.
assertFunctionContainsClassN
(
f
,
op
,
N
)
return
f
def
setUp
(
self
):
def
setUp
(
self
):
Subtensor
.
debug
=
False
Subtensor
.
debug
=
False
utt
.
seed_rng
()
utt
.
seed_rng
()
...
@@ -2369,7 +2393,7 @@ class T_subtensor(unittest.TestCase):
...
@@ -2369,7 +2393,7 @@ class T_subtensor(unittest.TestCase):
n
=
self
.
shared
(
data
)
n
=
self
.
shared
(
data
)
t
=
n
[
1
,
0
]
t
=
n
[
1
,
0
]
gn
=
grad
(
sum
(
exp
(
t
)),
n
)
gn
=
grad
(
sum
(
exp
(
t
)),
n
)
f
=
function
([],
gn
,
mode
=
self
.
mode
)
f
=
self
.
function
([],
gn
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
if
not
self
.
fast_compile
:
if
not
self
.
fast_compile
:
...
@@ -2438,7 +2462,7 @@ class T_subtensor(unittest.TestCase):
...
@@ -2438,7 +2462,7 @@ class T_subtensor(unittest.TestCase):
# We test again AdvancedSubtensor1 as we transfer data to the cpu.
# We test again AdvancedSubtensor1 as we transfer data to the cpu.
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
tensor
.
AdvancedSubtensor1
))
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
tensor
.
AdvancedSubtensor1
))
f
=
function
([
l
],
t
,
mode
=
self
.
mode
)
f
=
self
.
function
([
l
],
t
,
op
=
self
.
adv_sub1
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
assert
len
(
topo_
)
==
1
assert
len
(
topo_
)
==
1
...
@@ -2453,7 +2477,7 @@ class T_subtensor(unittest.TestCase):
...
@@ -2453,7 +2477,7 @@ class T_subtensor(unittest.TestCase):
t
=
n
[
idx
]
t
=
n
[
idx
]
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
tensor
.
AdvancedSubtensor1
))
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
tensor
.
AdvancedSubtensor1
))
f
=
function
([
idx
],
t
,
mode
=
self
.
mode
)
f
=
self
.
function
([
idx
],
t
,
op
=
self
.
adv_sub1
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
assert
len
(
topo_
)
==
1
assert
len
(
topo_
)
==
1
...
@@ -2464,11 +2488,7 @@ class T_subtensor(unittest.TestCase):
...
@@ -2464,11 +2488,7 @@ class T_subtensor(unittest.TestCase):
def
test_shape_i_const
(
self
):
def
test_shape_i_const
(
self
):
# Each axis is treated independently by shape_i/shape operators
# Each axis is treated independently by shape_i/shape operators
mode_opt
=
config
.
mode
mode_opt
=
self
.
mode
.
including
(
"fast_run"
)
if
mode_opt
==
'FAST_COMPILE'
:
mode_opt
=
'FAST_RUN'
mode_opt
=
compile
.
mode
.
get_mode
(
mode_opt
)
data
=
self
.
shared
(
numpy
.
array
(
numpy
.
arange
(
5
),
dtype
=
self
.
dtype
))
data
=
self
.
shared
(
numpy
.
array
(
numpy
.
arange
(
5
),
dtype
=
self
.
dtype
))
for
start
in
[
None
]
+
[
-
8
,
-
5
,
-
1
,
0
,
1
,
5
,
8
]:
for
start
in
[
None
]
+
[
-
8
,
-
5
,
-
1
,
0
,
1
,
5
,
8
]:
outs
=
[]
outs
=
[]
...
@@ -2477,7 +2497,8 @@ class T_subtensor(unittest.TestCase):
...
@@ -2477,7 +2497,8 @@ class T_subtensor(unittest.TestCase):
for
step
in
[
None
]
+
[
-
3
,
-
1
,
2
]:
for
step
in
[
None
]
+
[
-
3
,
-
1
,
2
]:
outs
+=
[
data
[
start
:
stop
:
step
]
.
shape
]
outs
+=
[
data
[
start
:
stop
:
step
]
.
shape
]
shapes
+=
[
data
.
get_value
(
borrow
=
True
)[
start
:
stop
:
step
]
.
shape
]
shapes
+=
[
data
.
get_value
(
borrow
=
True
)[
start
:
stop
:
step
]
.
shape
]
f
=
function
([],
outs
,
mode
=
mode_opt
)
f
=
self
.
function
([],
outs
,
mode
=
mode_opt
,
op
=
self
.
ops
,
N
=
0
)
t_shapes
=
f
()
t_shapes
=
f
()
for
t_shape
,
shape
in
zip
(
t_shapes
,
shapes
):
for
t_shape
,
shape
in
zip
(
t_shapes
,
shapes
):
assert
numpy
.
all
(
t_shape
==
shape
)
assert
numpy
.
all
(
t_shape
==
shape
)
...
@@ -2487,17 +2508,18 @@ class T_subtensor(unittest.TestCase):
...
@@ -2487,17 +2508,18 @@ class T_subtensor(unittest.TestCase):
def
test_shape_i_scalar
(
self
):
def
test_shape_i_scalar
(
self
):
# Each axis is treated independently by shape_i/shape operators
# Each axis is treated independently by shape_i/shape operators
mode_opt
=
config
.
mode
mode_opt
=
self
.
mode
.
including
(
"fast_run"
)
if
mode_opt
==
'FAST_COMPILE'
:
mode_opt
=
'FAST_RUN'
mode_opt
=
compile
.
mode
.
get_mode
(
mode_opt
)
v_data
=
numpy
.
array
(
numpy
.
arange
(
5
),
dtype
=
self
.
dtype
)
v_data
=
numpy
.
array
(
numpy
.
arange
(
5
),
dtype
=
self
.
dtype
)
t_data
=
self
.
shared
(
v_data
)
t_data
=
self
.
shared
(
v_data
)
start
=
tensor
.
iscalar
(
'b'
)
start
=
tensor
.
iscalar
(
'b'
)
stop
=
tensor
.
iscalar
(
'e'
)
stop
=
tensor
.
iscalar
(
'e'
)
step
=
tensor
.
iscalar
(
's'
)
step
=
tensor
.
iscalar
(
's'
)
f
=
function
([
start
,
stop
,
step
],
t_data
[
start
:
stop
:
step
]
.
shape
,
mode
=
mode_opt
)
f
=
self
.
function
([
start
,
stop
,
step
],
f2
=
function
([
start
,
stop
,
step
],
t_data
[
start
:
stop
:
step
])
t_data
[
start
:
stop
:
step
]
.
shape
,
mode
=
mode_opt
,
op
=
self
.
ops
,
N
=
0
)
assert
tensor
.
Subtensor
not
in
[
x
.
op
for
x
in
f
.
maker
.
env
.
toposort
()]
assert
tensor
.
Subtensor
not
in
[
x
.
op
for
x
in
f
.
maker
.
env
.
toposort
()]
for
start
in
[
-
8
,
-
5
,
-
4
,
-
1
,
0
,
1
,
4
,
5
,
8
]:
for
start
in
[
-
8
,
-
5
,
-
4
,
-
1
,
0
,
1
,
4
,
5
,
8
]:
for
stop
in
[
-
8
,
-
5
,
-
4
,
-
1
,
0
,
1
,
4
,
5
,
8
]:
for
stop
in
[
-
8
,
-
5
,
-
4
,
-
1
,
0
,
1
,
4
,
5
,
8
]:
...
@@ -2511,11 +2533,11 @@ class T_subtensor(unittest.TestCase):
...
@@ -2511,11 +2533,11 @@ class T_subtensor(unittest.TestCase):
step
=
tensor
.
iscalar
(
's'
)
step
=
tensor
.
iscalar
(
's'
)
length
=
tensor
.
iscalar
(
'l'
)
length
=
tensor
.
iscalar
(
'l'
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
start
,
stop
,
step
),
length
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
start
,
stop
,
step
),
length
)
f
=
function
([
start
,
stop
,
step
,
length
],
[
f
=
self
.
function
([
start
,
stop
,
step
,
length
],
[
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
1
])
]
)
tensor
.
as_tensor_variable
(
cnf
[
1
])
],
N
=
0
,
op
=
self
.
ops
)
length
=
5
length
=
5
a
=
numpy
.
arange
(
length
)
a
=
numpy
.
arange
(
length
)
...
@@ -2533,11 +2555,11 @@ class T_subtensor(unittest.TestCase):
...
@@ -2533,11 +2555,11 @@ class T_subtensor(unittest.TestCase):
step
=
tensor
.
iscalar
(
's'
)
step
=
tensor
.
iscalar
(
's'
)
length
=
tensor
.
iscalar
(
'l'
)
length
=
tensor
.
iscalar
(
'l'
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
None
,
stop
,
step
),
length
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
None
,
stop
,
step
),
length
)
f
=
function
([
stop
,
step
,
length
],
[
f
=
self
.
function
([
stop
,
step
,
length
],
[
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
1
])
]
)
tensor
.
as_tensor_variable
(
cnf
[
1
])
],
N
=
0
,
op
=
self
.
ops
)
length
=
5
length
=
5
a
=
numpy
.
arange
(
length
)
a
=
numpy
.
arange
(
length
)
...
@@ -2555,11 +2577,11 @@ class T_subtensor(unittest.TestCase):
...
@@ -2555,11 +2577,11 @@ class T_subtensor(unittest.TestCase):
step
=
tensor
.
iscalar
(
's'
)
step
=
tensor
.
iscalar
(
's'
)
length
=
tensor
.
iscalar
(
'l'
)
length
=
tensor
.
iscalar
(
'l'
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
start
,
None
,
step
),
length
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
start
,
None
,
step
),
length
)
f
=
function
([
start
,
step
,
length
],
[
f
=
self
.
function
([
start
,
step
,
length
],
[
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
1
])
]
)
tensor
.
as_tensor_variable
(
cnf
[
1
])
],
N
=
0
,
op
=
self
.
ops
)
length
=
5
length
=
5
a
=
numpy
.
arange
(
length
)
a
=
numpy
.
arange
(
length
)
...
@@ -2577,11 +2599,11 @@ class T_subtensor(unittest.TestCase):
...
@@ -2577,11 +2599,11 @@ class T_subtensor(unittest.TestCase):
stop
=
tensor
.
iscalar
(
'e'
)
stop
=
tensor
.
iscalar
(
'e'
)
length
=
tensor
.
iscalar
(
'l'
)
length
=
tensor
.
iscalar
(
'l'
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
start
,
stop
,
None
),
length
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
start
,
stop
,
None
),
length
)
f
=
function
([
start
,
stop
,
length
],
[
f
=
self
.
function
([
start
,
stop
,
length
],
[
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
1
])
]
)
tensor
.
as_tensor_variable
(
cnf
[
1
])
],
N
=
0
,
op
=
self
.
ops
)
length
=
5
length
=
5
a
=
numpy
.
arange
(
length
)
a
=
numpy
.
arange
(
length
)
...
@@ -2597,11 +2619,11 @@ class T_subtensor(unittest.TestCase):
...
@@ -2597,11 +2619,11 @@ class T_subtensor(unittest.TestCase):
step
=
tensor
.
iscalar
(
's'
)
step
=
tensor
.
iscalar
(
's'
)
length
=
tensor
.
iscalar
(
'l'
)
length
=
tensor
.
iscalar
(
'l'
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
None
,
None
,
step
),
length
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
None
,
None
,
step
),
length
)
f
=
function
([
step
,
length
],
[
f
=
self
.
function
([
step
,
length
],
[
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
1
])
]
)
tensor
.
as_tensor_variable
(
cnf
[
1
])
],
N
=
0
,
op
=
self
.
ops
)
length
=
5
length
=
5
a
=
numpy
.
arange
(
length
)
a
=
numpy
.
arange
(
length
)
...
@@ -2617,11 +2639,11 @@ class T_subtensor(unittest.TestCase):
...
@@ -2617,11 +2639,11 @@ class T_subtensor(unittest.TestCase):
start
=
tensor
.
iscalar
(
'b'
)
start
=
tensor
.
iscalar
(
'b'
)
length
=
tensor
.
iscalar
(
'l'
)
length
=
tensor
.
iscalar
(
'l'
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
start
,
None
,
None
),
length
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
start
,
None
,
None
),
length
)
f
=
function
([
start
,
length
],
[
f
=
self
.
function
([
start
,
length
],
[
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
1
])
]
)
tensor
.
as_tensor_variable
(
cnf
[
1
])
],
N
=
0
,
op
=
self
.
ops
)
length
=
5
length
=
5
a
=
numpy
.
arange
(
length
)
a
=
numpy
.
arange
(
length
)
...
@@ -2636,11 +2658,11 @@ class T_subtensor(unittest.TestCase):
...
@@ -2636,11 +2658,11 @@ class T_subtensor(unittest.TestCase):
stop
=
tensor
.
iscalar
(
'e'
)
stop
=
tensor
.
iscalar
(
'e'
)
length
=
tensor
.
iscalar
(
'l'
)
length
=
tensor
.
iscalar
(
'l'
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
None
,
stop
,
None
),
length
)
cnf
=
tensor
.
get_canonical_form_slice
(
slice
(
None
,
stop
,
None
),
length
)
f
=
function
([
stop
,
length
],
[
f
=
self
.
function
([
stop
,
length
],
[
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
start
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
stop
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
0
]
.
step
),
tensor
.
as_tensor_variable
(
cnf
[
1
])
]
)
tensor
.
as_tensor_variable
(
cnf
[
1
])
],
N
=
0
,
op
=
self
.
ops
)
length
=
5
length
=
5
a
=
numpy
.
arange
(
length
)
a
=
numpy
.
arange
(
length
)
...
@@ -2659,7 +2681,7 @@ class T_subtensor(unittest.TestCase):
...
@@ -2659,7 +2681,7 @@ class T_subtensor(unittest.TestCase):
idx_
=
_shared
(
numpy
.
asarray
(
idx
))
idx_
=
_shared
(
numpy
.
asarray
(
idx
))
t
=
n
[
idx_
]
t
=
n
[
idx_
]
gn
=
grad
(
sum
(
exp
(
t
)),
n
)
gn
=
grad
(
sum
(
exp
(
t
)),
n
)
f
=
function
([],
[
gn
,
gn
.
shape
],
mode
=
self
.
mode
)
f
=
self
.
function
([],
[
gn
,
gn
.
shape
],
op
=
self
.
adv_incsub1
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
if
not
self
.
fast_compile
:
if
not
self
.
fast_compile
:
assert
any
([
isinstance
(
node
.
op
,
self
.
adv_incsub1
)
and
node
.
op
.
inplace
for
node
in
topo
])
assert
any
([
isinstance
(
node
.
op
,
self
.
adv_incsub1
)
and
node
.
op
.
inplace
for
node
in
topo
])
...
@@ -2685,12 +2707,14 @@ class T_subtensor(unittest.TestCase):
...
@@ -2685,12 +2707,14 @@ class T_subtensor(unittest.TestCase):
utt
.
verify_grad
(
fct
,
[
data
])
utt
.
verify_grad
(
fct
,
[
data
])
# Test shape of AdvancedIncSubtensor1 and AdvancedSubtensor1
# Test shape of AdvancedIncSubtensor1 and AdvancedSubtensor1
if
idx
is
idxs
[
0
]:
f
=
function
([],
[
gn
.
shape
,
n
[
idx_
]
.
shape
],
mode
=
self
.
mode
)
topo
=
f
.
maker
.
env
.
toposort
()
if
not
self
.
fast_compile
:
if
not
self
.
fast_compile
:
self
.
assertTrue
(
not
any
([
isinstance
(
node
.
op
,
self
.
adv_incsub1
)
for
node
in
topo
]))
ops
=
(
self
.
adv_incsub1
,
self
.
adv_sub1
)
self
.
assertTrue
(
not
any
([
isinstance
(
node
.
op
,
self
.
adv_sub1
)
for
node
in
topo
]))
else
:
ops
=
self
.
ops
if
idx
is
idxs
[
0
]:
f
=
self
.
function
([],
[
gn
.
shape
,
n
[
idx_
]
.
shape
],
op
=
ops
,
N
=
(
2
,
0
))
f
()
f
()
def
test_wrong_exception_regression
(
self
):
def
test_wrong_exception_regression
(
self
):
...
@@ -2743,7 +2767,7 @@ class T_subtensor(unittest.TestCase):
...
@@ -2743,7 +2767,7 @@ class T_subtensor(unittest.TestCase):
data
=
numpy
.
asarray
(
data
,
dtype
=
self
.
dtype
)
data
=
numpy
.
asarray
(
data
,
dtype
=
self
.
dtype
)
n
=
self
.
shared
(
data
)
n
=
self
.
shared
(
data
)
t
=
n
[
idx
]
t
=
n
[
idx
]
f
=
function
([],
t
.
shape
,
mode
=
None
)
f
=
self
.
function
([],
t
.
shape
,
op
=
self
.
ops
,
N
=
(
1
,
0
)
)
val
=
f
()
val
=
f
()
self
.
assertTrue
(
numpy
.
allclose
(
val
,
data
[
idx
]
.
shape
))
self
.
assertTrue
(
numpy
.
allclose
(
val
,
data
[
idx
]
.
shape
))
...
@@ -2852,8 +2876,9 @@ class T_subtensor(unittest.TestCase):
...
@@ -2852,8 +2876,9 @@ class T_subtensor(unittest.TestCase):
all_outputs_var
.
append
(
output
)
all_outputs_var
.
append
(
output
)
all_outputs_num
.
append
(
data_copy
)
all_outputs_num
.
append
(
data_copy
)
if
False
:
# Enable for debugging purpose.
if
False
:
# Enable for debugging purpose.
f
=
theano
.
function
([
data_var
,
idx_var
,
inc_var
],
f
=
self
.
function
([
data_var
,
idx_var
,
inc_var
],
output
,
accept_inplace
=
inplace
)
output
,
accept_inplace
=
inplace
,
op
=
self
.
adv_incsub1
)
if
inplace
:
if
inplace
:
# Ensure calling `f` will not alter `data_num`.
# Ensure calling `f` will not alter `data_num`.
data_num
=
data_num
.
copy
()
data_num
=
data_num
.
copy
()
...
@@ -2864,8 +2889,9 @@ class T_subtensor(unittest.TestCase):
...
@@ -2864,8 +2889,9 @@ class T_subtensor(unittest.TestCase):
assert
(
data_num
==
data_num_init
)
.
all
()
assert
(
data_num
==
data_num_init
)
.
all
()
# Actual test (we compile a single Theano function to make it faster).
# Actual test (we compile a single Theano function to make it faster).
f
=
theano
.
function
(
all_inputs_var
,
all_outputs_var
,
f
=
self
.
function
(
all_inputs_var
,
all_outputs_var
,
accept_inplace
=
True
)
accept_inplace
=
True
,
op
=
self
.
adv_incsub1
,
N
=
len
(
all_outputs_var
))
f_outs
=
f
(
*
all_inputs_num
)
f_outs
=
f
(
*
all_inputs_num
)
assert
len
(
f_outs
)
==
len
(
all_outputs_num
)
assert
len
(
f_outs
)
==
len
(
all_outputs_num
)
for
f_out
,
output_num
in
izip
(
f_outs
,
all_outputs_num
):
for
f_out
,
output_num
in
izip
(
f_outs
,
all_outputs_num
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论