Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
278525e1
提交
278525e1
authored
4月 23, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2768 from nouiz/faster_test
[MRG] Faster test
上级
00d4a5d0
b91ab02b
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
111 行增加
和
63 行删除
+111
-63
graph.py
theano/gof/graph.py
+66
-30
test_scan.py
theano/scan_module/tests/test_scan.py
+1
-0
test_sp.py
theano/sparse/sandbox/test_sp.py
+2
-0
test_basic.py
theano/sparse/tests/test_basic.py
+2
-0
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+3
-0
test_extra_ops.py
theano/tensor/tests/test_extra_ops.py
+4
-0
test_opt.py
theano/tensor/tests/test_opt.py
+24
-27
test_slinalg.py
theano/tensor/tests/test_slinalg.py
+6
-6
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+1
-0
test_tutorial.py
theano/tests/test_tutorial.py
+2
-0
没有找到文件。
theano/gof/graph.py
浏览文件 @
278525e1
...
@@ -716,7 +716,8 @@ def clone_get_equiv(inputs, outputs,
...
@@ -716,7 +716,8 @@ def clone_get_equiv(inputs, outputs,
return
memo
return
memo
def
general_toposort
(
r_out
,
deps
,
debug_print
=
False
):
def
general_toposort
(
r_out
,
deps
,
debug_print
=
False
,
_deps
=
None
,
deps_cache
=
None
):
"""WRITEME
"""WRITEME
:note:
:note:
...
@@ -727,22 +728,29 @@ def general_toposort(r_out, deps, debug_print=False):
...
@@ -727,22 +728,29 @@ def general_toposort(r_out, deps, debug_print=False):
:note:
:note:
The order of the return value list is determined by the order of nodes returned by the deps() function.
The order of the return value list is determined by the order of nodes returned by the deps() function.
"""
deps_cache
=
{}
def
_deps
(
io
):
:note: deps should be provided or can be None and the caller
if
io
not
in
deps_cache
:
provide _deps and deps_cache. The second option remove a
d
=
deps
(
io
)
Python function call, so is faster.
if
d
:
if
not
isinstance
(
d
,
(
list
,
OrderedSet
)):
"""
raise
TypeError
(
"Non-deterministic collections here make"
if
_deps
is
None
:
deps_cache
=
{}
def
_deps
(
io
):
if
io
not
in
deps_cache
:
d
=
deps
(
io
)
if
d
:
if
not
isinstance
(
d
,
(
list
,
OrderedSet
)):
raise
TypeError
(
"Non-deterministic collections here make"
" toposort non-deterministic."
)
" toposort non-deterministic."
)
deps_cache
[
io
]
=
list
(
d
)
deps_cache
[
io
]
=
list
(
d
)
else
:
deps_cache
[
io
]
=
d
return
d
else
:
else
:
deps_cache
[
io
]
=
d
return
deps_cache
[
io
]
return
d
else
:
return
deps_cache
[
io
]
assert
isinstance
(
r_out
,
(
tuple
,
list
,
deque
))
assert
isinstance
(
r_out
,
(
tuple
,
list
,
deque
))
...
@@ -786,26 +794,54 @@ def io_toposort(inputs, outputs, orderings=None):
...
@@ -786,26 +794,54 @@ def io_toposort(inputs, outputs, orderings=None):
order. no sets allowed!
order. no sets allowed!
"""
"""
if
orderings
is
None
:
orderings
=
{}
# the inputs are used only here in the function that decides what 'predecessors' to explore
# the inputs are used only here in the function that decides what 'predecessors' to explore
iset
=
set
(
inputs
)
iset
=
set
(
inputs
)
def
deps
(
obj
):
# We build 2 functions as a speed up
rval
=
[]
deps_cache
=
{}
if
obj
not
in
iset
:
if
isinstance
(
obj
,
Variable
):
deps
=
None
if
obj
.
owner
:
_deps
=
None
rval
=
[
obj
.
owner
]
if
not
orderings
:
# can be None or empty dict
elif
isinstance
(
obj
,
Apply
):
# Specialized function that is faster when no ordering.
rval
=
list
(
obj
.
inputs
)
# Also include the cache in the function itself for speed up.
rval
.
extend
(
orderings
.
get
(
obj
,
[]))
def
_deps
(
obj
):
else
:
if
obj
in
deps_cache
:
assert
not
orderings
.
get
(
obj
,
[])
return
deps_cache
[
io
]
return
rval
rval
=
[]
if
obj
not
in
iset
:
if
isinstance
(
obj
,
Variable
):
if
obj
.
owner
:
rval
=
[
obj
.
owner
]
elif
isinstance
(
obj
,
Apply
):
rval
=
list
(
obj
.
inputs
)
if
rval
:
if
not
isinstance
(
rval
,
(
list
,
OrderedSet
)):
raise
TypeError
(
"Non-deterministic collections here make"
" toposort non-deterministic."
)
deps_cache
[
obj
]
=
list
(
rval
)
else
:
deps_cache
[
obj
]
=
rval
else
:
deps_cache
[
obj
]
=
rval
return
rval
else
:
def
deps
(
obj
):
rval
=
[]
if
obj
not
in
iset
:
if
isinstance
(
obj
,
Variable
):
if
obj
.
owner
:
rval
=
[
obj
.
owner
]
elif
isinstance
(
obj
,
Apply
):
rval
=
list
(
obj
.
inputs
)
rval
.
extend
(
orderings
.
get
(
obj
,
[]))
else
:
assert
not
orderings
.
get
(
obj
,
[])
return
rval
topo
=
general_toposort
(
outputs
,
deps
)
topo
=
general_toposort
(
outputs
,
deps
=
deps
,
_deps
=
_deps
,
deps_cache
=
deps_cache
)
return
[
o
for
o
in
topo
if
isinstance
(
o
,
Apply
)]
return
[
o
for
o
in
topo
if
isinstance
(
o
,
Apply
)]
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
278525e1
...
@@ -1969,6 +1969,7 @@ class T_Scan(unittest.TestCase):
...
@@ -1969,6 +1969,7 @@ class T_Scan(unittest.TestCase):
analytic_grad
=
reset_rng_grad_fn
(
v_u
,
v_x0
,
vW_in
)
analytic_grad
=
reset_rng_grad_fn
(
v_u
,
v_x0
,
vW_in
)
utt
.
assert_allclose
(
analytic_grad
[
0
][:
2
],
numpy
.
zeros
((
2
,
2
)))
utt
.
assert_allclose
(
analytic_grad
[
0
][:
2
],
numpy
.
zeros
((
2
,
2
)))
@attr
(
'slow'
)
def
test_grad_multiple_outs_some_disconnected
(
self
):
def
test_grad_multiple_outs_some_disconnected
(
self
):
# Created on Tue Oct 07 13:28:51 2014
# Created on Tue Oct 07 13:28:51 2014
# @author: vaneetke
# @author: vaneetke
...
...
theano/sparse/sandbox/test_sp.py
浏览文件 @
278525e1
...
@@ -24,6 +24,7 @@ from theano.sparse.tests.test_basic import sparse_random_inputs
...
@@ -24,6 +24,7 @@ from theano.sparse.tests.test_basic import sparse_random_inputs
class
TestSP
(
unittest
.
TestCase
):
class
TestSP
(
unittest
.
TestCase
):
@attr
(
'slow'
)
def
test_convolution
(
self
):
def
test_convolution
(
self
):
# print '\n\n*************************************************'
# print '\n\n*************************************************'
# print ' TEST CONVOLUTION'
# print ' TEST CONVOLUTION'
...
@@ -218,6 +219,7 @@ class TestSP(unittest.TestCase):
...
@@ -218,6 +219,7 @@ class TestSP(unittest.TestCase):
# print 'Theano processing time: ', ttot
# print 'Theano processing time: ', ttot
# profmode.print_summary()
# profmode.print_summary()
@attr
(
'slow'
)
def
test_multilayer_sparse
(
self
):
def
test_multilayer_sparse
(
self
):
# fixed parameters
# fixed parameters
bsize
=
10
# batch size
bsize
=
10
# batch size
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
278525e1
import
time
import
time
import
unittest
import
unittest
from
nose.plugins.attrib
import
attr
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
try
:
try
:
...
@@ -2347,6 +2348,7 @@ class CastTester(utt.InferShapeTester):
...
@@ -2347,6 +2348,7 @@ class CastTester(utt.InferShapeTester):
utt
.
assert_allclose
(
expected
,
t_cls
)
utt
.
assert_allclose
(
expected
,
t_cls
)
utt
.
assert_allclose
(
expected
,
t_prop
)
utt
.
assert_allclose
(
expected
,
t_prop
)
@attr
(
'slow'
)
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
for
format
in
sparse
.
sparse_formats
:
for
format
in
sparse
.
sparse_formats
:
for
i_dtype
in
sparse
.
all_dtypes
:
for
i_dtype
in
sparse
.
all_dtypes
:
...
...
theano/tensor/tests/test_elemwise.py
浏览文件 @
278525e1
...
@@ -521,6 +521,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
...
@@ -521,6 +521,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
self
.
with_linker
(
gof
.
CLinker
(),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
CLinker
(),
scalar
.
and_
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
CLinker
(),
scalar
.
xor
,
dtype
=
dtype
)
self
.
with_linker
(
gof
.
CLinker
(),
scalar
.
xor
,
dtype
=
dtype
)
@attr
(
'slow'
)
def
test_c_nan
(
self
):
def
test_c_nan
(
self
):
if
not
theano
.
config
.
cxx
:
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
...
@@ -568,6 +569,7 @@ class test_Prod(unittest.TestCase):
...
@@ -568,6 +569,7 @@ class test_Prod(unittest.TestCase):
self
.
mode
=
mode
self
.
mode
=
mode
@attr
(
'slow'
)
def
test_verify_grad
(
self
):
def
test_verify_grad
(
self
):
# including zeros, as the case with zeros is important
# including zeros, as the case with zeros is important
...
@@ -624,6 +626,7 @@ class test_Prod(unittest.TestCase):
...
@@ -624,6 +626,7 @@ class test_Prod(unittest.TestCase):
#unittest_tools.verify_grad(fn5, [x_val])
#unittest_tools.verify_grad(fn5, [x_val])
@attr
(
'slow'
)
def
test_prod_no_zeros_in_input
(
self
):
def
test_prod_no_zeros_in_input
(
self
):
x
=
theano
.
tensor
.
dmatrix
()
x
=
theano
.
tensor
.
dmatrix
()
x_val
=
numpy
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
],
[
7
,
8
,
9
]],
dtype
=
'float32'
)
x_val
=
numpy
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
],
[
7
,
8
,
9
]],
dtype
=
'float32'
)
...
...
theano/tensor/tests/test_extra_ops.py
浏览文件 @
278525e1
from
nose.plugins.attrib
import
attr
import
numpy
as
np
import
numpy
as
np
import
numpy
import
numpy
import
unittest
import
unittest
...
@@ -191,6 +192,7 @@ class TestBinCountOp(utt.InferShapeTester):
...
@@ -191,6 +192,7 @@ class TestBinCountOp(utt.InferShapeTester):
assert
(
np
.
bincount
(
a
,
minlength
=
23
)
==
f3
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
23
)
==
f3
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
5
)
==
f4
(
a
))
.
all
()
assert
(
np
.
bincount
(
a
,
minlength
=
5
)
==
f4
(
a
))
.
all
()
@attr
(
'slow'
)
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
for
dtype
in
tensor
.
discrete_dtypes
:
for
dtype
in
tensor
.
discrete_dtypes
:
# uint64 always fails
# uint64 always fails
...
@@ -432,6 +434,7 @@ class TestRepeatOp(utt.InferShapeTester):
...
@@ -432,6 +434,7 @@ class TestRepeatOp(utt.InferShapeTester):
assert
np
.
allclose
(
np
.
repeat
(
a
,
r
,
axis
=
axis
),
assert
np
.
allclose
(
np
.
repeat
(
a
,
r
,
axis
=
axis
),
f
(
a
,
r
))
f
(
a
,
r
))
@attr
(
'slow'
)
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
for
ndim
in
range
(
4
):
for
ndim
in
range
(
4
):
x
=
T
.
TensorType
(
config
.
floatX
,
[
False
]
*
ndim
)()
x
=
T
.
TensorType
(
config
.
floatX
,
[
False
]
*
ndim
)()
...
@@ -545,6 +548,7 @@ class TestFillDiagonal(utt.InferShapeTester):
...
@@ -545,6 +548,7 @@ class TestFillDiagonal(utt.InferShapeTester):
assert
out
[
2
,
2
,
2
]
==
val
assert
out
[
2
,
2
,
2
]
==
val
assert
(
out
==
val
)
.
sum
()
==
min
(
a
.
shape
)
assert
(
out
==
val
)
.
sum
()
==
min
(
a
.
shape
)
@attr
(
'slow'
)
def
test_gradient
(
self
):
def
test_gradient
(
self
):
utt
.
verify_grad
(
fill_diagonal
,
[
numpy
.
random
.
rand
(
5
,
8
),
utt
.
verify_grad
(
fill_diagonal
,
[
numpy
.
random
.
rand
(
5
,
8
),
numpy
.
random
.
rand
()],
numpy
.
random
.
rand
()],
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
278525e1
...
@@ -304,23 +304,20 @@ class test_canonize(unittest.TestCase):
...
@@ -304,23 +304,20 @@ class test_canonize(unittest.TestCase):
# We must be sure that the Canonizer is working, but that we don't have other
# We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode
=
compile
.
mode
.
get_default_mode
()
mode
=
compile
.
mode
.
get_default_mode
()
old_optimizer
=
mode
.
_optimizer
opt
=
gof
.
Query
([
"canonicalize"
])
try
:
opt
=
opt
.
excluding
(
'local_elemwise_fusion'
)
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
=
mode
.
__class__
(
linker
=
mode
.
linker
,
optimizer
=
opt
)
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
for
id
,
[
g
,
sym_inputs
,
val_inputs
,
'local_elemwise_fusion'
)
nb_elemwise
,
out_dtype
]
in
enumerate
(
cases
):
for
id
,
[
g
,
sym_inputs
,
val_inputs
,
nb_elemwise
,
out_dtype
]
in
enumerate
(
cases
):
if
isinstance
(
out_dtype
,
dict
):
if
isinstance
(
out_dtype
,
dict
):
out_dtype
=
out_dtype
[
config
.
cast_policy
]
out_dtype
=
out_dtype
[
config
.
cast_policy
]
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
f
=
compile
.
function
(
list
(
sym_inputs
),
g
,
# we need the optimisation enabled, debug do this.
# we need the optimisation enabled, debug do this.
mode
=
mode
)
mode
=
mode
)
out
=
f
(
*
val_inputs
)
out
=
f
(
*
val_inputs
)
assert
(
len
(
f
.
maker
.
fgraph
.
toposort
())
==
nb_elemwise
)
assert
(
len
(
f
.
maker
.
fgraph
.
toposort
())
==
nb_elemwise
)
assert
(
out_dtype
==
out
.
dtype
)
assert
(
out_dtype
==
out
.
dtype
)
finally
:
mode
.
_optimizer
=
old_optimizer
def
test_elemwise_multiple_inputs_optimisation2
(
self
):
def
test_elemwise_multiple_inputs_optimisation2
(
self
):
"""
"""
...
@@ -455,13 +452,12 @@ class test_canonize(unittest.TestCase):
...
@@ -455,13 +452,12 @@ class test_canonize(unittest.TestCase):
# We must be sure that the Canonizer is working, but that we don't have other
# We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode
=
compile
.
mode
.
get_default_mode
()
mode
=
compile
.
mode
.
get_default_mode
()
old_optimizer
=
mode
.
_optimizer
try
:
try
:
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
opt
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
mode
.
_optimizer
.
including
(
'ShapeOpt'
)
opt
=
opt
.
including
(
'ShapeOpt'
)
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
opt
=
opt
.
excluding
(
'local_elemwise_fusion'
)
'local_elemwise_fusion'
)
mode
=
mode
.
__class__
(
linker
=
mode
.
linker
,
optimizer
=
opt
)
# test x / x -> 1
# test x / x -> 1
for
id
,
(
g
,
sym_inputs
,
val_inputs
,
out_dtype
)
in
enumerate
([(
fx
/
fx
,
[
fx
],
[
fxv
],
'float32'
),
for
id
,
(
g
,
sym_inputs
,
val_inputs
,
out_dtype
)
in
enumerate
([(
fx
/
fx
,
[
fx
],
[
fxv
],
'float32'
),
(
dx
/
dx
,
[
dx
],
[
dxv
],
'float64'
),
(
dx
/
dx
,
[
dx
],
[
dxv
],
'float64'
),
...
@@ -644,7 +640,7 @@ class test_canonize(unittest.TestCase):
...
@@ -644,7 +640,7 @@ class test_canonize(unittest.TestCase):
assert
numpy
.
allclose
(
out
,
numpy
.
sign
(
val_inputs
[
0
])
*
2
/
3
)
assert
numpy
.
allclose
(
out
,
numpy
.
sign
(
val_inputs
[
0
])
*
2
/
3
)
assert
(
out_dtype
==
out
.
dtype
)
assert
(
out_dtype
==
out
.
dtype
)
finally
:
finally
:
mode
.
_optimizer
=
old_optimizer
pass
def
test_abs_mul_div
(
self
):
def
test_abs_mul_div
(
self
):
"""
"""
...
@@ -705,12 +701,11 @@ class test_canonize(unittest.TestCase):
...
@@ -705,12 +701,11 @@ class test_canonize(unittest.TestCase):
# We must be sure that the Canonizer is working, but that we don't have other
# We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode
=
compile
.
mode
.
get_default_mode
()
mode
=
compile
.
mode
.
get_default_mode
()
old_optimizer
=
mode
.
_optimizer
try
:
try
:
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
opt
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
opt
=
opt
.
excluding
(
'local_elemwise_fusion'
)
'local_elemwise_fusion'
)
mode
=
mode
.
__class__
(
linker
=
mode
.
linker
,
optimizer
=
opt
)
# test fail!
# test fail!
# test x / y / z -> x / (y * z)
# test x / y / z -> x / (y * z)
for
(
g
,
sym_inputs
,
val_inputs
,
out_dtype
)
in
[
for
(
g
,
sym_inputs
,
val_inputs
,
out_dtype
)
in
[
...
@@ -749,7 +744,7 @@ class test_canonize(unittest.TestCase):
...
@@ -749,7 +744,7 @@ class test_canonize(unittest.TestCase):
assert
(
out_dtype
==
out
.
dtype
)
assert
(
out_dtype
==
out
.
dtype
)
finally
:
finally
:
mode
.
_optimizer
=
old_optimizer
pass
def
test_dont_merge_if_multiple_client
(
self
):
def
test_dont_merge_if_multiple_client
(
self
):
""" test those case take from the comment in Canonizer
""" test those case take from the comment in Canonizer
...
@@ -3412,6 +3407,8 @@ class test_shapeoptimizer(unittest.TestCase):
...
@@ -3412,6 +3407,8 @@ class test_shapeoptimizer(unittest.TestCase):
# Register the optimization
# Register the optimization
opt
.
register_specialize
(
local_identity_noshape_to_identity_shape
)
opt
.
register_specialize
(
local_identity_noshape_to_identity_shape
)
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'ShapeOpt'
,
'specialize'
)
# With the optimization
# With the optimization
# The identity_shape op should not be needed anymore to compute
# The identity_shape op should not be needed anymore to compute
# the shape
# the shape
...
...
theano/tensor/tests/test_slinalg.py
浏览文件 @
278525e1
...
@@ -296,30 +296,30 @@ class TestKron(utt.InferShapeTester):
...
@@ -296,30 +296,30 @@ class TestKron(utt.InferShapeTester):
raise
SkipTest
(
'kron tests need the scipy package to be installed'
)
raise
SkipTest
(
'kron tests need the scipy package to be installed'
)
for
shp0
in
[(
2
,),
(
2
,
3
),
(
2
,
3
,
4
),
(
2
,
3
,
4
,
5
)]:
for
shp0
in
[(
2
,),
(
2
,
3
),
(
2
,
3
,
4
),
(
2
,
3
,
4
,
5
)]:
x
=
tensor
.
tensor
(
dtype
=
'floatX'
,
broadcastable
=
(
False
,)
*
len
(
shp0
))
a
=
numpy
.
asarray
(
self
.
rng
.
rand
(
*
shp0
))
.
astype
(
config
.
floatX
)
for
shp1
in
[(
6
,),
(
6
,
7
),
(
6
,
7
,
8
),
(
6
,
7
,
8
,
9
)]:
for
shp1
in
[(
6
,),
(
6
,
7
),
(
6
,
7
,
8
),
(
6
,
7
,
8
,
9
)]:
if
len
(
shp0
)
+
len
(
shp1
)
==
2
:
if
len
(
shp0
)
+
len
(
shp1
)
==
2
:
continue
continue
x
=
tensor
.
tensor
(
dtype
=
'floatX'
,
broadcastable
=
(
False
,)
*
len
(
shp0
))
y
=
tensor
.
tensor
(
dtype
=
'floatX'
,
y
=
tensor
.
tensor
(
dtype
=
'floatX'
,
broadcastable
=
(
False
,)
*
len
(
shp1
))
broadcastable
=
(
False
,)
*
len
(
shp1
))
f
=
function
([
x
,
y
],
kron
(
x
,
y
))
f
=
function
([
x
,
y
],
kron
(
x
,
y
))
a
=
numpy
.
asarray
(
self
.
rng
.
rand
(
*
shp0
))
.
astype
(
config
.
floatX
)
b
=
self
.
rng
.
rand
(
*
shp1
)
.
astype
(
config
.
floatX
)
b
=
self
.
rng
.
rand
(
*
shp1
)
.
astype
(
config
.
floatX
)
out
=
f
(
a
,
b
)
out
=
f
(
a
,
b
)
assert
numpy
.
allclose
(
out
,
scipy
.
linalg
.
kron
(
a
,
b
))
assert
numpy
.
allclose
(
out
,
scipy
.
linalg
.
kron
(
a
,
b
))
def
test_numpy_2d
(
self
):
def
test_numpy_2d
(
self
):
for
shp0
in
[(
2
,
3
)]:
for
shp0
in
[(
2
,
3
)]:
x
=
tensor
.
tensor
(
dtype
=
'floatX'
,
broadcastable
=
(
False
,)
*
len
(
shp0
))
a
=
numpy
.
asarray
(
self
.
rng
.
rand
(
*
shp0
))
.
astype
(
config
.
floatX
)
for
shp1
in
[(
6
,
7
)]:
for
shp1
in
[(
6
,
7
)]:
if
len
(
shp0
)
+
len
(
shp1
)
==
2
:
if
len
(
shp0
)
+
len
(
shp1
)
==
2
:
continue
continue
x
=
tensor
.
tensor
(
dtype
=
'floatX'
,
broadcastable
=
(
False
,)
*
len
(
shp0
))
y
=
tensor
.
tensor
(
dtype
=
'floatX'
,
y
=
tensor
.
tensor
(
dtype
=
'floatX'
,
broadcastable
=
(
False
,)
*
len
(
shp1
))
broadcastable
=
(
False
,)
*
len
(
shp1
))
f
=
function
([
x
,
y
],
kron
(
x
,
y
))
f
=
function
([
x
,
y
],
kron
(
x
,
y
))
a
=
numpy
.
asarray
(
self
.
rng
.
rand
(
*
shp0
))
.
astype
(
config
.
floatX
)
b
=
self
.
rng
.
rand
(
*
shp1
)
.
astype
(
config
.
floatX
)
b
=
self
.
rng
.
rand
(
*
shp1
)
.
astype
(
config
.
floatX
)
out
=
f
(
a
,
b
)
out
=
f
(
a
,
b
)
assert
numpy
.
allclose
(
out
,
numpy
.
kron
(
a
,
b
))
assert
numpy
.
allclose
(
out
,
numpy
.
kron
(
a
,
b
))
theano/tensor/tests/test_subtensor.py
浏览文件 @
278525e1
...
@@ -1432,6 +1432,7 @@ class TestAdvancedSubtensor(unittest.TestCase):
...
@@ -1432,6 +1432,7 @@ class TestAdvancedSubtensor(unittest.TestCase):
class
TestInferShape
(
utt
.
InferShapeTester
):
class
TestInferShape
(
utt
.
InferShapeTester
):
@attr
(
'slow'
)
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
# IncSubtensor
# IncSubtensor
admat
=
dmatrix
()
admat
=
dmatrix
()
...
...
theano/tests/test_tutorial.py
浏览文件 @
278525e1
...
@@ -5,6 +5,7 @@ import os
...
@@ -5,6 +5,7 @@ import os
import
shutil
import
shutil
import
unittest
import
unittest
from
nose.plugins.attrib
import
attr
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
from
numpy
import
array
from
numpy
import
array
...
@@ -724,6 +725,7 @@ class T_examples(unittest.TestCase):
...
@@ -724,6 +725,7 @@ class T_examples(unittest.TestCase):
assert
numpy
.
allclose
(
v3
,
0.59044123
)
assert
numpy
.
allclose
(
v3
,
0.59044123
)
assert
numpy
.
allclose
(
v4
,
0.59044123
)
assert
numpy
.
allclose
(
v4
,
0.59044123
)
@attr
(
'slow'
)
def
test_examples_real_example
(
self
):
def
test_examples_real_example
(
self
):
rng
=
numpy
.
random
rng
=
numpy
.
random
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论