Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ca55d2f9
提交
ca55d2f9
authored
9月 06, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #908 from lamblin/fix_test_neib
Fix tests for image2neibs
上级
7478227f
1d4f75a7
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
47 行增加
和
14 行删除
+47
-14
neighbours.py
theano/sandbox/cuda/neighbours.py
+1
-0
nvcc_compiler.py
theano/sandbox/cuda/nvcc_compiler.py
+1
-0
test_neighbours.py
theano/sandbox/cuda/tests/test_neighbours.py
+1
-0
test_neighbours.py
theano/sandbox/test_neighbours.py
+41
-13
unittest_tools.py
theano/tests/unittest_tools.py
+3
-1
没有找到文件。
theano/sandbox/cuda/neighbours.py
浏览文件 @
ca55d2f9
...
...
@@ -404,6 +404,7 @@ def gpu_images2neibs(ten4, neib_shape, neib_step=None, mode='valid'):
@local_optimizer
()
def
use_gpu_images2neibs
(
node
):
if
(
type
(
node
.
op
)
is
Images2Neibs
and
node
.
inputs
[
0
]
.
dtype
==
'float32'
and
node
.
op
.
mode
in
[
'valid'
,
'wrap_centered'
]):
return
[
host_from_gpu
(
gpu_images2neibs
(
gpu_from_host
(
node
.
inputs
[
0
]),
node
.
inputs
[
1
],
node
.
inputs
[
2
],
...
...
theano/sandbox/cuda/nvcc_compiler.py
浏览文件 @
ca55d2f9
...
...
@@ -139,6 +139,7 @@ class NVCC_compiler(object):
default_to_move_computation_to_gpu
=
False
,
move_shared_float32_to_gpu
=
False
,
enable_cuda
=
False
)
n
=
theano
.
sandbox
.
cuda
.
use
.
device_number
p
=
theano
.
sandbox
.
cuda
.
device_properties
(
n
)
flags
.
append
(
'-arch=sm_'
+
str
(
p
[
'major'
])
+
str
(
p
[
'minor'
]))
...
...
theano/sandbox/cuda/tests/test_neighbours.py
浏览文件 @
ca55d2f9
...
...
@@ -20,6 +20,7 @@ else:
class
T_GpuImages2Neibs
(
theano
.
sandbox
.
test_neighbours
.
T_Images2Neibs
):
mode
=
mode_with_gpu
op
=
GpuImages2Neibs
dtypes
=
[
'float32'
]
if
__name__
==
'__main__'
:
unittest
.
main
()
theano/sandbox/test_neighbours.py
浏览文件 @
ca55d2f9
...
...
@@ -18,9 +18,11 @@ else:
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
class
T_Images2Neibs
(
unittest_tools
.
InferShapeTester
):
mode
=
mode_without_gpu
op
=
Images2Neibs
dtypes
=
[
'int64'
,
'float32'
,
'float64'
]
def
test_neibs
(
self
):
for
shape
,
pshape
in
[((
100
,
40
,
18
,
18
),
(
2
,
2
)),
...
...
@@ -29,17 +31,23 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
((
10
,
40
,
68
,
66
),
(
34
,
33
))
]:
for
border
in
[
'valid'
,
'ignore_borders'
]:
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
for
dtype
in
self
.
dtypes
:
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
dtype
)
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
(
pshape
)
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
border
),
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
border
),
mode
=
self
.
mode
)
#print images.get_value(borrow=True)
neibs
=
f
()
#print neibs
g
=
function
([],
neibs2images
(
neibs
,
neib_shape
,
images
.
shape
),
g
=
function
([],
neibs2images
(
neibs
,
neib_shape
,
images
.
shape
),
mode
=
self
.
mode
)
if
border
in
[
'valid'
]:
assert
any
([
isinstance
(
node
.
op
,
self
.
op
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
...
...
@@ -48,7 +56,10 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
def
test_neibs_manual
(
self
):
shape
=
(
2
,
3
,
4
,
4
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
for
dtype
in
self
.
dtypes
:
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
dtype
)
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
((
2
,
2
))
for
border
in
[
'valid'
,
'ignore_borders'
]:
...
...
@@ -89,15 +100,19 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
def
test_neibs_manual_step
(
self
):
shape
=
(
2
,
3
,
5
,
5
)
for
dtype
in
self
.
dtypes
:
images
=
shared
(
numpy
.
asarray
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
),
dtype
=
'float32'
))
shape
))
.
reshape
(
shape
),
dtype
=
dtype
))
neib_shape
=
T
.
as_tensor_variable
((
3
,
3
))
neib_step
=
T
.
as_tensor_variable
((
2
,
2
))
for
border
in
[
'valid'
,
'ignore_borders'
]:
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
neib_step
,
mode
=
border
),
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
neib_step
,
mode
=
border
),
mode
=
self
.
mode
)
neibs
=
f
()
if
border
in
[
'valid'
]:
assert
self
.
op
in
[
type
(
node
.
op
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
...
...
@@ -136,15 +151,21 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
def
test_neibs_bad_shape
(
self
):
shape
=
(
2
,
3
,
10
,
10
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
for
dtype
in
self
.
dtypes
:
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
dtype
)
.
reshape
(
shape
))
for
neib_shape
in
[(
3
,
2
),
(
2
,
3
)]:
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
f
=
function
([],
images2neibs
(
images
,
neib_shape
),
mode
=
self
.
mode
)
f
=
function
([],
images2neibs
(
images
,
neib_shape
),
mode
=
self
.
mode
)
self
.
assertRaises
(
TypeError
,
f
)
#Test that ignore border work in that case.
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
'ignore_borders'
),
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
'ignore_borders'
),
mode
=
self
.
mode
)
f
()
...
...
@@ -197,8 +218,10 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
[(
1
,
1
,
1045
,
5
),
(
3
,
3
),
(
3
,
3
),
None
],
]):
for
dtype
in
self
.
dtypes
:
images
=
shared
(
numpy
.
asarray
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
),
dtype
=
'float32'
))
shape
))
.
reshape
(
shape
),
dtype
=
dtype
))
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
neib_step
=
T
.
as_tensor_variable
(
neib_step
)
expected
=
numpy
.
asarray
(
expected
)
...
...
@@ -210,9 +233,10 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
if
expected
.
size
>
1
:
for
i
in
range
(
shape
[
0
]
*
shape
[
1
]):
assert
numpy
.
allclose
(
neibs
[
i
*
expected
.
shape
[
0
]:
assert
numpy
.
allclose
(
neibs
[
i
*
expected
.
shape
[
0
]:
(
i
+
1
)
*
expected
.
shape
[
0
],
:],
expected
+
25
*
i
),
mode_idx
expected
+
25
*
i
),
"wrap_centered"
assert
self
.
op
in
[
type
(
node
.
op
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
...
...
@@ -223,7 +247,11 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
def
test_neibs_bad_shape_wrap_centered
(
self
):
shape
=
(
2
,
3
,
10
,
10
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
for
dtype
in
self
.
dtypes
:
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
dtype
)
.
reshape
(
shape
))
for
neib_shape
in
[(
3
,
2
),
(
2
,
3
)]:
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
...
...
theano/tests/unittest_tools.py
浏览文件 @
ca55d2f9
...
...
@@ -166,9 +166,11 @@ class T_OpContractMixin(object):
class
InferShapeTester
(
unittest
.
TestCase
):
def
setUp
(
self
):
seed_rng
()
# Take into account any mode that may be defined in a child class
mode
=
getattr
(
self
,
'mode'
,
theano
.
compile
.
get_default_mode
())
# This mode seems to be the minimal one including the shape_i
# optimizations, if we don't want to enumerate them explicitly.
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
"canonicalize"
)
self
.
mode
=
mode
.
including
(
"canonicalize"
)
def
_compile_and_check
(
self
,
inputs
,
outputs
,
numeric_inputs
,
cls
,
excluding
=
None
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论