Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
568f9c1a
提交
568f9c1a
authored
6月 23, 2011
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test case for CudaNdarray for add, iadd and idiv.
上级
6ef192a3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
81 行增加
和
33 行删除
+81
-33
test_cuda_ndarray.py
theano/sandbox/cuda/tests/test_cuda_ndarray.py
+81
-33
没有找到文件。
theano/sandbox/cuda/tests/test_cuda_ndarray.py
浏览文件 @
568f9c1a
...
@@ -37,62 +37,110 @@ def test_host_to_device():
...
@@ -37,62 +37,110 @@ def test_host_to_device():
assert
numpy
.
all
(
a
==
c
)
assert
numpy
.
all
(
a
==
c
)
def
test_add_iadd_idiv
():
def
test_add_iadd_idiv
():
for
shape
in
((),
(
0
,),
(
3
,),
(
2
,
3
),
(
1
,
10000000
),(
10
,
1000000
),
(
100
,
100000
),
for
shapes
in
(
(
1000
,
10000
),(
10000
,
1000
),
[(
5
,
5
),(
5
,
1
)],
[(
5
,
5
),(
1
,
5
)],
(),
(
0
,),
(
3
,),
(
2
,
3
),
(
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
),
(
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
),
):
):
a0
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
if
isinstance
(
shapes
,
tuple
):
a1
=
a0
.
copy
()
shape
=
shapes
shape2
=
shapes
a0
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
a0_orig
=
a0
.
copy
()
a1
=
a0
.
copy
()
assert
numpy
.
allclose
(
a0
,
a1
)
else
:
shape
=
shapes
[
0
]
shape2
=
shapes
[
1
]
a0
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
a0_orig
=
a0
.
copy
()
a1
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape2
),
dtype
=
'float32'
)
b0
=
cuda_ndarray
.
CudaNdarray
(
a0
)
b0
=
cuda_ndarray
.
CudaNdarray
(
a0
)
b1
=
cuda_ndarray
.
CudaNdarray
(
a1
)
b1
=
cuda_ndarray
.
CudaNdarray
(
a1
)
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a1
,
numpy
.
asarray
(
b1
))
# add don't support stride
if
shape
==
shape2
:
t0
=
time
.
time
()
bsum
=
b0
+
b1
bsum
=
b0
+
b1
t1
=
time
.
time
()
gpu_dt
=
t1
-
t0
t0
=
time
.
time
()
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
)
assert
numpy
.
allclose
(
asum
,
numpy
.
asarray
(
bsum
))
#test not contiguous version.
#should raise not implemented.
a0
=
a0_orig
.
copy
()
b0
=
cuda_ndarray
.
CudaNdarray
(
a0
)
if
len
(
shape
)
==
0
:
continue
elif
len
(
shape
)
==
1
:
_b
=
b1
[::
-
1
]
elif
len
(
shape
)
==
2
:
_b
=
b1
[::,
::
-
1
]
elif
len
(
shape
)
==
3
:
_b
=
b1
[::,
::,
::
-
1
]
elif
len
(
shape
)
==
4
:
_b
=
b1
[::,
::,
::,
::
-
1
]
elif
len
(
shape
)
==
5
:
_b
=
b1
[::,
::,
::,
::,
::
-
1
]
# TODO: b0[...,::-1] don't work
if
shape
==
shape2
:
t
=
False
try
:
_c
=
_b
+
b1
except
TypeError
:
t
=
True
assert
t
# test inplace version
t0
=
time
.
time
()
t0
=
time
.
time
()
bsum
=
b0
+
b1
b0
+=
b1
bsum
=
b0
+
b1
t1
=
time
.
time
()
t1
=
time
.
time
()
gpu_dt
=
t1
-
t0
gpu_dt
=
t1
-
t0
t0
=
time
.
time
()
t0
=
time
.
time
()
asum
=
a0
+
a1
a0
+=
a1
asum
=
a0
+
a1
t1
=
time
.
time
()
t1
=
time
.
time
()
cpu_dt
=
t1
-
t0
cpu_dt
=
t1
-
t0
print
shape
,
'adding '
,
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
(
asum
,
numpy
.
asarray
(
bsum
))
# test inplace version
b0
+=
b1
a0
+=
a1
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
a1
*
2
)
assert
numpy
.
allclose
(
a0
,
a0_orig
+
a1
)
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
,
numpy
.
ones
(
a0
.
shape
)
*
2
)
assert
numpy
.
allclose
(
a0
,
(
a0_orig
+
a1
)
/
a1
)
if
len
(
shape
)
==
2
:
#test not contiguous version.
#should raise not implemented.
_b
=
b0
[::,
::
-
1
]
b
=
numpy
.
asarray
(
_b
)
ones
=
numpy
.
ones
(
shape
,
dtype
=
'float32'
)
_ones
=
cuda_ndarray
.
CudaNdarray
(
ones
)
t
=
False
try
:
_c
=
_b
+
_ones
except
:
t
=
True
assert
t
# test inplace version
# for not contiguous input
b0
+=
_b
a0
+=
a1
[
...
,
::
-
1
]
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
(
a0_orig
+
a1
)
/
a1
+
a1
[
...
,
::
-
1
])
b0
/=
_b
a0
/=
a1
[
...
,
::
-
1
]
assert
numpy
.
allclose
(
a0
,
numpy
.
asarray
(
b0
))
assert
numpy
.
allclose
(
a0
,
((
a0_orig
+
a1
)
/
a1
+
a1
[
...
,
::
-
1
])
/
a1
[
...
,
::
-
1
])
def
test_exp
():
def
test_exp
():
print
>>
sys
.
stdout
,
'starting test_exp'
print
>>
sys
.
stdout
,
'starting test_exp'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论