Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
42750428
提交
42750428
authored
11月 21, 2016
作者:
Frédéric Bastien
提交者:
GitHub
11月 21, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5245 from lamblin/fix_subtensor_setsubtensor
Add tests for local_subtensor_inc_subtensor
上级
80c31e7b
f00f6ac5
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
116 行增加
和
83 行删除
+116
-83
test_opt.py
theano/tensor/tests/test_opt.py
+116
-82
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+0
-0
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/tensor/tests/test_opt.py
浏览文件 @
42750428
...
@@ -1882,76 +1882,122 @@ def test_local_subtensor_remove_broadcastable_index():
...
@@ -1882,76 +1882,122 @@ def test_local_subtensor_remove_broadcastable_index():
f2
(
xn
)
f2
(
xn
)
def
test_subtensor_inc_subtensor
():
class
Test_subtensor_inc_subtensor
(
unittest
.
TestCase
):
# basic test
@classmethod
x
=
tensor
.
matrix
(
'x'
)
def
setUpClass
(
cls
):
i
=
tensor
.
iscalar
(
'i'
)
cls
.
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'local_subtensor_inc_subtensor'
)
v
=
tensor
.
vector
(
'v'
)
y
=
tensor
.
set_subtensor
(
x
[
i
],
v
)
def
test_basic
(
self
):
z
=
y
[
i
]
# basic test
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'local_subtensor_inc_subtensor'
)
x
=
tensor
.
matrix
(
'x'
)
f
=
theano
.
function
([
x
,
i
,
v
],
z
,
mode
=
mode
)
i
=
tensor
.
iscalar
(
'i'
)
prog
=
f
.
maker
.
fgraph
.
toposort
()
v
=
tensor
.
vector
(
'v'
)
assert
len
(
prog
)
==
1
y
=
tensor
.
set_subtensor
(
x
[
i
],
v
)
assert
isinstance
(
prog
[
0
]
.
op
,
DeepCopyOp
)
z
=
y
[
i
]
# basic test, numerical check
f
=
theano
.
function
([
x
,
i
,
v
],
z
,
mode
=
self
.
mode
)
x_
=
numpy
.
random
.
uniform
(
size
=
[
3
,
4
])
.
astype
(
config
.
floatX
)
prog
=
f
.
maker
.
fgraph
.
toposort
()
v_
=
numpy
.
random
.
uniform
(
size
=
[
4
,
])
.
astype
(
config
.
floatX
)
assert
len
(
prog
)
==
1
i_
=
1
assert
isinstance
(
prog
[
0
]
.
op
,
DeepCopyOp
)
assert
numpy
.
array_equal
(
f
(
x_
,
i_
,
v_
),
v_
)
# basic test, numerical check
x_
=
numpy
.
random
.
uniform
(
size
=
[
3
,
4
])
.
astype
(
config
.
floatX
)
# complicated test
v_
=
numpy
.
random
.
uniform
(
size
=
[
4
,
])
.
astype
(
config
.
floatX
)
x
=
tensor
.
tensor4
(
'x'
)
i_
=
1
i1
=
tensor
.
iscalar
(
'i1'
)
assert
numpy
.
array_equal
(
f
(
x_
,
i_
,
v_
),
v_
)
i2
=
tensor
.
iscalar
(
'i2'
)
i3
=
tensor
.
iscalar
(
'i3'
)
def
test_multiple_idx
(
self
):
i4
=
tensor
.
iscalar
(
'i4'
)
# complicated test
v
=
tensor
.
tensor3
(
'v'
)
x
=
tensor
.
tensor4
(
'x'
)
y
=
tensor
.
set_subtensor
(
x
[
i1
,
:
i2
,
i3
:,
::
i4
],
v
)
i1
=
tensor
.
iscalar
(
'i1'
)
z
=
y
[
i1
,
:
i2
,
i3
:,
::
i4
]
i2
=
tensor
.
iscalar
(
'i2'
)
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'local_subtensor_inc_subtensor'
)
i3
=
tensor
.
iscalar
(
'i3'
)
f
=
theano
.
function
([
x
,
i1
,
i2
,
i3
,
i4
,
v
],
z
,
mode
=
mode
)
i4
=
tensor
.
iscalar
(
'i4'
)
prog
=
f
.
maker
.
fgraph
.
toposort
()
v
=
tensor
.
tensor3
(
'v'
)
assert
len
(
prog
)
==
1
y
=
tensor
.
set_subtensor
(
x
[
i1
,
:
i2
,
i3
:,
::
i4
],
v
)
assert
isinstance
(
prog
[
0
]
.
op
,
DeepCopyOp
)
z
=
y
[
i1
,
:
i2
,
i3
:,
::
i4
]
# complicated test, numerical check
f
=
theano
.
function
([
x
,
i1
,
i2
,
i3
,
i4
,
v
],
z
,
mode
=
self
.
mode
)
x_
=
numpy
.
random
.
uniform
(
size
=
[
3
,
4
,
5
,
6
])
.
astype
(
config
.
floatX
)
prog
=
f
.
maker
.
fgraph
.
toposort
()
v_
=
numpy
.
random
.
uniform
(
size
=
[
2
,
2
,
2
])
.
astype
(
config
.
floatX
)
assert
len
(
prog
)
==
1
i1_
,
i2_
,
i3_
,
i4_
=
1
,
2
,
3
,
4
assert
isinstance
(
prog
[
0
]
.
op
,
DeepCopyOp
)
assert
numpy
.
array_equal
(
f
(
x_
,
i1_
,
i2_
,
i3_
,
i4_
,
v_
),
v_
)
# complicated test, numerical check
x_
=
numpy
.
random
.
uniform
(
size
=
[
3
,
4
,
5
,
6
])
.
astype
(
config
.
floatX
)
# case not use this optimization
v_
=
numpy
.
random
.
uniform
(
size
=
[
2
,
2
,
2
])
.
astype
(
config
.
floatX
)
z
=
y
[
i1
,
:
i3
,
i2
:,
::
i4
]
i1_
,
i2_
,
i3_
,
i4_
=
1
,
2
,
3
,
4
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'local_subtensor_inc_subtensor'
)
assert
numpy
.
array_equal
(
f
(
x_
,
i1_
,
i2_
,
i3_
,
i4_
,
v_
),
v_
)
f
=
theano
.
function
([
x
,
i1
,
i2
,
i3
,
i4
,
v
],
z
,
mode
=
mode
)
prog
=
f
.
maker
.
fgraph
.
toposort
()
def
test_not_applied
(
self
):
assert
len
(
prog
)
!=
1
# case not use this optimization
assert
any
(
isinstance
(
x
.
op
,
tensor
.
IncSubtensor
)
for
x
in
prog
)
x
=
tensor
.
tensor4
(
'x'
)
assert
any
(
isinstance
(
x
.
op
,
tensor
.
Subtensor
)
for
x
in
prog
)
i1
=
tensor
.
iscalar
(
'i1'
)
# case not use this optimization, numerical check
i2
=
tensor
.
iscalar
(
'i2'
)
x_
=
numpy
.
random
.
uniform
(
size
=
[
3
,
4
,
5
,
6
])
.
astype
(
config
.
floatX
)
i3
=
tensor
.
iscalar
(
'i3'
)
v_
=
numpy
.
random
.
uniform
(
size
=
[
2
,
2
,
2
])
.
astype
(
config
.
floatX
)
i4
=
tensor
.
iscalar
(
'i4'
)
i1_
,
i2_
,
i3_
,
i4_
=
1
,
2
,
3
,
4
v
=
tensor
.
tensor3
(
'v'
)
x_
[
i1_
,
:
i2_
,
i3_
:,
::
i4_
]
=
v_
y
=
tensor
.
set_subtensor
(
x
[
i1
,
:
i2
,
i3
:,
::
i4
],
v
)
assert
numpy
.
array_equal
(
f
(
x_
,
i1_
,
i2_
,
i3_
,
i4_
,
v_
),
x_
[
i1_
,
:
i3_
,
i2_
:,
::
i4_
])
z
=
y
[
i1
,
:
i3
,
i2
:,
::
i4
]
f
=
theano
.
function
([
x
,
i1
,
i2
,
i3
,
i4
,
v
],
z
,
mode
=
self
.
mode
)
# case when v is broadcastable
prog
=
f
.
maker
.
fgraph
.
toposort
()
x
=
tensor
.
matrix
(
'x'
)
assert
len
(
prog
)
!=
1
i1
=
tensor
.
iscalar
(
'i'
)
assert
any
(
isinstance
(
x
.
op
,
tensor
.
IncSubtensor
)
for
x
in
prog
)
i2
=
tensor
.
iscalar
(
'i'
)
assert
any
(
isinstance
(
x
.
op
,
tensor
.
Subtensor
)
for
x
in
prog
)
v
=
tensor
.
vector
(
'v'
)
# case not use this optimization, numerical check
y
=
tensor
.
set_subtensor
(
x
[:
i1
,
:
i2
],
v
)
x_
=
numpy
.
random
.
uniform
(
size
=
[
3
,
4
,
5
,
6
])
.
astype
(
config
.
floatX
)
z
=
y
[:
i1
,
:
i2
]
v_
=
numpy
.
random
.
uniform
(
size
=
[
2
,
2
,
2
])
.
astype
(
config
.
floatX
)
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'local_subtensor_inc_subtensor'
)
i1_
,
i2_
,
i3_
,
i4_
=
1
,
2
,
3
,
4
f
=
theano
.
function
([
x
,
i1
,
i2
,
v
],
z
,
mode
=
mode
)
x_
[
i1_
,
:
i2_
,
i3_
:,
::
i4_
]
=
v_
prog
=
f
.
maker
.
fgraph
.
toposort
()
assert
numpy
.
array_equal
(
f
(
x_
,
i1_
,
i2_
,
i3_
,
i4_
,
v_
),
x_
[
i1_
,
:
i3_
,
i2_
:,
::
i4_
])
assert
any
(
isinstance
(
x
.
op
,
tensor
.
Alloc
)
for
x
in
prog
)
# case when v is broadcastable, numerical check
def
test_fewer_dims
(
self
):
x_
=
numpy
.
random
.
uniform
(
size
=
[
3
,
4
])
.
astype
(
config
.
floatX
)
# case when v has fewer dimensions
v_
=
numpy
.
random
.
uniform
(
size
=
[
2
,
])
.
astype
(
config
.
floatX
)
x
=
tensor
.
matrix
(
'x'
)
i1_
,
i2_
=
2
,
2
i1
=
tensor
.
iscalar
(
'i'
)
x_
[:
i1_
,
:
i2_
]
=
v_
i2
=
tensor
.
iscalar
(
'i'
)
assert
numpy
.
array_equal
(
f
(
x_
,
i1_
,
i2_
,
v_
),
x_
[:
i1_
,
:
i2_
])
v
=
tensor
.
vector
(
'v'
)
y
=
tensor
.
set_subtensor
(
x
[:
i1
,
:
i2
],
v
)
z
=
y
[:
i1
,
:
i2
]
f
=
theano
.
function
([
x
,
i1
,
i2
,
v
],
z
,
mode
=
self
.
mode
)
prog
=
f
.
maker
.
fgraph
.
toposort
()
assert
any
(
isinstance
(
x
.
op
,
tensor
.
Alloc
)
for
x
in
prog
)
# case when v is broadcastable, numerical check
x_
=
numpy
.
random
.
uniform
(
size
=
[
3
,
4
])
.
astype
(
config
.
floatX
)
v_
=
numpy
.
random
.
uniform
(
size
=
[
2
,
])
.
astype
(
config
.
floatX
)
i1_
,
i2_
=
2
,
2
x_
[:
i1_
,
:
i2_
]
=
v_
assert
numpy
.
array_equal
(
f
(
x_
,
i1_
,
i2_
,
v_
),
x_
[:
i1_
,
:
i2_
])
def
test_broadcasted
(
self
):
# case when v has the same number of dimensions, some broadcastable
x
=
tensor
.
matrix
(
'x'
)
i1
=
tensor
.
iscalar
(
'i'
)
i2
=
tensor
.
iscalar
(
'i'
)
v
=
tensor
.
col
(
'v'
)
y
=
tensor
.
set_subtensor
(
x
[:
i1
,
:
i2
],
v
)
z
=
y
[:
i1
,
:
i2
]
f
=
theano
.
function
([
x
,
i1
,
i2
,
v
],
z
,
mode
=
self
.
mode
)
prog
=
f
.
maker
.
fgraph
.
toposort
()
assert
any
(
isinstance
(
x
.
op
,
tensor
.
Alloc
)
for
x
in
prog
)
# case when v is broadcastable, numerical check
x_
=
numpy
.
random
.
uniform
(
size
=
[
3
,
4
])
.
astype
(
config
.
floatX
)
v_
=
numpy
.
random
.
uniform
(
size
=
[
2
,
1
])
.
astype
(
config
.
floatX
)
i1_
,
i2_
=
2
,
2
x_
[:
i1_
,
:
i2_
]
=
v_
assert
numpy
.
array_equal
(
f
(
x_
,
i1_
,
i2_
,
v_
),
x_
[:
i1_
,
:
i2_
])
def
test_different_dtypes
(
self
):
# Case when the dtype differs
x
=
tensor
.
bmatrix
(
'x'
)
i
=
tensor
.
iscalar
(
'i'
)
v
=
tensor
.
vector
(
'v'
)
y
=
tensor
.
set_subtensor
(
x
[
i
],
v
)
z
=
y
[
i
]
f
=
theano
.
function
([
x
,
i
,
v
],
z
,
mode
=
self
.
mode
)
prog
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
prog
)
==
1
assert
prog
[
0
]
.
op
==
tensor
.
basic
.
_convert_to_int8
# basic test, numerical check
x_
=
numpy
.
random
.
randint
(
12
,
size
=
[
3
,
4
])
.
astype
(
'int8'
)
v_
=
numpy
.
random
.
uniform
(
12
,
size
=
[
4
,
])
.
astype
(
config
.
floatX
)
i_
=
1
assert
numpy
.
array_equal
(
f
(
x_
,
i_
,
v_
),
v_
.
astype
(
'int8'
))
class
test_local_subtensor_make_vector
(
unittest
.
TestCase
):
class
test_local_subtensor_make_vector
(
unittest
.
TestCase
):
...
@@ -6763,15 +6809,3 @@ def test_local_log_sum_exp3():
...
@@ -6763,15 +6809,3 @@ def test_local_log_sum_exp3():
optimised_ret
=
f
(
x_val
)
optimised_ret
=
f
(
x_val
)
assert
numpy
.
allclose
(
optimised_ret
,
100.
)
assert
numpy
.
allclose
(
optimised_ret
,
100.
)
if
__name__
==
'__main__'
:
t
=
TestMakeVector
(
'setUp'
)
t
.
setUp
()
# t.test_perform()
t
.
test_infer_shape
()
test_subtensor_inc_subtensor
()
"""
# unittest.main()
test_fusion().tes_memory_leak()
"""
theano/tensor/tests/test_subtensor.py
浏览文件 @
42750428
差异被折叠。
点击展开。
theano/tests/test_flake8.py
浏览文件 @
42750428
...
@@ -46,7 +46,6 @@ whitelist_flake8 = [
...
@@ -46,7 +46,6 @@ whitelist_flake8 = [
"typed_list/tests/__init__.py"
,
"typed_list/tests/__init__.py"
,
"tensor/__init__.py"
,
"tensor/__init__.py"
,
"tensor/tests/__init__.py"
,
"tensor/tests/__init__.py"
,
"tensor/tests/test_subtensor.py"
,
"tensor/tests/test_utils.py"
,
"tensor/tests/test_utils.py"
,
"tensor/tests/test_nlinalg.py"
,
"tensor/tests/test_nlinalg.py"
,
"tensor/tests/test_shared_randomstreams.py"
,
"tensor/tests/test_shared_randomstreams.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论