Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
21581731
提交
21581731
authored
10月 23, 2013
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revise makeTester to make it easier to test Gpu ops.
上级
890b9af0
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
88 行增加
和
119 行删除
+88
-119
basic_ops.py
theano/sandbox/gpuarray/basic_ops.py
+2
-2
test_basic_ops.py
theano/sandbox/gpuarray/tests/test_basic_ops.py
+86
-117
没有找到文件。
theano/sandbox/gpuarray/basic_ops.py
浏览文件 @
21581731
...
@@ -504,7 +504,7 @@ class GpuAlloc(HideC, Alloc):
...
@@ -504,7 +504,7 @@ class GpuAlloc(HideC, Alloc):
}
}
if (GpuArray_setarray(&
%(zz)
s->ga, &
%(vv)
s->ga) != GA_NO_ERROR) {
if (GpuArray_setarray(&
%(zz)
s->ga, &
%(vv)
s->ga) != GA_NO_ERROR) {
PyErr_SetString(PyExc_
Runtim
eError, "setarray failed");
PyErr_SetString(PyExc_
Valu
eError, "setarray failed");
%(fail)
s
%(fail)
s
}
}
"""
%
dict
(
name
=
name
,
ndim
=
ndim
,
zz
=
zz
,
vv
=
vv
,
fail
=
sub
[
'fail'
])
"""
%
dict
(
name
=
name
,
ndim
=
ndim
,
zz
=
zz
,
vv
=
vv
,
fail
=
sub
[
'fail'
])
...
@@ -515,6 +515,6 @@ class GpuAlloc(HideC, Alloc):
...
@@ -515,6 +515,6 @@ class GpuAlloc(HideC, Alloc):
return
code
return
code
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
0
,)
return
(
1
,)
gpu_alloc
=
GpuAlloc
()
gpu_alloc
=
GpuAlloc
()
theano/sandbox/gpuarray/tests/test_basic_ops.py
浏览文件 @
21581731
...
@@ -5,7 +5,9 @@ from copy import copy, deepcopy
...
@@ -5,7 +5,9 @@ from copy import copy, deepcopy
import
numpy
import
numpy
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
from
theano.tensor.tests.test_basic
import
safe_make_node
from
theano.tensor
import
TensorType
from
theano.tensor.basic
import
alloc
from
theano.tensor.tests.test_basic
import
rand
,
safe_make_node
from
theano.tests.unittest_tools
import
SkipTest
from
theano.tests.unittest_tools
import
SkipTest
from
numpy.testing.noseclasses
import
KnownFailureTest
from
numpy.testing.noseclasses
import
KnownFailureTest
...
@@ -94,134 +96,102 @@ def rand_gpuarray(*shape, **kwargs):
...
@@ -94,134 +96,102 @@ def rand_gpuarray(*shape, **kwargs):
return
gpuarray
.
array
(
r
,
dtype
=
dtype
,
cls
=
cls
)
return
gpuarray
.
array
(
r
,
dtype
=
dtype
,
cls
=
cls
)
def
makeTester
(
name
,
op
,
expected
,
good
=
None
,
bad_build
=
None
,
checks
=
None
,
def
makeTester
(
name
,
op
,
gpu_op
,
cases
,
checks
=
None
,
mode_gpu
=
mode_with_gpu
,
bad_runtime
=
None
,
mode
=
None
,
skip
=
False
,
eps
=
1e-10
):
mode_nogpu
=
mode_without_gpu
,
skip
=
False
,
eps
=
1e-10
):
if
good
is
None
:
good
=
{}
if
bad_build
is
None
:
bad_build
=
{}
if
bad_runtime
is
None
:
bad_runtime
=
{}
if
checks
is
None
:
if
checks
is
None
:
checks
=
{}
checks
=
{}
_op
=
op
_op
=
op
_expected
=
expected
_gpu_op
=
gpu_op
_good
=
good
_cases
=
cases
_bad_build
=
bad_build
_bad_runtime
=
bad_runtime
_skip
=
skip
_skip
=
skip
_checks
=
checks
_checks
=
checks
class
Checker
(
unittest
.
TestCase
):
class
Checker
(
unittest
.
TestCase
):
op
=
staticmethod
(
_op
)
op
=
staticmethod
(
_op
)
expected
=
staticmethod
(
_expected
)
gpu_op
=
staticmethod
(
_gpu_op
)
good
=
_good
cases
=
_cases
bad_build
=
_bad_build
bad_runtime
=
_bad_runtime
skip
=
_skip
skip
=
_skip
checks
=
_checks
checks
=
_checks
def
setUp
(
self
):
def
setUp
(
self
):
eval
(
self
.
__class__
.
__module__
+
'.'
+
self
.
__class__
.
__name__
)
eval
(
self
.
__class__
.
__module__
+
'.'
+
self
.
__class__
.
__name__
)
def
test_
good
(
self
):
def
test_
all
(
self
):
if
skip
:
if
skip
:
raise
SkipTest
(
skip
)
raise
SkipTest
(
skip
)
for
testname
,
inputs
in
good
.
items
():
for
testname
,
inputs
in
cases
.
items
():
inputs
=
[
copy
(
input
)
for
input
in
inputs
]
self
.
run_case
(
testname
,
inputrs
=
[
fake_shared
(
input
)
for
input
in
inputs
]
[
theano
.
shared
(
input
)
for
input
in
inputs
])
try
:
def
run_case
(
self
,
testname
,
inputs
):
node
=
safe_make_node
(
self
.
op
,
*
inputrs
)
try
:
except
Exception
,
exc
:
node
=
safe_make_node
(
self
.
op
,
*
inputs
)
err_msg
=
(
"Test
%
s::
%
s: Error occured while making "
except
Exception
,
exc
:
"a node with inputs
%
s"
)
%
(
self
.
op
,
testname
,
err_msg
=
(
"Test
%
s::
%
s: Error occured while making "
inputs
)
"a node with inputs
%
s"
)
%
(
self
.
gpu_op
,
testname
,
exc
.
args
+=
(
err_msg
,)
inputs
)
raise
exc
.
args
+=
(
err_msg
,)
raise
try
:
try
:
f
=
inplace_func
([],
node
.
outputs
,
mode
=
mode
,
f_ref
=
inplace_func
([],
node
.
outputs
,
mode
=
mode_nogpu
)
name
=
'test_good'
)
f_tst
=
inplace_func
([],
node
.
outputs
,
mode
=
mode_gpu
)
except
Exception
,
exc
:
except
Exception
,
exc
:
err_msg
=
(
"Test
%
s::
%
s: Error occured while trying to "
err_msg
=
(
"Test
%
s::
%
s: Error occured while trying to "
"make a Function"
)
%
(
self
.
op
,
testname
)
"make a Function"
)
%
(
self
.
gpu_
op
,
testname
)
exc
.
args
+=
(
err_msg
,)
exc
.
args
+=
(
err_msg
,)
raise
raise
if
isinstance
(
self
.
expected
,
dict
)
and
\
assert
any
(
node
.
op
is
self
.
gpu_op
testname
in
self
.
expected
:
for
node
in
f_tst
.
maker
.
fgraph
.
toposort
()),
testname
expecteds
=
self
.
expected
[
testname
]
else
:
expecteds
=
self
.
expected
(
*
inputs
)
if
not
isinstance
(
expecteds
,
(
list
,
tuple
)):
expecteds
=
(
expecteds
,)
try
:
variables
=
f
()
except
Exception
,
exc
:
err_msg
=
(
"Test
%
s::
%
s: Error occured while calling "
"the Function on the inputs
%
s"
)
%
(
self
.
op
,
testname
,
inputs
)
exc
.
args
+=
(
err_msg
,)
raise
for
i
,
(
variable
,
expected
)
in
\
ref_e
=
None
enumerate
(
izip
(
variables
,
expecteds
)):
try
:
if
variable
.
dtype
!=
expected
.
dtype
or
\
expecteds
=
f_ref
()
variable
.
shape
!=
expected
.
shape
or
\
except
Exception
,
exc
:
not
GpuArrayType
.
values_eq_approx
(
variable
,
ref_e
=
exc
expected
):
self
.
fail
((
"Test
%
s::
%
s: Output
%
s gave the wrong "
"value. With inputs
%
s, expected
%
s "
"(dtype
%
s), got
%
s (dtype
%
s)."
)
%
(
self
.
op
,
testname
,
i
,
inputs
,
expected
,
expected
.
dtype
,
variable
,
variable
.
dtype
))
for
description
,
check
in
self
.
checks
.
items
():
if
not
check
(
inputs
,
variables
):
self
.
fail
((
"Test
%
s::
%
s: Failed check:
%
s "
"(inputs were
%
s, ouputs were
%
s)"
)
%
(
self
.
op
,
testname
,
description
,
inputs
,
variables
))
def
test_bad_build
(
self
):
if
skip
:
raise
SkipTest
(
skip
)
for
testname
,
inputs
in
self
.
bad_build
.
items
():
inputs
=
[
copy
(
input
)
for
input
in
inputs
]
inputrs
=
[
fake_shared
(
input
)
for
input
in
inputs
]
self
.
assertRaises
(
Exception
,
safe_make_node
,
self
.
op
,
*
inputrs
)
def
test_bad_runtime
(
self
):
if
skip
:
raise
SkipTest
(
skip
)
for
testname
,
inputs
in
self
.
bad_runtime
.
items
():
inputrs
=
[
fake_shared
(
input
)
for
input
in
inputs
]
try
:
node
=
safe_make_node
(
self
.
op
,
*
inputrs
)
except
Exception
,
exc
:
err_msg
=
(
"Test
%
s::
%
s: Error occured while trying to "
"make a node with inputs
%
s"
)
%
(
self
.
op
,
testname
,
inputs
)
exc
.
args
+=
(
err_msg
,)
raise
try
:
try
:
f
=
inplace_func
([],
node
.
outputs
,
mode
=
mode
,
variables
=
f_tst
()
name
=
"test_bad_runtime"
)
except
Exception
,
exc
:
except
Exception
,
exc
:
if
ref_e
is
None
:
err_msg
=
(
"Test
%
s::
%
s:
Error occured while trying to
"
err_msg
=
(
"Test
%
s::
%
s:
exception when calling the
"
"
make a Function"
)
%
(
self
.
op
,
testname
)
"
Function"
)
%
(
self
.
gpu_
op
,
testname
)
exc
.
args
+=
(
err_msg
,)
exc
.
args
+=
(
err_msg
,)
raise
raise
else
:
self
.
assertRaises
(
Exception
,
f
,
[])
# if we raised an exception of the same type we're good.
if
isinstance
(
exc
,
type
(
ref_e
)):
return
else
:
err_msg
=
(
"Test
%
s::
%
s: exception raised during test "
"call was not the same as the reference "
"call (got:
%
s, expected
%
s)"
)
%
\
(
self
.
gpu_op
,
testname
,
type
(
exc
),
type
(
ref_e
))
exc
.
args
+=
(
err_msg
,)
raise
for
i
,
(
variable
,
expected
)
in
\
enumerate
(
izip
(
variables
,
expecteds
)):
if
variable
.
dtype
!=
expected
.
dtype
or
\
variable
.
shape
!=
expected
.
shape
or
\
not
TensorType
.
values_eq_approx
(
variable
,
expected
):
self
.
fail
((
"Test
%
s::
%
s: Output
%
s gave the wrong "
"value. With inputs
%
s, expected
%
s "
"(dtype
%
s), got
%
s (dtype
%
s)."
)
%
(
self
.
op
,
testname
,
i
,
inputs
,
expected
,
expected
.
dtype
,
variable
,
variable
.
dtype
))
for
description
,
check
in
self
.
checks
.
items
():
if
not
check
(
inputs
,
variables
):
self
.
fail
((
"Test
%
s::
%
s: Failed check:
%
s "
"(inputs were
%
s, ouputs were
%
s)"
)
%
(
self
.
op
,
testname
,
description
,
inputs
,
variables
))
Checker
.
__name__
=
name
Checker
.
__name__
=
name
return
Checker
return
Checker
...
@@ -301,19 +271,18 @@ def gpu_alloc_expected(x, *shp):
...
@@ -301,19 +271,18 @@ def gpu_alloc_expected(x, *shp):
GpuAllocTester
=
makeTester
(
GpuAllocTester
=
makeTester
(
name
=
"GpuAllocTester"
,
name
=
"GpuAllocTester"
,
op
=
gpu_alloc
,
op
=
alloc
,
expected
=
gpu_alloc_expected
,
gpu_op
=
gpu_alloc
,
good
=
dict
(
cases
=
dict
(
correct01
=
(
rand_gpuarray
(),
numpy
.
int32
(
7
)),
correct01
=
(
rand
(),
numpy
.
int32
(
7
)),
correct01_bcast
=
(
rand_gpuarray
(
1
),
numpy
.
int32
(
7
)),
# just gives a DeepCopyOp with possibly wrong results on the CPU
correct02
=
(
rand_gpuarray
(),
numpy
.
int32
(
4
),
numpy
.
int32
(
7
)),
# correct01_bcast=(rand(1), numpy.int32(7)),
correct12
=
(
rand_gpuarray
(
7
),
numpy
.
int32
(
4
),
numpy
.
int32
(
7
)),
correct02
=
(
rand
(),
numpy
.
int32
(
4
),
numpy
.
int32
(
7
)),
correct13
=
(
rand_gpuarray
(
7
),
numpy
.
int32
(
2
),
numpy
.
int32
(
4
),
correct12
=
(
rand
(
7
),
numpy
.
int32
(
4
),
numpy
.
int32
(
7
)),
correct13
=
(
rand
(
7
),
numpy
.
int32
(
2
),
numpy
.
int32
(
4
),
numpy
.
int32
(
7
)),
correct23
=
(
rand
(
4
,
7
),
numpy
.
int32
(
2
),
numpy
.
int32
(
4
),
numpy
.
int32
(
7
)),
numpy
.
int32
(
7
)),
correct23
=
(
rand_gpuarray
(
4
,
7
),
numpy
.
int32
(
2
),
numpy
.
int32
(
4
),
bad_shape12
=
(
rand
(
7
),
numpy
.
int32
(
7
),
numpy
.
int32
(
5
)),
numpy
.
int32
(
7
))
),
bad_runtime
=
dict
(
bad_shape12
=
(
rand_gpuarray
(
7
),
numpy
.
int32
(
7
),
numpy
.
int32
(
5
)),
)
)
)
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论