Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d95b7cd7
提交
d95b7cd7
authored
8月 19, 2013
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test for the DeepCopyOp code and fix it.
上级
f148f376
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
25 行增加
和
13 行删除
+25
-13
test_basic_ops.py
theano/sandbox/gpuarray/tests/test_basic_ops.py
+22
-5
type.py
theano/sandbox/gpuarray/type.py
+3
-8
没有找到文件。
theano/sandbox/gpuarray/tests/test_basic_ops.py
浏览文件 @
d95b7cd7
...
@@ -6,6 +6,7 @@ from nose.plugins.skip import SkipTest
...
@@ -6,6 +6,7 @@ from nose.plugins.skip import SkipTest
import
numpy
import
numpy
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
from
theano.compile
import
DeepCopyOp
from
theano.tensor.tests.test_basic
import
safe_make_node
from
theano.tensor.tests.test_basic
import
safe_make_node
import
theano.sandbox.gpuarray
import
theano.sandbox.gpuarray
...
@@ -19,6 +20,7 @@ from theano.sandbox.gpuarray.basic_ops import host_from_gpu, gpu_from_host, \
...
@@ -19,6 +20,7 @@ from theano.sandbox.gpuarray.basic_ops import host_from_gpu, gpu_from_host, \
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
utt
.
seed_rng
()
utt
.
seed_rng
()
rng
=
numpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
from
pygpu
import
gpuarray
from
pygpu
import
gpuarray
...
@@ -51,9 +53,12 @@ def fake_shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
...
@@ -51,9 +53,12 @@ def fake_shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
except
TypeError
:
except
TypeError
:
continue
continue
def
rand_gpuarray
(
*
shape
):
def
rand_gpuarray
(
*
shape
,
**
kwargs
):
r
=
numpy
.
random
.
rand
(
*
shape
)
*
2
-
1
r
=
rng
.
rand
(
*
shape
)
*
2
-
1
return
gpuarray
.
array
(
r
,
dtype
=
theano
.
config
.
floatX
)
dtype
=
kwargs
.
pop
(
'dtype'
,
theano
.
config
.
floatX
)
if
len
(
kwargs
)
!=
0
:
raise
TypeError
(
'Unexpected argument
%
s'
,
kwargs
.
keys
()[
0
])
return
gpuarray
.
array
(
r
,
dtype
=
dtype
)
def
makeTester
(
name
,
op
,
expected
,
good
=
None
,
bad_build
=
None
,
checks
=
None
,
def
makeTester
(
name
,
op
,
expected
,
good
=
None
,
bad_build
=
None
,
checks
=
None
,
...
@@ -193,7 +198,7 @@ def test_transfer_cpu_gpu():
...
@@ -193,7 +198,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
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
5
,
4
),
dtype
=
'float32'
)
av
=
numpy
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
'float32'
)
gv
=
gpuarray
.
array
(
av
)
gv
=
gpuarray
.
array
(
av
)
f
=
theano
.
function
([
a
],
gpu_from_host
(
a
))
f
=
theano
.
function
([
a
],
gpu_from_host
(
a
))
...
@@ -212,7 +217,7 @@ def test_transfer_cuda_gpu():
...
@@ -212,7 +217,7 @@ def test_transfer_cuda_gpu():
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
))(
'g'
)
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
))(
'g'
)
c
=
cuda_ndarray
.
CudaNdarrayType
((
False
,
False
))(
'c'
)
c
=
cuda_ndarray
.
CudaNdarrayType
((
False
,
False
))(
'c'
)
av
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
5
,
4
),
dtype
=
'float32'
)
av
=
theano
.
_asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
'float32'
)
gv
=
gpuarray
.
array
(
av
)
gv
=
gpuarray
.
array
(
av
)
cv
=
cuda_ndarray
.
CudaNdarray
(
av
)
cv
=
cuda_ndarray
.
CudaNdarray
(
av
)
...
@@ -248,3 +253,15 @@ GpuAllocTester = makeTester(
...
@@ -248,3 +253,15 @@ GpuAllocTester = makeTester(
bad_shape12
=
(
rand_gpuarray
(
7
),
numpy
.
int32
(
7
),
numpy
.
int32
(
5
)),
bad_shape12
=
(
rand_gpuarray
(
7
),
numpy
.
int32
(
7
),
numpy
.
int32
(
5
)),
)
)
)
)
def
test_deep_copy
():
a
=
rand_gpuarray
(
20
,
dtype
=
'float32'
)
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,))(
'g'
)
f
=
theano
.
function
([
g
],
g
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
,
DeepCopyOp
)
res
=
f
(
a
)
assert
GpuArrayType
.
values_eq
(
res
,
a
)
theano/sandbox/gpuarray/type.py
浏览文件 @
d95b7cd7
...
@@ -267,17 +267,12 @@ theano.compile.register_view_op_c_code(GpuArrayType, """
...
@@ -267,17 +267,12 @@ theano.compile.register_view_op_c_code(GpuArrayType, """
theano
.
compile
.
register_deep_copy_op_c_code
(
GpuArrayType
,
"""
theano
.
compile
.
register_deep_copy_op_c_code
(
GpuArrayType
,
"""
Py_XDECREF(
%(oname)
s);
Py_XDECREF(
%(oname)
s);
%(oname)
s = new_GpuArray(GpuArrayType, GpuArray_default_context);
%(oname)
s = new_GpuArray(
(PyObject *)&
GpuArrayType, GpuArray_default_context);
if (!
%(oname)
s) {
%(fail)
s }
if (!
%(oname)
s) {
%(fail)
s }
int err;
int err;
err = GpuArray_empty(&
%(oname)
s.ga,
%(oname)
s->context->ops);
err = GpuArray_copy(&
%(oname)
s->ga, &
%(iname)
s->ga, GA_ANY_ORDER);
if (err != GA_NO_ERROR) {
PyErr_SetString(PyExc_MemoryError, "Could not allocate new array");
%(fail)
s
}
err = GpuArray_copy(&
%(oname)
s.ga, &
%(iname)
s.ga, GA_ANY_ORDER);
if (err != GA_NO_ERROR) {
if (err != GA_NO_ERROR) {
PyErr_SetString(PyExc_RuntimeError, "Error during copy");
PyErr_SetString(PyExc_RuntimeError, "Error during copy");
%(fail)
s
%(fail)
s
}
}
"""
,
version
=
(
0
,))
"""
,
version
=
(
1
,))
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论