Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
80728319
提交
80728319
authored
1月 26, 2017
作者:
Benjamin Scellier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
file theano/gpuarray/tests/test_subtensor.py
上级
e6576b19
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
22 行删除
+22
-22
test_subtensor.py
theano/gpuarray/tests/test_subtensor.py
+22
-22
没有找到文件。
theano/gpuarray/tests/test_subtensor.py
浏览文件 @
80728319
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
unittest
import
unittest
import
theano
import
theano
...
@@ -47,8 +47,8 @@ def test_advinc_subtensor1():
...
@@ -47,8 +47,8 @@ def test_advinc_subtensor1():
# Test the second case in the opt local_gpu_advanced_incsubtensor1
# Test the second case in the opt local_gpu_advanced_incsubtensor1
for
shp
in
[(
3
,
3
),
(
3
,
3
,
3
)]:
for
shp
in
[(
3
,
3
),
(
3
,
3
,
3
)]:
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
xval
=
n
umpy
.
arange
(
numpy
.
prod
(
shp
),
dtype
=
'float32'
)
.
reshape
(
shp
)
+
1
xval
=
n
p
.
arange
(
np
.
prod
(
shp
),
dtype
=
'float32'
)
.
reshape
(
shp
)
+
1
yval
=
n
umpy
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
'float32'
)
yval
=
n
p
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
'float32'
)
yval
[:]
=
10
yval
[:]
=
10
x
=
shared
(
xval
,
name
=
'x'
)
x
=
shared
(
xval
,
name
=
'x'
)
y
=
tensor
.
tensor
(
dtype
=
'float32'
,
y
=
tensor
.
tensor
(
dtype
=
'float32'
,
...
@@ -61,7 +61,7 @@ def test_advinc_subtensor1():
...
@@ -61,7 +61,7 @@ def test_advinc_subtensor1():
rval
=
f
(
yval
)
rval
=
f
(
yval
)
rep
=
xval
.
copy
()
rep
=
xval
.
copy
()
rep
[[
0
,
2
]]
+=
yval
rep
[[
0
,
2
]]
+=
yval
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
def
test_advinc_subtensor1_dtype
():
def
test_advinc_subtensor1_dtype
():
...
@@ -69,8 +69,8 @@ def test_advinc_subtensor1_dtype():
...
@@ -69,8 +69,8 @@ def test_advinc_subtensor1_dtype():
shp
=
(
3
,
4
)
shp
=
(
3
,
4
)
for
dtype1
,
dtype2
in
[(
'float32'
,
'int8'
),
(
'float32'
,
'float64'
)]:
for
dtype1
,
dtype2
in
[(
'float32'
,
'int8'
),
(
'float32'
,
'float64'
)]:
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
xval
=
n
umpy
.
arange
(
numpy
.
prod
(
shp
),
dtype
=
dtype1
)
.
reshape
(
shp
)
+
1
xval
=
n
p
.
arange
(
np
.
prod
(
shp
),
dtype
=
dtype1
)
.
reshape
(
shp
)
+
1
yval
=
n
umpy
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
dtype2
)
yval
=
n
p
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
dtype2
)
yval
[:]
=
10
yval
[:]
=
10
x
=
shared
(
xval
,
name
=
'x'
)
x
=
shared
(
xval
,
name
=
'x'
)
y
=
tensor
.
tensor
(
dtype
=
yval
.
dtype
,
y
=
tensor
.
tensor
(
dtype
=
yval
.
dtype
,
...
@@ -83,7 +83,7 @@ def test_advinc_subtensor1_dtype():
...
@@ -83,7 +83,7 @@ def test_advinc_subtensor1_dtype():
rval
=
f
(
yval
)
rval
=
f
(
yval
)
rep
=
xval
.
copy
()
rep
=
xval
.
copy
()
rep
[[
0
,
2
]]
+=
yval
rep
[[
0
,
2
]]
+=
yval
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
def
test_advinc_subtensor1_vector_scalar
():
def
test_advinc_subtensor1_vector_scalar
():
...
@@ -91,8 +91,8 @@ def test_advinc_subtensor1_vector_scalar():
...
@@ -91,8 +91,8 @@ def test_advinc_subtensor1_vector_scalar():
shp
=
(
3
,)
shp
=
(
3
,)
for
dtype1
,
dtype2
in
[(
'float32'
,
'int8'
),
(
'float32'
,
'float64'
)]:
for
dtype1
,
dtype2
in
[(
'float32'
,
'int8'
),
(
'float32'
,
'float64'
)]:
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
xval
=
n
umpy
.
arange
(
numpy
.
prod
(
shp
),
dtype
=
dtype1
)
.
reshape
(
shp
)
+
1
xval
=
n
p
.
arange
(
np
.
prod
(
shp
),
dtype
=
dtype1
)
.
reshape
(
shp
)
+
1
yval
=
n
umpy
.
asarray
(
10
,
dtype
=
dtype2
)
yval
=
n
p
.
asarray
(
10
,
dtype
=
dtype2
)
x
=
shared
(
xval
,
name
=
'x'
)
x
=
shared
(
xval
,
name
=
'x'
)
y
=
tensor
.
tensor
(
dtype
=
yval
.
dtype
,
y
=
tensor
.
tensor
(
dtype
=
yval
.
dtype
,
broadcastable
=
(
False
,)
*
len
(
yval
.
shape
),
broadcastable
=
(
False
,)
*
len
(
yval
.
shape
),
...
@@ -104,14 +104,14 @@ def test_advinc_subtensor1_vector_scalar():
...
@@ -104,14 +104,14 @@ def test_advinc_subtensor1_vector_scalar():
rval
=
f
(
yval
)
rval
=
f
(
yval
)
rep
=
xval
.
copy
()
rep
=
xval
.
copy
()
rep
[[
0
,
2
]]
+=
yval
rep
[[
0
,
2
]]
+=
yval
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
def
test_incsub_f16
():
def
test_incsub_f16
():
shp
=
(
3
,
3
)
shp
=
(
3
,
3
)
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
xval
=
n
umpy
.
arange
(
numpy
.
prod
(
shp
),
dtype
=
'float16'
)
.
reshape
(
shp
)
+
1
xval
=
n
p
.
arange
(
np
.
prod
(
shp
),
dtype
=
'float16'
)
.
reshape
(
shp
)
+
1
yval
=
n
umpy
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
'float16'
)
yval
=
n
p
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
'float16'
)
yval
[:]
=
2
yval
[:]
=
2
x
=
shared
(
xval
,
name
=
'x'
)
x
=
shared
(
xval
,
name
=
'x'
)
y
=
tensor
.
tensor
(
dtype
=
'float16'
,
y
=
tensor
.
tensor
(
dtype
=
'float16'
,
...
@@ -124,7 +124,7 @@ def test_incsub_f16():
...
@@ -124,7 +124,7 @@ def test_incsub_f16():
rval
=
f
(
yval
)
rval
=
f
(
yval
)
rep
=
xval
.
copy
()
rep
=
xval
.
copy
()
rep
[[
0
,
2
]]
+=
yval
rep
[[
0
,
2
]]
+=
yval
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
expr
=
tensor
.
inc_subtensor
(
x
[
1
:],
y
)
expr
=
tensor
.
inc_subtensor
(
x
[
1
:],
y
)
f
=
theano
.
function
([
y
],
expr
,
mode
=
mode_with_gpu
)
f
=
theano
.
function
([
y
],
expr
,
mode
=
mode_with_gpu
)
...
@@ -133,7 +133,7 @@ def test_incsub_f16():
...
@@ -133,7 +133,7 @@ def test_incsub_f16():
rval
=
f
(
yval
)
rval
=
f
(
yval
)
rep
=
xval
.
copy
()
rep
=
xval
.
copy
()
rep
[
1
:]
+=
yval
rep
[
1
:]
+=
yval
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
class
G_advancedsubtensor
(
test_subtensor
.
TestAdvancedSubtensor
):
class
G_advancedsubtensor
(
test_subtensor
.
TestAdvancedSubtensor
):
...
@@ -159,7 +159,7 @@ def test_adv_subtensor():
...
@@ -159,7 +159,7 @@ def test_adv_subtensor():
# Test the advancedsubtensor on gpu.
# Test the advancedsubtensor on gpu.
shp
=
(
2
,
3
,
4
)
shp
=
(
2
,
3
,
4
)
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
xval
=
n
umpy
.
arange
(
numpy
.
prod
(
shp
),
dtype
=
theano
.
config
.
floatX
)
.
reshape
(
shp
)
xval
=
n
p
.
arange
(
np
.
prod
(
shp
),
dtype
=
theano
.
config
.
floatX
)
.
reshape
(
shp
)
idx1
,
idx2
=
tensor
.
ivectors
(
'idx1'
,
'idx2'
)
idx1
,
idx2
=
tensor
.
ivectors
(
'idx1'
,
'idx2'
)
idxs
=
[
idx1
,
None
,
slice
(
0
,
2
,
1
),
idx2
,
None
]
idxs
=
[
idx1
,
None
,
slice
(
0
,
2
,
1
),
idx2
,
None
]
x
=
shared
(
xval
,
name
=
'x'
)
x
=
shared
(
xval
,
name
=
'x'
)
...
@@ -171,27 +171,27 @@ def test_adv_subtensor():
...
@@ -171,27 +171,27 @@ def test_adv_subtensor():
idx2_val
=
[
0
,
1
]
idx2_val
=
[
0
,
1
]
rval
=
f
(
idx1_val
,
idx2_val
)
rval
=
f
(
idx1_val
,
idx2_val
)
rep
=
xval
[
idx1_val
,
None
,
slice
(
0
,
2
,
1
),
idx2_val
,
None
]
rep
=
xval
[
idx1_val
,
None
,
slice
(
0
,
2
,
1
),
idx2_val
,
None
]
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
class
test_gpudiagonal
(
unittest
.
TestCase
):
class
test_gpudiagonal
(
unittest
.
TestCase
):
def
test_matrix
(
self
):
def
test_matrix
(
self
):
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
np_x
=
n
umpy
.
arange
(
77
)
.
reshape
(
7
,
11
)
.
astype
(
theano
.
config
.
floatX
)
np_x
=
n
p
.
arange
(
77
)
.
reshape
(
7
,
11
)
.
astype
(
theano
.
config
.
floatX
)
fn
=
theano
.
function
([
x
],
GpuDiagonal
()(
x
),
mode
=
mode_with_gpu
)
fn
=
theano
.
function
([
x
],
GpuDiagonal
()(
x
),
mode
=
mode_with_gpu
)
assert
n
umpy
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
())
assert
n
p
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
())
fn
=
theano
.
function
([
x
],
GpuDiagonal
(
2
)(
x
),
mode
=
mode_with_gpu
)
fn
=
theano
.
function
([
x
],
GpuDiagonal
(
2
)(
x
),
mode
=
mode_with_gpu
)
assert
n
umpy
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
(
2
))
assert
n
p
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
(
2
))
fn
=
theano
.
function
([
x
],
GpuDiagonal
(
-
3
)(
x
),
mode
=
mode_with_gpu
)
fn
=
theano
.
function
([
x
],
GpuDiagonal
(
-
3
)(
x
),
mode
=
mode_with_gpu
)
assert
n
umpy
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
(
-
3
))
assert
n
p
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
(
-
3
))
def
test_tensor
(
self
):
def
test_tensor
(
self
):
x
=
tensor
.
tensor4
()
x
=
tensor
.
tensor4
()
np_x
=
n
umpy
.
arange
(
30107
)
.
reshape
(
7
,
11
,
17
,
23
)
.
astype
(
theano
.
config
.
floatX
)
np_x
=
n
p
.
arange
(
30107
)
.
reshape
(
7
,
11
,
17
,
23
)
.
astype
(
theano
.
config
.
floatX
)
for
offset
,
axis1
,
axis2
in
[
for
offset
,
axis1
,
axis2
in
[
(
1
,
0
,
1
),
(
-
1
,
0
,
1
),
(
0
,
1
,
0
),
(
-
2
,
1
,
0
),
(
1
,
0
,
1
),
(
-
1
,
0
,
1
),
(
0
,
1
,
0
),
(
-
2
,
1
,
0
),
(
-
3
,
1
,
0
),
(
-
2
,
2
,
0
),
(
3
,
3
,
0
),
(
-
1
,
3
,
2
),
(
-
3
,
1
,
0
),
(
-
2
,
2
,
0
),
(
3
,
3
,
0
),
(
-
1
,
3
,
2
),
(
2
,
2
,
3
),
(
-
1
,
2
,
1
),
(
1
,
3
,
1
),
(
-
1
,
1
,
3
)]:
(
2
,
2
,
3
),
(
-
1
,
2
,
1
),
(
1
,
3
,
1
),
(
-
1
,
1
,
3
)]:
assert
n
umpy
.
allclose
(
assert
n
p
.
allclose
(
GpuDiagonal
(
offset
,
axis1
,
axis2
)(
x
)
.
eval
({
x
:
np_x
}),
GpuDiagonal
(
offset
,
axis1
,
axis2
)(
x
)
.
eval
({
x
:
np_x
}),
np_x
.
diagonal
(
offset
,
axis1
,
axis2
))
np_x
.
diagonal
(
offset
,
axis1
,
axis2
))
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论