Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8f5e49d3
提交
8f5e49d3
authored
2月 02, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2465 from nouiz/tests
Fix tests
上级
10063ce8
20e31da5
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
45 行增加
和
32 行删除
+45
-32
extra_ops.py
theano/sandbox/cuda/extra_ops.py
+3
-2
test_extra_ops.py
theano/sandbox/cuda/tests/test_extra_ops.py
+42
-29
test_basic.py
theano/sparse/tests/test_basic.py
+0
-1
没有找到文件。
theano/sandbox/cuda/extra_ops.py
浏览文件 @
8f5e49d3
...
@@ -25,8 +25,9 @@ class GpuCumsum(CumsumOp, GpuOp):
...
@@ -25,8 +25,9 @@ class GpuCumsum(CumsumOp, GpuOp):
self
.
max_grid_size1
=
None
self
.
max_grid_size1
=
None
self
.
max_grid_size2
=
None
self
.
max_grid_size2
=
None
def
perform
(
self
,
node
,
inp
,
out
):
# We must reuse the same method, not reimplement and call it.
return
Op
.
perform
(
self
,
node
,
inp
,
out
)
# Otherwise DebugMode will print many warnings.
perform
=
Op
.
perform
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
assert
x
.
dtype
==
'float32'
assert
x
.
dtype
==
'float32'
...
...
theano/sandbox/cuda/tests/test_extra_ops.py
浏览文件 @
8f5e49d3
# Skip test if cuda_ndarray is not available.
# Skip test if cuda_ndarray is not available.
import
itertools
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
as
np
import
theano.sandbox.cuda
as
cuda_ndarray
import
theano.sandbox.cuda
as
cuda_ndarray
if
cuda_ndarray
.
cuda_available
is
False
:
if
cuda_ndarray
.
cuda_available
is
False
:
...
@@ -14,10 +17,10 @@ else:
...
@@ -14,10 +17,10 @@ else:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
from
theano
import
tensor
as
T
from
theano
import
tensor
as
T
import
numpy
as
np
import
theano
import
theano
from
theano.tensor.extra_ops
import
cumsum
,
CumsumOp
from
theano.tensor.extra_ops
import
cumsum
,
CumsumOp
import
itertools
from
theano.tests
import
unittest_tools
as
utt
class
TestGpuCumsum
(
theano
.
tensor
.
tests
.
test_extra_ops
.
TestCumsumOp
):
class
TestGpuCumsum
(
theano
.
tensor
.
tests
.
test_extra_ops
.
TestCumsumOp
):
mode
=
mode_with_gpu
mode
=
mode_with_gpu
...
@@ -46,7 +49,8 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
...
@@ -46,7 +49,8 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
for
axis
in
[
0
,
None
]:
for
axis
in
[
0
,
None
]:
a
=
np
.
random
.
random
((
42
,))
.
astype
(
"float32"
)
a
=
np
.
random
.
random
((
42
,))
.
astype
(
"float32"
)
cumsum_function
=
theano
.
function
([
x
],
cumsum
(
x
,
axis
=
axis
),
mode
=
self
.
mode
)
cumsum_function
=
theano
.
function
([
x
],
cumsum
(
x
,
axis
=
axis
),
mode
=
self
.
mode
)
slicings
=
[
slice
(
None
,
None
,
None
),
# Normal strides
slicings
=
[
slice
(
None
,
None
,
None
),
# Normal strides
slice
(
None
,
None
,
2
),
# Stepped strides
slice
(
None
,
None
,
2
),
# Stepped strides
...
@@ -55,18 +59,21 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
...
@@ -55,18 +59,21 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
# Cartesian product of all slicings to test.
# Cartesian product of all slicings to test.
for
slicing
in
itertools
.
product
(
slicings
,
repeat
=
x
.
ndim
):
for
slicing
in
itertools
.
product
(
slicings
,
repeat
=
x
.
ndim
):
f
=
theano
.
function
([
x
],
cumsum
(
x
[
slicing
],
axis
=
axis
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
cumsum
(
x
[
slicing
],
axis
=
axis
),
mode
=
self
.
mode
)
assert
[
n
for
n
in
f
.
maker
.
fgraph
.
toposort
()
assert
[
n
for
n
in
f
.
maker
.
fgraph
.
toposort
()
if
isinstance
(
n
.
op
,
GpuCumsum
)]
if
isinstance
(
n
.
op
,
GpuCumsum
)]
assert
np
.
allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
f
(
a
))
utt
.
assert_allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
f
(
a
))
assert
np
.
allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
cumsum_function
(
a
[
slicing
]))
utt
.
assert_allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
cumsum_function
(
a
[
slicing
]))
def
test_Strides2D
(
self
):
def
test_Strides2D
(
self
):
x
=
T
.
fmatrix
(
'x'
)
x
=
T
.
fmatrix
(
'x'
)
for
axis
in
[
0
,
1
,
None
]:
for
axis
in
[
0
,
1
,
None
]:
a
=
np
.
random
.
random
((
42
,
30
))
.
astype
(
"float32"
)
a
=
np
.
random
.
random
((
42
,
30
))
.
astype
(
"float32"
)
cumsum_function
=
theano
.
function
([
x
],
cumsum
(
x
,
axis
=
axis
),
mode
=
self
.
mode
)
cumsum_function
=
theano
.
function
([
x
],
cumsum
(
x
,
axis
=
axis
),
mode
=
self
.
mode
)
slicings
=
[
slice
(
None
,
None
,
None
),
# Normal strides
slicings
=
[
slice
(
None
,
None
,
None
),
# Normal strides
slice
(
None
,
None
,
2
),
# Stepped strides
slice
(
None
,
None
,
2
),
# Stepped strides
...
@@ -75,18 +82,21 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
...
@@ -75,18 +82,21 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
# Cartesian product of all slicings to test.
# Cartesian product of all slicings to test.
for
slicing
in
itertools
.
product
(
slicings
,
repeat
=
x
.
ndim
):
for
slicing
in
itertools
.
product
(
slicings
,
repeat
=
x
.
ndim
):
f
=
theano
.
function
([
x
],
cumsum
(
x
[
slicing
],
axis
=
axis
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
cumsum
(
x
[
slicing
],
axis
=
axis
),
mode
=
self
.
mode
)
assert
[
n
for
n
in
f
.
maker
.
fgraph
.
toposort
()
assert
[
n
for
n
in
f
.
maker
.
fgraph
.
toposort
()
if
isinstance
(
n
.
op
,
GpuCumsum
)]
if
isinstance
(
n
.
op
,
GpuCumsum
)]
assert
np
.
allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
f
(
a
))
utt
.
assert_allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
f
(
a
))
assert
np
.
allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
cumsum_function
(
a
[
slicing
]))
utt
.
assert_allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
cumsum_function
(
a
[
slicing
]))
def
test_Strides3D
(
self
):
def
test_Strides3D
(
self
):
x
=
T
.
ftensor3
(
'x'
)
x
=
T
.
ftensor3
(
'x'
)
for
axis
in
[
0
,
1
,
2
,
None
]:
for
axis
in
[
0
,
1
,
2
,
None
]:
a
=
np
.
random
.
random
((
42
,
30
,
25
))
.
astype
(
"float32"
)
a
=
np
.
random
.
random
((
42
,
30
,
25
))
.
astype
(
"float32"
)
cumsum_function
=
theano
.
function
([
x
],
cumsum
(
x
,
axis
=
axis
),
mode
=
self
.
mode
)
cumsum_function
=
theano
.
function
([
x
],
cumsum
(
x
,
axis
=
axis
),
mode
=
self
.
mode
)
slicings
=
[
slice
(
None
,
None
,
None
),
# Normal strides
slicings
=
[
slice
(
None
,
None
,
None
),
# Normal strides
slice
(
None
,
None
,
2
),
# Stepped strides
slice
(
None
,
None
,
2
),
# Stepped strides
...
@@ -95,12 +105,13 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
...
@@ -95,12 +105,13 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
# Cartesian product of all slicings to test.
# Cartesian product of all slicings to test.
for
slicing
in
itertools
.
product
(
slicings
,
repeat
=
x
.
ndim
):
for
slicing
in
itertools
.
product
(
slicings
,
repeat
=
x
.
ndim
):
f
=
theano
.
function
([
x
],
cumsum
(
x
[
slicing
],
axis
=
axis
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
cumsum
(
x
[
slicing
],
axis
=
axis
),
mode
=
self
.
mode
)
assert
[
n
for
n
in
f
.
maker
.
fgraph
.
toposort
()
assert
[
n
for
n
in
f
.
maker
.
fgraph
.
toposort
()
if
isinstance
(
n
.
op
,
GpuCumsum
)]
if
isinstance
(
n
.
op
,
GpuCumsum
)]
assert
np
.
allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
f
(
a
))
utt
.
assert_
allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
f
(
a
))
assert
np
.
allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
cumsum_function
(
a
[
slicing
]))
utt
.
assert_allclose
(
np
.
cumsum
(
a
[
slicing
],
axis
=
axis
),
cumsum_function
(
a
[
slicing
]))
def
test_GpuCumsum1D
(
self
):
def
test_GpuCumsum1D
(
self
):
block_max_size
=
self
.
max_threads_dim0
*
2
block_max_size
=
self
.
max_threads_dim0
*
2
...
@@ -113,16 +124,16 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
...
@@ -113,16 +124,16 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
# Extensive testing for the first 1025 sizes
# Extensive testing for the first 1025 sizes
a
=
np
.
random
.
random
(
1025
)
.
astype
(
"float32"
)
a
=
np
.
random
.
random
(
1025
)
.
astype
(
"float32"
)
for
i
in
xrange
(
a
.
shape
[
0
]):
for
i
in
xrange
(
a
.
shape
[
0
]):
assert
np
.
allclose
(
np
.
cumsum
(
a
[:
i
]),
f
(
a
[:
i
]))
utt
.
assert_
allclose
(
np
.
cumsum
(
a
[:
i
]),
f
(
a
[:
i
]))
# Use multiple GPU threadblocks
# Use multiple GPU threadblocks
a
=
np
.
random
.
random
((
block_max_size
+
2
,))
.
astype
(
"float32"
)
a
=
np
.
random
.
random
((
block_max_size
+
2
,))
.
astype
(
"float32"
)
assert
np
.
allclose
(
np
.
cumsum
(
a
),
f
(
a
))
utt
.
assert_
allclose
(
np
.
cumsum
(
a
),
f
(
a
))
# Use recursive cumsum
# Use recursive cumsum
a
=
np
.
ones
((
block_max_size
*
(
block_max_size
+
1
)
+
2
,),
a
=
np
.
ones
((
block_max_size
*
(
block_max_size
+
1
)
+
2
,),
dtype
=
"float32"
)
dtype
=
"float32"
)
assert
np
.
allclose
(
np
.
cumsum
(
a
),
f
(
a
))
utt
.
assert_
allclose
(
np
.
cumsum
(
a
),
f
(
a
))
def
test_GpuCumsum2D
(
self
):
def
test_GpuCumsum2D
(
self
):
block_max_size
=
self
.
max_threads_dim0
*
2
block_max_size
=
self
.
max_threads_dim0
*
2
...
@@ -142,26 +153,26 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
...
@@ -142,26 +153,26 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
slices
[
shape_axis
]
=
slice
(
i
)
slices
[
shape_axis
]
=
slice
(
i
)
fa
=
f
(
a
[
slices
])
fa
=
f
(
a
[
slices
])
npa
=
np
.
cumsum
(
a
[
slices
],
axis
=
axis
)
npa
=
np
.
cumsum
(
a
[
slices
],
axis
=
axis
)
assert
np
.
allclose
(
npa
,
fa
)
utt
.
assert_
allclose
(
npa
,
fa
)
# Use multiple GPU threadblocks
# Use multiple GPU threadblocks
a_shape
=
[
5
,
5
]
a_shape
=
[
5
,
5
]
a_shape
[
shape_axis
]
=
block_max_size
+
2
a_shape
[
shape_axis
]
=
block_max_size
+
2
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
assert
np
.
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
utt
.
assert_
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
# Use multiple GPU gridblocks
# Use multiple GPU gridblocks
a_shape
=
[
5
,
5
]
a_shape
=
[
5
,
5
]
a_shape
[
1
-
shape_axis
]
=
self
.
max_grid_size1
+
1
a_shape
[
1
-
shape_axis
]
=
self
.
max_grid_size1
+
1
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
assert
np
.
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
)
)
utt
.
assert_allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
),
rtol
=
5e-5
)
# Use recursive cumsum
# Use recursive cumsum
a_shape
=
[
3
,
3
]
a_shape
=
[
3
,
3
]
a_shape
[
shape_axis
]
=
block_max_size
*
(
block_max_size
+
1
)
+
2
a_shape
[
shape_axis
]
=
block_max_size
*
(
block_max_size
+
1
)
+
2
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
a
=
np
.
sign
(
a
-
0.5
)
.
astype
(
"float32"
)
# Avoid floating point error
a
=
np
.
sign
(
a
-
0.5
)
.
astype
(
"float32"
)
# Avoid floating point error
assert
np
.
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
utt
.
assert_
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
def
test_GpuCumsum3D
(
self
):
def
test_GpuCumsum3D
(
self
):
block_max_size
=
self
.
max_threads_dim0
*
2
block_max_size
=
self
.
max_threads_dim0
*
2
...
@@ -181,35 +192,37 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
...
@@ -181,35 +192,37 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
slices
[
shape_axis
]
=
slice
(
i
)
slices
[
shape_axis
]
=
slice
(
i
)
fa
=
f
(
a
[
slices
])
fa
=
f
(
a
[
slices
])
npa
=
np
.
cumsum
(
a
[
slices
],
axis
=
axis
)
npa
=
np
.
cumsum
(
a
[
slices
],
axis
=
axis
)
assert
np
.
allclose
(
npa
,
fa
)
utt
.
assert_
allclose
(
npa
,
fa
)
# Use multiple GPU threadblocks (along accumulation axis)
# Use multiple GPU threadblocks (along accumulation axis)
a_shape
=
[
2
,
2
,
2
]
a_shape
=
[
2
,
2
,
2
]
a_shape
[
shape_axis
]
=
block_max_size
+
2
a_shape
[
shape_axis
]
=
block_max_size
+
2
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
assert
np
.
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
utt
.
assert_
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
# Use multiple GPU gridblocks (not along accumulation axis)
# Use multiple GPU gridblocks (not along accumulation axis)
a_shape
=
[
5
,
5
,
5
]
a_shape
=
[
5
,
5
,
5
]
a_shape
[(
shape_axis
+
1
)
%
3
]
=
self
.
max_grid_size1
+
1
a_shape
[(
shape_axis
+
1
)
%
3
]
=
self
.
max_grid_size1
+
1
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
if
axis
is
None
:
if
axis
is
None
:
a
=
np
.
sign
(
a
-
0.5
)
.
astype
(
"float32"
)
# Avoid floating point error
# Avoid floating point error
assert
np
.
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
a
=
np
.
sign
(
a
-
0.5
)
.
astype
(
"float32"
)
utt
.
assert_allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
a_shape
=
[
5
,
5
,
5
]
a_shape
=
[
5
,
5
,
5
]
a_shape
[(
shape_axis
+
2
)
%
3
]
=
self
.
max_grid_size1
+
1
a_shape
[(
shape_axis
+
2
)
%
3
]
=
self
.
max_grid_size1
+
1
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
if
axis
is
None
:
if
axis
is
None
:
a
=
np
.
sign
(
a
-
0.5
)
.
astype
(
"float32"
)
# Avoid floating point error
# Avoid floating point error
assert
np
.
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
a
=
np
.
sign
(
a
-
0.5
)
.
astype
(
"float32"
)
utt
.
assert_allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
# Use recursive cumsum (along accumulation axis)
# Use recursive cumsum (along accumulation axis)
a_shape
=
[
3
,
3
,
3
]
a_shape
=
[
3
,
3
,
3
]
a_shape
[
shape_axis
]
=
block_max_size
*
(
block_max_size
+
1
)
+
2
a_shape
[
shape_axis
]
=
block_max_size
*
(
block_max_size
+
1
)
+
2
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
a
=
np
.
random
.
random
(
a_shape
)
.
astype
(
"float32"
)
a
=
np
.
sign
(
a
-
0.5
)
.
astype
(
"float32"
)
# Avoid floating point error
a
=
np
.
sign
(
a
-
0.5
)
.
astype
(
"float32"
)
# Avoid floating point error
assert
np
.
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
utt
.
assert_
allclose
(
np
.
cumsum
(
a
,
axis
=
axis
),
f
(
a
))
def
test_GpuCumsum4D
(
self
):
def
test_GpuCumsum4D
(
self
):
# Should not use the GPU version.
# Should not use the GPU version.
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
8f5e49d3
...
@@ -2105,7 +2105,6 @@ class Test_getitem(unittest.TestCase):
...
@@ -2105,7 +2105,6 @@ class Test_getitem(unittest.TestCase):
def
test_GetItem2D
(
self
):
def
test_GetItem2D
(
self
):
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
assert
scipy_ver
>=
[
0
,
11
]
is_supported_version
=
bool
(
scipy_ver
>=
[
0
,
14
])
is_supported_version
=
bool
(
scipy_ver
>=
[
0
,
14
])
sparse_formats
=
(
'csc'
,
'csr'
)
sparse_formats
=
(
'csc'
,
'csr'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论