Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
57c8ffdc
提交
57c8ffdc
authored
1月 26, 2017
作者:
Benjamin Scellier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
file theano/gpuarray/tests/test_basic_ops.py
上级
e589234b
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
34 行增加
和
34 行删除
+34
-34
test_basic_ops.py
theano/gpuarray/tests/test_basic_ops.py
+34
-34
没有找到文件。
theano/gpuarray/tests/test_basic_ops.py
浏览文件 @
57c8ffdc
...
@@ -4,7 +4,7 @@ from theano.compat import izip
...
@@ -4,7 +4,7 @@ from theano.compat import izip
from
six
import
iteritems
from
six
import
iteritems
import
numpy
import
numpy
as
np
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
from
theano.tensor
import
TensorType
from
theano.tensor
import
TensorType
...
@@ -29,7 +29,7 @@ from .config import mode_with_gpu, mode_without_gpu, test_ctx_name
...
@@ -29,7 +29,7 @@ from .config import mode_with_gpu, mode_without_gpu, test_ctx_name
from
pygpu
import
gpuarray
from
pygpu
import
gpuarray
utt
.
seed_rng
()
utt
.
seed_rng
()
rng
=
n
umpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
def
inplace_func
(
inputs
,
outputs
,
mode
=
None
,
allow_input_downcast
=
False
,
def
inplace_func
(
inputs
,
outputs
,
mode
=
None
,
allow_input_downcast
=
False
,
...
@@ -92,7 +92,7 @@ def makeTester(name, op, gpu_op, cases, checks=None, mode_gpu=mode_with_gpu,
...
@@ -92,7 +92,7 @@ def makeTester(name, op, gpu_op, cases, checks=None, mode_gpu=mode_with_gpu,
for
testname
,
inputs
in
iteritems
(
cases
):
for
testname
,
inputs
in
iteritems
(
cases
):
for
_
in
range
(
len
(
inputs
)):
for
_
in
range
(
len
(
inputs
)):
if
type
(
inputs
[
_
])
is
float
:
if
type
(
inputs
[
_
])
is
float
:
inputs
[
_
]
=
n
umpy
.
asarray
(
inputs
[
_
],
inputs
[
_
]
=
n
p
.
asarray
(
inputs
[
_
],
dtype
=
theano
.
config
.
floatX
)
dtype
=
theano
.
config
.
floatX
)
self
.
run_case
(
testname
,
inputs
)
self
.
run_case
(
testname
,
inputs
)
...
@@ -177,7 +177,7 @@ def test_transfer_cpu_gpu():
...
@@ -177,7 +177,7 @@ def test_transfer_cpu_gpu():
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
))(
'g'
)
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
))(
'g'
)
av
=
n
umpy
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
'float32'
)
av
=
n
p
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
'float32'
)
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
f
=
theano
.
function
([
a
],
GpuFromHost
(
test_ctx_name
)(
a
))
f
=
theano
.
function
([
a
],
GpuFromHost
(
test_ctx_name
)(
a
))
...
@@ -186,14 +186,14 @@ def test_transfer_cpu_gpu():
...
@@ -186,14 +186,14 @@ def test_transfer_cpu_gpu():
f
=
theano
.
function
([
g
],
host_from_gpu
(
g
))
f
=
theano
.
function
([
g
],
host_from_gpu
(
g
))
fv
=
f
(
gv
)
fv
=
f
(
gv
)
assert
n
umpy
.
all
(
fv
==
av
)
assert
n
p
.
all
(
fv
==
av
)
def
test_transfer_gpu_gpu
():
def
test_transfer_gpu_gpu
():
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
),
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
),
context_name
=
test_ctx_name
)()
context_name
=
test_ctx_name
)()
av
=
n
umpy
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
'float32'
)
av
=
n
p
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
'float32'
)
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
mode
=
mode_with_gpu
.
excluding
(
'cut_gpua_host_transfers'
,
'local_cut_gpua_host_gpua'
)
mode
=
mode_with_gpu
.
excluding
(
'cut_gpua_host_transfers'
,
'local_cut_gpua_host_gpua'
)
f
=
theano
.
function
([
g
],
GpuToGpu
(
test_ctx_name
)(
g
),
mode
=
mode
)
f
=
theano
.
function
([
g
],
GpuToGpu
(
test_ctx_name
)(
g
),
mode
=
mode
)
...
@@ -211,7 +211,7 @@ def test_transfer_strided():
...
@@ -211,7 +211,7 @@ def test_transfer_strided():
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
))(
'g'
)
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
))(
'g'
)
av
=
n
umpy
.
asarray
(
rng
.
rand
(
5
,
8
),
dtype
=
'float32'
)
av
=
n
p
.
asarray
(
rng
.
rand
(
5
,
8
),
dtype
=
'float32'
)
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
av
=
av
[:,
::
2
]
av
=
av
[:,
::
2
]
...
@@ -223,7 +223,7 @@ def test_transfer_strided():
...
@@ -223,7 +223,7 @@ def test_transfer_strided():
f
=
theano
.
function
([
g
],
host_from_gpu
(
g
))
f
=
theano
.
function
([
g
],
host_from_gpu
(
g
))
fv
=
f
(
gv
)
fv
=
f
(
gv
)
assert
n
umpy
.
all
(
fv
==
av
)
assert
n
p
.
all
(
fv
==
av
)
def
gpu_alloc_expected
(
x
,
*
shp
):
def
gpu_alloc_expected
(
x
,
*
shp
):
...
@@ -237,16 +237,16 @@ GpuAllocTester = makeTester(
...
@@ -237,16 +237,16 @@ GpuAllocTester = makeTester(
op
=
alloc
,
op
=
alloc
,
gpu_op
=
GpuAlloc
(
test_ctx_name
),
gpu_op
=
GpuAlloc
(
test_ctx_name
),
cases
=
dict
(
cases
=
dict
(
correct01
=
(
rand
(),
n
umpy
.
int32
(
7
)),
correct01
=
(
rand
(),
n
p
.
int32
(
7
)),
# just gives a DeepCopyOp with possibly wrong results on the CPU
# just gives a DeepCopyOp with possibly wrong results on the CPU
# correct01_bcast=(rand(1), n
umpy
.int32(7)),
# correct01_bcast=(rand(1), n
p
.int32(7)),
correct02
=
(
rand
(),
n
umpy
.
int32
(
4
),
numpy
.
int32
(
7
)),
correct02
=
(
rand
(),
n
p
.
int32
(
4
),
np
.
int32
(
7
)),
correct12
=
(
rand
(
7
),
n
umpy
.
int32
(
4
),
numpy
.
int32
(
7
)),
correct12
=
(
rand
(
7
),
n
p
.
int32
(
4
),
np
.
int32
(
7
)),
correct13
=
(
rand
(
7
),
n
umpy
.
int32
(
2
),
numpy
.
int32
(
4
),
correct13
=
(
rand
(
7
),
n
p
.
int32
(
2
),
np
.
int32
(
4
),
n
umpy
.
int32
(
7
)),
n
p
.
int32
(
7
)),
correct23
=
(
rand
(
4
,
7
),
n
umpy
.
int32
(
2
),
numpy
.
int32
(
4
),
correct23
=
(
rand
(
4
,
7
),
n
p
.
int32
(
2
),
np
.
int32
(
4
),
n
umpy
.
int32
(
7
)),
n
p
.
int32
(
7
)),
bad_shape12
=
(
rand
(
7
),
n
umpy
.
int32
(
7
),
numpy
.
int32
(
5
)),
bad_shape12
=
(
rand
(
7
),
n
p
.
int32
(
7
),
np
.
int32
(
5
)),
)
)
)
)
...
@@ -282,7 +282,7 @@ def test_shape():
...
@@ -282,7 +282,7 @@ def test_shape():
v
=
gpuarray
.
zeros
((
3
,
4
,
5
),
dtype
=
'float32'
,
context
=
get_context
(
test_ctx_name
))
v
=
gpuarray
.
zeros
((
3
,
4
,
5
),
dtype
=
'float32'
,
context
=
get_context
(
test_ctx_name
))
f
=
theano
.
function
([
x
],
x
.
shape
)
f
=
theano
.
function
([
x
],
x
.
shape
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
n
umpy
.
all
(
f
(
v
)
==
(
3
,
4
,
5
))
assert
n
p
.
all
(
f
(
v
)
==
(
3
,
4
,
5
))
if
theano
.
config
.
mode
!=
'FAST_COMPILE'
:
if
theano
.
config
.
mode
!=
'FAST_COMPILE'
:
assert
len
(
topo
)
==
4
assert
len
(
topo
)
==
4
assert
isinstance
(
topo
[
0
]
.
op
,
T
.
opt
.
Shape_i
)
assert
isinstance
(
topo
[
0
]
.
op
,
T
.
opt
.
Shape_i
)
...
@@ -292,7 +292,7 @@ def test_shape():
...
@@ -292,7 +292,7 @@ def test_shape():
mode
=
mode_with_gpu
.
excluding
(
"local_shape_to_shape_i"
)
mode
=
mode_with_gpu
.
excluding
(
"local_shape_to_shape_i"
)
f
=
theano
.
function
([
x
],
x
.
shape
,
mode
=
mode
)
f
=
theano
.
function
([
x
],
x
.
shape
,
mode
=
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
n
umpy
.
all
(
f
(
v
)
==
(
3
,
4
,
5
))
assert
n
p
.
all
(
f
(
v
)
==
(
3
,
4
,
5
))
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
T
.
Shape
)
assert
isinstance
(
topo
[
0
]
.
op
,
T
.
Shape
)
...
@@ -300,7 +300,7 @@ def test_shape():
...
@@ -300,7 +300,7 @@ def test_shape():
def
test_gpu_contiguous
():
def
test_gpu_contiguous
():
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
i
=
T
.
iscalar
(
'i'
)
i
=
T
.
iscalar
(
'i'
)
a_val
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
a_val
=
n
p
.
asarray
(
np
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
# The reshape is needed otherwise we make the subtensor on the CPU
# The reshape is needed otherwise we make the subtensor on the CPU
# to transfer less data.
# to transfer less data.
f
=
theano
.
function
([
a
,
i
],
gpu_contiguous
(
a
.
reshape
((
5
,
4
))[::
i
]),
f
=
theano
.
function
([
a
,
i
],
gpu_contiguous
(
a
.
reshape
((
5
,
4
))[::
i
]),
...
@@ -353,22 +353,22 @@ class G_Join_and_Split(test_basic.T_Join_and_Split):
...
@@ -353,22 +353,22 @@ class G_Join_and_Split(test_basic.T_Join_and_Split):
self
.
shared
=
gpuarray_shared_constructor
self
.
shared
=
gpuarray_shared_constructor
def
test_gpusplit_opt
(
self
):
def
test_gpusplit_opt
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
m
=
self
.
shared
(
rng
.
rand
(
4
,
6
)
.
astype
(
self
.
floatX
))
m
=
self
.
shared
(
rng
.
rand
(
4
,
6
)
.
astype
(
self
.
floatX
))
o
=
T
.
Split
(
2
)(
m
,
0
,
[
2
,
2
])
o
=
T
.
Split
(
2
)(
m
,
0
,
[
2
,
2
])
f
=
theano
.
function
([],
o
,
mode
=
self
.
mode
)
f
=
theano
.
function
([],
o
,
mode
=
self
.
mode
)
assert
any
([
isinstance
(
node
.
op
,
self
.
split_op_class
)
assert
any
([
isinstance
(
node
.
op
,
self
.
split_op_class
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
o1
,
o2
=
f
()
o1
,
o2
=
f
()
assert
n
umpy
.
allclose
(
o1
,
m
.
get_value
(
borrow
=
True
)[:
2
])
assert
n
p
.
allclose
(
o1
,
m
.
get_value
(
borrow
=
True
)[:
2
])
assert
n
umpy
.
allclose
(
o2
,
m
.
get_value
(
borrow
=
True
)[
2
:])
assert
n
p
.
allclose
(
o2
,
m
.
get_value
(
borrow
=
True
)[
2
:])
def
test_gpujoin_gpualloc
():
def
test_gpujoin_gpualloc
():
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
a_val
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
a_val
=
n
p
.
asarray
(
np
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
b
=
T
.
fmatrix
(
'b'
)
b
=
T
.
fmatrix
(
'b'
)
b_val
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
3
,
5
),
dtype
=
'float32'
)
b_val
=
n
p
.
asarray
(
np
.
random
.
rand
(
3
,
5
),
dtype
=
'float32'
)
f
=
theano
.
function
([
a
,
b
],
T
.
join
(
0
,
T
.
zeros_like
(
a
),
T
.
ones_like
(
b
))
+
4
,
f
=
theano
.
function
([
a
,
b
],
T
.
join
(
0
,
T
.
zeros_like
(
a
),
T
.
ones_like
(
b
))
+
4
,
mode
=
mode_without_gpu
)
mode
=
mode_without_gpu
)
...
@@ -387,7 +387,7 @@ def test_gpujoin_gpualloc():
...
@@ -387,7 +387,7 @@ def test_gpujoin_gpualloc():
for
node
in
f_gpu2
.
maker
.
fgraph
.
toposort
()])
==
2
for
node
in
f_gpu2
.
maker
.
fgraph
.
toposort
()])
==
2
assert
sum
([
node
.
op
==
gpu_join
assert
sum
([
node
.
op
==
gpu_join
for
node
in
f_gpu2
.
maker
.
fgraph
.
toposort
()])
==
1
for
node
in
f_gpu2
.
maker
.
fgraph
.
toposort
()])
==
1
assert
n
umpy
.
allclose
(
f
(
a_val
,
b_val
),
f_gpu2
(
a_val
,
b_val
))
assert
n
p
.
allclose
(
f
(
a_val
,
b_val
),
f_gpu2
(
a_val
,
b_val
))
def
test_gpueye
():
def
test_gpueye
():
...
@@ -401,14 +401,14 @@ def test_gpueye():
...
@@ -401,14 +401,14 @@ def test_gpueye():
M
=
N
M
=
N
N_symb
=
T
.
iscalar
()
N_symb
=
T
.
iscalar
()
M_symb
=
T
.
iscalar
()
M_symb
=
T
.
iscalar
()
k_symb
=
n
umpy
.
asarray
(
0
)
k_symb
=
n
p
.
asarray
(
0
)
out
=
T
.
eye
(
N_symb
,
M_symb
,
k_symb
,
dtype
=
dtype
)
out
=
T
.
eye
(
N_symb
,
M_symb
,
k_symb
,
dtype
=
dtype
)
f
=
theano
.
function
([
N_symb
,
M_symb
],
f
=
theano
.
function
([
N_symb
,
M_symb
],
T
.
stack
(
out
),
T
.
stack
(
out
),
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
result
=
n
umpy
.
asarray
(
f
(
N
,
M
))
result
=
n
p
.
asarray
(
f
(
N
,
M
))
assert
n
umpy
.
allclose
(
result
,
numpy
.
eye
(
N
,
M_
,
dtype
=
dtype
))
assert
n
p
.
allclose
(
result
,
np
.
eye
(
N
,
M_
,
dtype
=
dtype
))
assert
result
.
dtype
==
n
umpy
.
dtype
(
dtype
)
assert
result
.
dtype
==
n
p
.
dtype
(
dtype
)
assert
any
([
isinstance
(
node
.
op
,
GpuEye
)
assert
any
([
isinstance
(
node
.
op
,
GpuEye
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
...
@@ -429,8 +429,8 @@ def test_hostfromgpu_shape_i():
...
@@ -429,8 +429,8 @@ def test_hostfromgpu_shape_i():
'specialize'
)
'specialize'
)
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
ca
=
theano
.
gpuarray
.
type
.
GpuArrayType
(
'float32'
,
(
False
,
False
))()
ca
=
theano
.
gpuarray
.
type
.
GpuArrayType
(
'float32'
,
(
False
,
False
))()
av
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
5
,
4
),
dtype
=
'float32'
)
av
=
n
p
.
asarray
(
np
.
random
.
rand
(
5
,
4
),
dtype
=
'float32'
)
cv
=
gpuarray
.
asarray
(
n
umpy
.
random
.
rand
(
5
,
4
),
cv
=
gpuarray
.
asarray
(
n
p
.
random
.
rand
(
5
,
4
),
dtype
=
'float32'
,
dtype
=
'float32'
,
context
=
get_context
(
test_ctx_name
))
context
=
get_context
(
test_ctx_name
))
...
@@ -464,7 +464,7 @@ def test_Gpujoin_inplace():
...
@@ -464,7 +464,7 @@ def test_Gpujoin_inplace():
non-empty element.
non-empty element.
"""
"""
s
=
T
.
lscalar
()
s
=
T
.
lscalar
()
data
=
n
umpy
.
array
([
3
,
4
,
5
],
dtype
=
theano
.
config
.
floatX
)
data
=
n
p
.
array
([
3
,
4
,
5
],
dtype
=
theano
.
config
.
floatX
)
x
=
gpuarray_shared_constructor
(
data
,
borrow
=
True
)
x
=
gpuarray_shared_constructor
(
data
,
borrow
=
True
)
z
=
T
.
zeros
((
s
,))
z
=
T
.
zeros
((
s
,))
...
@@ -473,4 +473,4 @@ def test_Gpujoin_inplace():
...
@@ -473,4 +473,4 @@ def test_Gpujoin_inplace():
f
=
theano
.
function
([
s
],
theano
.
Out
(
c
,
borrow
=
True
))
f
=
theano
.
function
([
s
],
theano
.
Out
(
c
,
borrow
=
True
))
assert
x
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
is
f
(
0
)
assert
x
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
is
f
(
0
)
assert
n
umpy
.
allclose
(
f
(
0
),
[
3
,
4
,
5
])
assert
n
p
.
allclose
(
f
(
0
),
[
3
,
4
,
5
])
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论