Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
19a6bd40
提交
19a6bd40
authored
3月 16, 2016
作者:
Chiheb Trabelsi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test_cuda_ndarray.py has been modified in order to respect the flake8 style.
上级
791d4871
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
94 行增加
和
122 行删除
+94
-122
test_cuda_ndarray.py
theano/sandbox/cuda/tests/test_cuda_ndarray.py
+94
-122
没有找到文件。
theano/sandbox/cuda/tests/test_cuda_ndarray.py
浏览文件 @
19a6bd40
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
time
,
copy
,
sys
,
unittest
import
copy
import
unittest
# Skip test if cuda_ndarray is not available.
# Skip test if cuda_ndarray is not available.
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
...
@@ -32,7 +33,7 @@ def advantage(cpu_dt, gpu_dt):
...
@@ -32,7 +33,7 @@ def advantage(cpu_dt, gpu_dt):
def
test_host_to_device
():
def
test_host_to_device
():
#print >>sys.stdout, 'starting test_host_to_dev'
#
print >>sys.stdout, 'starting test_host_to_dev'
for
shape
in
((),
(
3
,),
(
2
,
3
),
(
3
,
4
,
5
,
6
)):
for
shape
in
((),
(
3
,),
(
2
,
3
),
(
3
,
4
,
5
,
6
)):
a
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
a
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
b
=
cuda_ndarray
.
CudaNdarray
(
a
)
b
=
cuda_ndarray
.
CudaNdarray
(
a
)
...
@@ -52,30 +53,29 @@ def test_host_to_device():
...
@@ -52,30 +53,29 @@ def test_host_to_device():
def
test_add_iadd_idiv
():
def
test_add_iadd_idiv
():
for
shapes
in
(
for
shapes
in
([(
5
,
5
),
(
5
,
1
)],
[(
5
,
5
),
(
5
,
1
)],
[(
5
,
5
),
(
1
,
5
)],
[(
5
,
5
),
(
1
,
5
)],
(),
(
0
,),
(
3
,),
(
2
,
3
),
(),
(
0
,),
(
3
,),
(
2
,
3
),
(
1
,
10000000
),
(
10000
,
1000
),
(
1000000
,
10
),
(
1
,
10000000
),
(
10000
,
1000
),
(
1000000
,
10
),
(
4100
,
33
,
34
),
(
33
,
4100
,
34
),
(
33
,
34
,
4100
),
(
4100
,
33
,
34
),
(
33
,
4100
,
34
),
(
33
,
34
,
4100
),
(
4100
,
33
,
3
,
6
),
(
33
,
4100
,
3
,
6
),
(
33
,
3
,
4100
,
6
),
(
33
,
3
,
6
,
4100
),
(
4100
,
33
,
3
,
6
),
(
33
,
4100
,
3
,
6
),
(
33
,
3
,
4100
,
6
),
(
33
,
3
,
6
,
4100
),
(
4100
,
3
,
34
,
6
),
(
3
,
4100
,
34
,
6
),
(
3
,
34
,
4100
,
6
),
(
3
,
34
,
6
,
4100
),
(
4100
,
3
,
34
,
6
),
(
3
,
4100
,
34
,
6
),
(
3
,
34
,
4100
,
6
),
(
3
,
34
,
6
,
4100
),
(
4100
,
3
,
4
,
36
),
(
3
,
4100
,
4
,
36
),
(
3
,
4
,
4100
,
36
),
(
3
,
4
,
36
,
4100
),
(
4100
,
3
,
4
,
36
),
(
3
,
4100
,
4
,
36
),
(
3
,
4
,
4100
,
36
),
(
3
,
4
,
36
,
4100
),
(
0
,
0
,
0
,
0
,
0
),
(
0
,
0
,
0
,
0
,
0
),
(
3
,
34
,
35
,
36
,
37
),
(
3
,
34
,
35
,
36
,
37
),
(
33
,
34
,
3
,
36
,
37
),
(
33
,
34
,
3
,
36
,
37
),
(
33
,
34
,
35
,
36
,
3
),
(
33
,
34
,
35
,
36
,
3
),
(
0
,
0
,
0
,
0
,
0
,
0
),
(
0
,
0
,
0
,
0
,
0
,
0
),
(
3
,
34
,
35
,
36
,
37
,
2
),
(
3
,
34
,
35
,
36
,
37
,
2
),
(
33
,
34
,
3
,
36
,
37
,
2
),
(
33
,
34
,
3
,
36
,
37
,
2
),
(
33
,
34
,
35
,
36
,
3
,
2
),
(
33
,
34
,
35
,
36
,
3
,
2
),
(
3
,
4
,
5
,
6
,
7
,
1025
),
(
3
,
4
,
5
,
6
,
7
,
1025
),
(
3
,
4
,
5
,
6
,
1025
,
7
),
(
3
,
4
,
5
,
6
,
1025
,
7
),
(
3
,
4
,
5
,
1025
,
6
,
7
),
(
3
,
4
,
5
,
1025
,
6
,
7
),
(
3
,
4
,
1025
,
5
,
6
,
7
),
(
3
,
4
,
1025
,
5
,
6
,
7
),
(
3
,
1025
,
4
,
5
,
6
,
7
),
(
3
,
1025
,
4
,
5
,
6
,
7
),
(
1025
,
3
,
4
,
5
,
6
,
7
),
(
1025
,
3
,
4
,
5
,
6
,
7
),
):
):
if
isinstance
(
shapes
,
tuple
):
if
isinstance
(
shapes
,
tuple
):
shape
=
shapes
shape
=
shapes
shape2
=
shapes
shape2
=
shapes
...
@@ -98,18 +98,12 @@ def test_add_iadd_idiv():
...
@@ -98,18 +98,12 @@ def test_add_iadd_idiv():
# add don't support stride
# add don't support stride
if
shape
==
shape2
:
if
shape
==
shape2
:
t0
=
time
.
time
()
bsum
=
b0
+
b1
bsum
=
b0
+
b1
bsum
=
b0
+
b1
bsum
=
b0
+
b1
t1
=
time
.
time
()
gpu_dt
=
t1
-
t0
t0
=
time
.
time
()
asum
=
a0
+
a1
asum
=
a0
+
a1
asum
=
a0
+
a1
asum
=
a0
+
a1
t1
=
time
.
time
()
cpu_dt
=
t1
-
t0
# print shape, 'adding ', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
# print shape, 'adding ', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
assert
numpy
.
allclose
(
asum
,
numpy
.
asarray
(
bsum
))
assert
numpy
.
allclose
(
asum
,
numpy
.
asarray
(
bsum
))
# test not contiguous version.
# test not contiguous version.
# should raise not implemented.
# should raise not implemented.
...
@@ -133,23 +127,9 @@ def test_add_iadd_idiv():
...
@@ -133,23 +127,9 @@ def test_add_iadd_idiv():
raise
Exception
(
"You need to modify this case!"
)
raise
Exception
(
"You need to modify this case!"
)
# TODO: b0[...,::-1] don't work
# TODO: b0[...,::-1] don't work
if
shape
==
shape2
:
t
=
False
try
:
_c
=
_b
+
b1
except
TypeError
:
t
=
True
assert
t
# test inplace version
# test inplace version
t0
=
time
.
time
()
b0
+=
b1
b0
+=
b1
t1
=
time
.
time
()
gpu_dt
=
t1
-
t0
t0
=
time
.
time
()
a0
+=
a1
a0
+=
a1
t1
=
time
.
time
()
cpu_dt
=
t1
-
t0
# print shape, 'adding inplace', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
# print shape, 'adding inplace', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
a0_orig
+
a1
)
assert
numpy
.
allclose
(
a0
,
a0_orig
+
a1
)
...
@@ -157,14 +137,14 @@ def test_add_iadd_idiv():
...
@@ -157,14 +137,14 @@ def test_add_iadd_idiv():
b0
/=
b1
b0
/=
b1
a0
/=
a1
a0
/=
a1
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
(
a0_orig
+
a1
)
/
a1
)
assert
numpy
.
allclose
(
a0
,
(
a0_orig
+
a1
)
/
a1
)
# test inplace version
# test inplace version
# for not contiguous input
# for not contiguous input
b0
+=
_b
b0
+=
_b
a0
+=
a1
[
...
,
::
-
1
]
a0
+=
a1
[
...
,
::
-
1
]
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
(
a0_orig
+
a1
)
/
a1
+
a1
[
...
,
::
-
1
])
assert
numpy
.
allclose
(
a0
,
(
a0_orig
+
a1
)
/
a1
+
a1
[
...
,
::
-
1
])
b0
/=
_b
b0
/=
_b
a0
/=
a1
[
...
,
::
-
1
]
a0
/=
a1
[
...
,
::
-
1
]
...
@@ -174,48 +154,42 @@ def test_add_iadd_idiv():
...
@@ -174,48 +154,42 @@ def test_add_iadd_idiv():
def
test_exp
():
def
test_exp
():
#print >>sys.stdout, 'starting test_exp'
#
print >>sys.stdout, 'starting test_exp'
for
shape
in
((),
(
3
,),
(
2
,
3
),
for
shape
in
((),
(
3
,),
(
2
,
3
),
(
1
,
10000000
),
(
10
,
1000000
),
(
1
,
10000000
),
(
10
,
1000000
),
(
100
,
100000
),
(
1000
,
10000
),
(
10000
,
1000
)):
(
100
,
100000
),
(
1000
,
10000
),
(
10000
,
1000
)):
a0
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
a0
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
a1
=
a0
.
copy
()
a1
=
a0
.
copy
()
b0
=
cuda_ndarray
.
CudaNdarray
(
a0
)
b0
=
cuda_ndarray
.
CudaNdarray
(
a0
)
b1
=
cuda_ndarray
.
CudaNdarray
(
a1
)
cuda_ndarray
.
CudaNdarray
(
a1
)
t0
=
time
.
time
()
bsum
=
b0
.
exp
()
bsum
=
b0
.
exp
()
t1
=
time
.
time
()
gpu_dt
=
t1
-
t0
t0
=
time
.
time
()
asum
=
numpy
.
exp
(
a1
)
asum
=
numpy
.
exp
(
a1
)
t1
=
time
.
time
()
cpu_dt
=
t1
-
t0
# print shape, 'adding ', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
# print shape, 'adding ', a0.size, 'cpu', cpu_dt, 'advantage', advantage(cpu_dt, gpu_dt)
#c = numpy.asarray(b0+b1)
#
c = numpy.asarray(b0+b1)
if
asum
.
shape
:
if
asum
.
shape
:
assert
numpy
.
allclose
(
asum
,
numpy
.
asarray
(
bsum
))
assert
numpy
.
allclose
(
asum
,
numpy
.
asarray
(
bsum
))
def
test_copy
():
def
test_copy
():
#print >>sys.stdout, 'starting test_copy'
#
print >>sys.stdout, 'starting test_copy'
shape
=
(
500
,
499
)
shape
=
(
500
,
499
)
a
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
a
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
#print >>sys.stdout, '.. creating device object'
#
print >>sys.stdout, '.. creating device object'
b
=
cuda_ndarray
.
CudaNdarray
(
a
)
b
=
cuda_ndarray
.
CudaNdarray
(
a
)
#print >>sys.stdout, '.. copy'
#
print >>sys.stdout, '.. copy'
c
=
copy
.
copy
(
b
)
c
=
copy
.
copy
(
b
)
#print >>sys.stdout, '.. deepcopy'
#
print >>sys.stdout, '.. deepcopy'
d
=
copy
.
deepcopy
(
b
)
d
=
copy
.
deepcopy
(
b
)
#print >>sys.stdout, '.. comparisons'
#
print >>sys.stdout, '.. comparisons'
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
b
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
b
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
c
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
c
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
d
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
d
))
b
+=
b
b
+=
b
assert
numpy
.
allclose
(
a
+
a
,
numpy
.
asarray
(
b
))
assert
numpy
.
allclose
(
a
+
a
,
numpy
.
asarray
(
b
))
assert
numpy
.
allclose
(
a
+
a
,
numpy
.
asarray
(
c
))
assert
numpy
.
allclose
(
a
+
a
,
numpy
.
asarray
(
c
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
d
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
d
))
...
@@ -237,8 +211,8 @@ def test_nvcc_bug():
...
@@ -237,8 +211,8 @@ def test_nvcc_bug():
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
c
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
c
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
d
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
d
))
b
+=
b
b
+=
b
assert
numpy
.
allclose
(
a
+
a
,
numpy
.
asarray
(
b
))
assert
numpy
.
allclose
(
a
+
a
,
numpy
.
asarray
(
b
))
assert
numpy
.
allclose
(
a
+
a
,
numpy
.
asarray
(
c
))
assert
numpy
.
allclose
(
a
+
a
,
numpy
.
asarray
(
c
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
d
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
d
))
...
@@ -318,7 +292,7 @@ class test_DimShuffle(unittest.TestCase):
...
@@ -318,7 +292,7 @@ class test_DimShuffle(unittest.TestCase):
def
test_dot
():
def
test_dot
():
#print >>sys.stdout, 'starting test_dot'
#
print >>sys.stdout, 'starting test_dot'
utt
.
seed_rng
()
utt
.
seed_rng
()
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
@@ -336,7 +310,7 @@ def test_dot():
...
@@ -336,7 +310,7 @@ def test_dot():
numpy_version
=
numpy
.
dot
(
a0
,
a1
.
T
)
numpy_version
=
numpy
.
dot
(
a0
,
a1
.
T
)
transposed
=
cuda_ndarray
.
dimshuffle
(
b1
,
(
1
,
0
))
transposed
=
cuda_ndarray
.
dimshuffle
(
b1
,
(
1
,
0
))
cuda_version
=
cuda_ndarray
.
dot
(
b0
,
transposed
)
cuda_version
=
cuda_ndarray
.
dot
(
b0
,
transposed
)
assert
_allclose
(
numpy_version
,
cuda_version
)
assert
_allclose
(
numpy_version
,
cuda_version
)
...
@@ -347,14 +321,16 @@ def test_dot():
...
@@ -347,14 +321,16 @@ def test_dot():
b0
=
cuda_ndarray
.
CudaNdarray
(
a0
)
b0
=
cuda_ndarray
.
CudaNdarray
(
a0
)
assert
_allclose
(
numpy
.
dot
(
a0
.
T
,
a1
),
assert
_allclose
(
numpy
.
dot
(
a0
.
T
,
a1
),
cuda_ndarray
.
dot
(
cuda_ndarray
.
dimshuffle
(
b0
,
(
1
,
0
)),
b1
))
cuda_ndarray
.
dot
(
cuda_ndarray
.
dimshuffle
(
b0
,
(
1
,
0
)),
b1
))
a1
=
theano
.
_asarray
(
rng
.
randn
(
6
,
7
),
dtype
=
'float32'
)
a1
=
theano
.
_asarray
(
rng
.
randn
(
6
,
7
),
dtype
=
'float32'
)
b1
=
cuda_ndarray
.
CudaNdarray
(
a1
)
b1
=
cuda_ndarray
.
CudaNdarray
(
a1
)
assert
_allclose
(
numpy
.
dot
(
a0
.
T
,
a1
.
T
),
assert
_allclose
(
cuda_ndarray
.
dot
(
cuda_ndarray
.
dimshuffle
(
b0
,
(
1
,
0
)),
numpy
.
dot
(
a0
.
T
,
a1
.
T
),
cuda_ndarray
.
dimshuffle
(
b1
,
(
1
,
0
))))
cuda_ndarray
.
dot
(
cuda_ndarray
.
dimshuffle
(
b0
,
(
1
,
0
)),
cuda_ndarray
.
dimshuffle
(
b1
,
(
1
,
0
))))
def
test_sum
():
def
test_sum
():
...
@@ -367,8 +343,8 @@ def test_sum():
...
@@ -367,8 +343,8 @@ def test_sum():
assert
numpy
.
allclose
(
a0
.
sum
(),
assert
numpy
.
allclose
(
a0
.
sum
(),
numpy
.
asarray
(
b0
.
reduce_sum
([
1
,
1
])))
numpy
.
asarray
(
b0
.
reduce_sum
([
1
,
1
])))
a0
sum
=
a0
.
sum
(
axis
=
0
)
a0
.
sum
(
axis
=
0
)
b0
sum
=
b0
.
reduce_sum
([
1
,
0
])
b0
.
reduce_sum
([
1
,
0
])
# print 'asum\n',a0sum
# print 'asum\n',a0sum
# print 'bsum\n',numpy.asarray(b0sum)
# print 'bsum\n',numpy.asarray(b0sum)
...
@@ -399,31 +375,30 @@ def test_sum():
...
@@ -399,31 +375,30 @@ def test_sum():
def
test_reshape
():
def
test_reshape
():
shapelist
=
[
shapelist
=
[((
1
,
2
,
3
),
(
1
,
2
,
3
)),
((
1
,
2
,
3
),
(
1
,
2
,
3
)),
((
1
,),
(
1
,)),
((
1
,),
(
1
,)),
((
1
,
2
,
3
),
(
3
,
2
,
1
)),
((
1
,
2
,
3
),
(
3
,
2
,
1
)),
((
1
,
2
,
3
),
(
6
,)),
((
1
,
2
,
3
),
(
6
,)),
((
1
,
2
,
3
,
2
),
(
6
,
2
)),
((
1
,
2
,
3
,
2
),
(
6
,
2
)),
((
2
,
3
,
2
),
(
6
,
2
)),
((
2
,
3
,
2
),
(
6
,
2
)),
((
2
,
3
,
2
),
(
12
,))
((
2
,
3
,
2
),
(
12
,))
]
]
bad_shapelist
=
[
bad_shapelist
=
[
((
1
,
2
,
3
),
(
1
,
2
,
4
)),
((
1
,
2
,
3
),
(
1
,
2
,
4
)),
((
1
,),
(
2
,)),
((
1
,),
(
2
,)),
((
1
,
2
,
3
),
(
2
,
2
,
1
)),
((
1
,
2
,
3
),
(
2
,
2
,
1
)),
((
1
,
2
,
3
),
(
5
,)),
((
1
,
2
,
3
),
(
5
,)),
((
1
,
2
,
3
,
2
),
(
6
,
3
)),
((
1
,
2
,
3
,
2
),
(
6
,
3
)),
((
2
,
3
,
2
),
(
5
,
2
)),
((
2
,
3
,
2
),
(
5
,
2
)),
((
2
,
3
,
2
),
(
11
,))
((
2
,
3
,
2
),
(
11
,))
]
]
utt
.
seed_rng
()
utt
.
seed_rng
()
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
def
subtest
(
shape_1
,
shape_2
,
rng
):
def
subtest
(
shape_1
,
shape_2
,
rng
):
#print >> sys.stdout, "INFO: shapes", shape_1, shape_2
#
print >> sys.stdout, "INFO: shapes", shape_1, shape_2
a
=
theano
.
_asarray
(
rng
.
randn
(
*
shape_1
),
dtype
=
'float32'
)
a
=
theano
.
_asarray
(
rng
.
randn
(
*
shape_1
),
dtype
=
'float32'
)
b
=
cuda_ndarray
.
CudaNdarray
(
a
)
b
=
cuda_ndarray
.
CudaNdarray
(
a
)
...
@@ -459,8 +434,8 @@ def test_reshape():
...
@@ -459,8 +434,8 @@ def test_reshape():
b
=
cuda_ndarray
.
CudaNdarray
(
a
)
b
=
cuda_ndarray
.
CudaNdarray
(
a
)
try
:
try
:
b
b
=
b
.
reshape
(
shape_2
)
b
.
reshape
(
shape_2
)
except
Exception
as
ValueError
:
except
Exception
:
return
return
assert
False
assert
False
...
@@ -477,13 +452,13 @@ def test_reshape():
...
@@ -477,13 +452,13 @@ def test_reshape():
def
test_getshape
():
def
test_getshape
():
shapelist
=
[
shapelist
=
[
((
1
,
2
,
3
),
(
1
,
2
,
3
)),
((
1
,
2
,
3
),
(
1
,
2
,
3
)),
((
1
,),
(
1
,)),
((
1
,),
(
1
,)),
((
1
,
2
,
3
),
(
3
,
2
,
1
)),
((
1
,
2
,
3
),
(
3
,
2
,
1
)),
((
1
,
2
,
3
),
(
6
,)),
((
1
,
2
,
3
),
(
6
,)),
((
1
,
2
,
3
,
2
),
(
6
,
2
)),
((
1
,
2
,
3
,
2
),
(
6
,
2
)),
((
2
,
3
,
2
),
(
6
,
2
))
((
2
,
3
,
2
),
(
6
,
2
))
]
]
def
subtest
(
shape
):
def
subtest
(
shape
):
a
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape_1
),
dtype
=
'float32'
)
a
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape_1
),
dtype
=
'float32'
)
...
@@ -509,7 +484,7 @@ def test_stride_manipulation():
...
@@ -509,7 +484,7 @@ def test_stride_manipulation():
b_strides
=
b
.
_strides
b_strides
=
b
.
_strides
for
i
in
xrange
(
len
(
b
.
shape
)):
for
i
in
xrange
(
len
(
b
.
shape
)):
offset
+=
(
b
.
shape
[
i
]
-
1
)
*
b_strides
[
i
]
offset
+=
(
b
.
shape
[
i
]
-
1
)
*
b_strides
[
i
]
v
.
_set_stride
(
i
,
-
b_strides
[
i
])
v
.
_set_stride
(
i
,
-
b_strides
[
i
])
v
.
_dev_data
+=
offset
*
sizeof_float
v
.
_dev_data
+=
offset
*
sizeof_float
...
@@ -699,8 +674,8 @@ def test_setitem_matrixvector1():
...
@@ -699,8 +674,8 @@ def test_setitem_matrixvector1():
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
_a
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
_a
))
# test direct transfert from numpy
# test direct transfert from numpy
_a
[:,
1
]
=
b
*
100
_a
[:,
1
]
=
b
*
100
a
[:,
1
]
=
b
*
100
a
[:,
1
]
=
b
*
100
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
_a
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
_a
))
row
=
theano
.
_asarray
([
777
,
888
,
999
],
dtype
=
'float32'
)
row
=
theano
.
_asarray
([
777
,
888
,
999
],
dtype
=
'float32'
)
...
@@ -725,8 +700,8 @@ def test_setitem_matrix_tensor3():
...
@@ -725,8 +700,8 @@ def test_setitem_matrix_tensor3():
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
_a
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
_a
))
# test direct transfert from numpy
# test direct transfert from numpy
_a
[:,
1
,
1
]
=
b
*
100
_a
[:,
1
,
1
]
=
b
*
100
a
[:,
1
,
1
]
=
b
*
100
a
[:,
1
,
1
]
=
b
*
100
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
_a
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
_a
))
row
=
theano
.
_asarray
([
777
,
888
,
999
],
dtype
=
'float32'
)
row
=
theano
.
_asarray
([
777
,
888
,
999
],
dtype
=
'float32'
)
...
@@ -752,7 +727,7 @@ def test_setitem_matrix_bad_shape():
...
@@ -752,7 +727,7 @@ def test_setitem_matrix_bad_shape():
# attempt to assign the ndarray b with setitem
# attempt to assign the ndarray b with setitem
_a
[:,
1
,
1
]
=
_b
_a
[:,
1
,
1
]
=
_b
assert
False
assert
False
except
ValueError
as
e
:
except
ValueError
:
# print e
# print e
assert
True
assert
True
...
@@ -761,7 +736,7 @@ def test_setitem_matrix_bad_shape():
...
@@ -761,7 +736,7 @@ def test_setitem_matrix_bad_shape():
# attempt to assign the ndarray b with setitem
# attempt to assign the ndarray b with setitem
_a
[
1
,
1
,
:]
=
b
_a
[
1
,
1
,
:]
=
b
assert
False
assert
False
except
ValueError
as
e
:
except
ValueError
:
# print e
# print e
assert
True
assert
True
...
@@ -779,7 +754,7 @@ def test_setitem_matrix_bad_ndim():
...
@@ -779,7 +754,7 @@ def test_setitem_matrix_bad_ndim():
# attempt to assign the ndarray b with setitem
# attempt to assign the ndarray b with setitem
_a
[:,
:,
1
]
=
_b
_a
[:,
:,
1
]
=
_b
assert
False
assert
False
except
ValueError
as
e
:
except
ValueError
:
# print e
# print e
assert
True
assert
True
...
@@ -788,7 +763,7 @@ def test_setitem_matrix_bad_ndim():
...
@@ -788,7 +763,7 @@ def test_setitem_matrix_bad_ndim():
# attempt to assign the ndarray b with setitem
# attempt to assign the ndarray b with setitem
_a
[
1
,
:,
:]
=
b
_a
[
1
,
:,
:]
=
b
assert
False
assert
False
except
ValueError
as
e
:
except
ValueError
:
# print e
# print e
assert
True
assert
True
...
@@ -806,7 +781,7 @@ def test_setitem_matrix_bad_type():
...
@@ -806,7 +781,7 @@ def test_setitem_matrix_bad_type():
# attempt to assign the ndarray b with setitem
# attempt to assign the ndarray b with setitem
_a
[
1
,
:,
:]
=
b
_a
[
1
,
:,
:]
=
b
assert
False
assert
False
except
TypeError
as
e
:
except
TypeError
:
# print e
# print e
assert
True
assert
True
...
@@ -832,8 +807,8 @@ def test_setitem_assign_to_slice():
...
@@ -832,8 +807,8 @@ def test_setitem_assign_to_slice():
# test direct transfert from numpy
# test direct transfert from numpy
_d
=
_a
[
1
,
:,
:]
_d
=
_a
[
1
,
:,
:]
_d
[
1
,
:]
=
b
*
10
_d
[
1
,
:]
=
b
*
10
a
[
1
,
:,
:][
1
,
:]
=
b
*
10
a
[
1
,
:,
:][
1
,
:]
=
b
*
10
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
_a
))
assert
numpy
.
allclose
(
a
,
numpy
.
asarray
(
_a
))
...
@@ -923,7 +898,7 @@ def test_setitem_rightvalue_ndarray_fails():
...
@@ -923,7 +898,7 @@ def test_setitem_rightvalue_ndarray_fails():
b
=
theano
.
_asarray
([
7
,
8
,
9
,
10
],
dtype
=
'float32'
)
b
=
theano
.
_asarray
([
7
,
8
,
9
,
10
],
dtype
=
'float32'
)
_b
=
cuda_ndarray
.
CudaNdarray
(
b
)
_b
=
cuda_ndarray
.
CudaNdarray
(
b
)
b5
=
theano
.
_asarray
([
7
,
8
,
9
,
10
,
11
],
dtype
=
'float32'
)
b5
=
theano
.
_asarray
([
7
,
8
,
9
,
10
,
11
],
dtype
=
'float32'
)
_b5
=
cuda_ndarray
.
CudaNdarray
(
b
)
cuda_ndarray
.
CudaNdarray
(
b
)
# attempt to assign the ndarray b with setitem
# attempt to assign the ndarray b with setitem
_a
[:,
:,
1
]
=
_b
_a
[:,
:,
1
]
=
_b
...
@@ -941,9 +916,9 @@ def test_setitem_rightvalue_ndarray_fails():
...
@@ -941,9 +916,9 @@ def test_setitem_rightvalue_ndarray_fails():
# without same number of dim
# without same number of dim
try
:
try
:
_a
[
0
,
:,
:]
=
mat
_a
[
0
,
:,
:]
=
mat
#a[0, :, :] = mat
#
a[0, :, :] = mat
#assert numpy.allclose(numpy.asarray(_a), a)
#
assert numpy.allclose(numpy.asarray(_a), a)
except
ValueError
as
e
:
except
ValueError
:
pass
pass
# test direct transfert from numpy with broadcast
# test direct transfert from numpy with broadcast
...
@@ -964,7 +939,7 @@ def test_zeros_basic():
...
@@ -964,7 +939,7 @@ def test_zeros_basic():
_n
=
numpy
.
zeros
(
shp
,
dtype
=
"float32"
)
_n
=
numpy
.
zeros
(
shp
,
dtype
=
"float32"
)
assert
numpy
.
allclose
(
numpy
.
asarray
(
_a
),
_n
)
assert
numpy
.
allclose
(
numpy
.
asarray
(
_a
),
_n
)
assert
_a
.
shape
==
_n
.
shape
assert
_a
.
shape
==
_n
.
shape
assert
all
(
_a
.
_strides
==
numpy
.
asarray
(
_n
.
strides
)
/
4
)
assert
all
(
_a
.
_strides
==
numpy
.
asarray
(
_n
.
strides
)
/
4
)
# TODO:The following don't have the same stride!
# TODO:The following don't have the same stride!
# This should be fixed with the new GpuNdArray.
# This should be fixed with the new GpuNdArray.
...
@@ -1039,10 +1014,7 @@ def test_is_c_contiguous():
...
@@ -1039,10 +1014,7 @@ def test_is_c_contiguous():
assert
not
a
[::
2
]
.
is_c_contiguous
()
assert
not
a
[::
2
]
.
is_c_contiguous
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_zeros_basic_3d_tensor
()
test_zeros_basic_vector
()
test_setitem_matrixvector1
()
test_setitem_matrixvector1
()
test_setitem_matrix_tensor3
()
test_setitem_matrix_tensor3
()
test_setitem_broadcast_must_fail
()
test_setitem_assign_to_slice
()
test_setitem_assign_to_slice
()
test_setitem_rightvalue_ndarray_fails
()
test_setitem_rightvalue_ndarray_fails
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论