Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6a936ae7
提交
6a936ae7
authored
3月 30, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Have the type constructor be part of the test class.
上级
98af764b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
31 行删除
+31
-31
test_elemwise.py
theano/tensor/tests/test_elemwise.py
+13
-11
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+18
-20
没有找到文件。
theano/tensor/tests/test_elemwise.py
浏览文件 @
6a936ae7
...
...
@@ -27,6 +27,7 @@ def FunctionGraph(i, o):
class
test_DimShuffle
(
unittest_tools
.
InferShapeTester
):
op
=
DimShuffle
type
=
TensorType
def
with_linker
(
self
,
linker
):
for
xsh
,
shuffle
,
zsh
in
[((
2
,
3
),
(
1
,
'x'
,
0
),
(
3
,
1
,
2
)),
...
...
@@ -40,12 +41,12 @@ class test_DimShuffle(unittest_tools.InferShapeTester):
((
1
,
1
,
1
),
(),
()),
((
1
,),
(
'x'
,
'x'
),
(
1
,
1
))]:
ib
=
[(
entry
==
1
)
for
entry
in
xsh
]
x
=
TensorT
ype
(
'float64'
,
ib
)(
'x'
)
x
=
self
.
t
ype
(
'float64'
,
ib
)(
'x'
)
e
=
self
.
op
(
ib
,
shuffle
)(
x
)
f
=
copy
(
linker
)
.
accept
(
FunctionGraph
([
x
],
[
e
]))
.
make_function
()
assert
f
(
numpy
.
ones
(
xsh
))
.
shape
==
zsh
# test that DimShuffle.infer_shape work correctly
x
=
TensorT
ype
(
'float64'
,
ib
)(
'x'
)
x
=
self
.
t
ype
(
'float64'
,
ib
)(
'x'
)
e
=
self
.
op
(
ib
,
shuffle
)(
x
)
f
=
copy
(
linker
)
.
accept
(
FunctionGraph
([
x
],
[
e
.
shape
]))
.
make_function
()
...
...
@@ -53,12 +54,12 @@ class test_DimShuffle(unittest_tools.InferShapeTester):
# Test when we drop a axis that is not broadcastable
ib
=
[
False
,
True
,
False
]
x
=
TensorT
ype
(
'float64'
,
ib
)(
'x'
)
x
=
self
.
t
ype
(
'float64'
,
ib
)(
'x'
)
self
.
assertRaises
(
ValueError
,
self
.
op
,
ib
,
shuffle
)
# Test when we drop a axis that don't have shape 1
ib
=
[
True
,
True
,
False
]
x
=
TensorT
ype
(
'float64'
,
ib
)(
'x'
)
x
=
self
.
t
ype
(
'float64'
,
ib
)(
'x'
)
e
=
self
.
op
(
ib
,
(
1
,
2
))(
x
)
f
=
copy
(
linker
)
.
accept
(
FunctionGraph
([
x
],
[
e
.
shape
]))
.
make_function
()
self
.
assertRaises
(
TypeError
,
f
,
numpy
.
ones
((
2
,
1
,
4
)))
...
...
@@ -66,7 +67,7 @@ class test_DimShuffle(unittest_tools.InferShapeTester):
# Test that we can't take a dimensions multiple time
xsh
,
shuffle
,
zsh
=
((
1
,
1
,
4
),
(
0
,
1
,
2
,
0
),
(
1
,
4
))
ib
=
[
False
,
True
,
False
]
x
=
TensorT
ype
(
'float64'
,
ib
)(
'x'
)
x
=
self
.
t
ype
(
'float64'
,
ib
)(
'x'
)
self
.
assertRaises
(
ValueError
,
DimShuffle
,
ib
,
shuffle
)
def
test_perform
(
self
):
...
...
@@ -89,7 +90,7 @@ class test_DimShuffle(unittest_tools.InferShapeTester):
((
1
,
1
,
1
),
()),
((
1
,),
(
'x'
,
'x'
))]:
ib
=
[(
entry
==
1
)
for
entry
in
xsh
]
adtens
=
TensorT
ype
(
'float64'
,
ib
)(
'x'
)
adtens
=
self
.
t
ype
(
'float64'
,
ib
)(
'x'
)
adtens_val
=
numpy
.
ones
(
xsh
)
self
.
_compile_and_check
([
adtens
],
[
self
.
op
(
ib
,
shuffle
)(
adtens
)],
...
...
@@ -97,7 +98,7 @@ class test_DimShuffle(unittest_tools.InferShapeTester):
warn
=
False
)
def
test_too_big_rank
(
self
):
x
=
tensor
.
dscalar
()
x
=
self
.
type
(
'float64'
,
broadcastable
=
())
()
y
=
x
.
dimshuffle
((
'x'
,)
*
(
numpy
.
MAXDIMS
+
1
))
self
.
assertRaises
(
ValueError
,
y
.
eval
,
{
x
:
0
})
...
...
@@ -328,6 +329,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
((),
None
),
((),
())
]
type
=
TensorType
def
with_linker
(
self
,
linker
,
scalar_op
=
scalar
.
add
,
dtype
=
"floatX"
,
pre_scalar_op
=
None
,
...
...
@@ -335,7 +337,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
for
xsh
,
tosum
in
self
.
cases
:
if
dtype
==
"floatX"
:
dtype
=
theano
.
config
.
floatX
x
=
TensorT
ype
(
dtype
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
x
=
self
.
t
ype
(
dtype
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
d
=
{}
if
pre_scalar_op
is
not
None
:
d
=
{
"pre_scalar_op"
:
pre_scalar_op
}
...
...
@@ -438,7 +440,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
if
test_nan
:
try
:
self
.
assertTrue
(
theano
.
tensor
.
TensorT
ype
.
values_eq
(
f
(
xv
),
zv
),
self
.
t
ype
.
values_eq
(
f
(
xv
),
zv
),
(
f
(
xv
),
zv
))
except
NotImplementedError
:
# GpuCAReduce don't implement all cases when size is 0
...
...
@@ -453,7 +455,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
# GpuCAReduce don't implement all cases when size is 0
assert
xv
.
size
==
0
x
=
TensorT
ype
(
dtype
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
x
=
self
.
t
ype
(
dtype
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
if
tensor_op
is
None
:
e
=
self
.
op
(
scalar_op
,
axis
=
tosum
)(
x
)
else
:
...
...
@@ -538,7 +540,7 @@ class test_CAReduce(unittest_tools.InferShapeTester):
if
dtype
is
None
:
dtype
=
theano
.
config
.
floatX
for
xsh
,
tosum
in
self
.
cases
:
x
=
TensorT
ype
(
dtype
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
x
=
self
.
t
ype
(
dtype
,
[(
entry
==
1
)
for
entry
in
xsh
])(
'x'
)
if
pre_scalar_op
is
not
None
:
x
=
pre_scalar_op
(
x
)
if
tosum
is
None
:
...
...
theano/tensor/tests/test_subtensor.py
浏览文件 @
6a936ae7
...
...
@@ -49,6 +49,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
adv_incsub1
=
tensor
.
AdvancedIncSubtensor1
,
mode
=
None
,
dtype
=
theano
.
config
.
floatX
,
type
=
tensor
.
TensorType
,
ignore_topo
=
DeepCopyOp
):
self
.
shared
=
shared
self
.
sub
=
sub
...
...
@@ -59,6 +60,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
self
.
mode
=
mode
self
.
dtype
=
dtype
self
.
type
=
type
self
.
ignore_topo
=
ignore_topo
self
.
fast_compile
=
theano
.
config
.
mode
==
'FAST_COMPILE'
self
.
ops
=
(
sub
,
inc_sub
,
adv_sub1
,
adv_incsub1
)
...
...
@@ -88,8 +90,10 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
Subtensor
.
debug
=
False
utt
.
seed_rng
()
def
eval_output_and_check
(
self
,
t
,
list
=
False
):
f
=
inplace_func
([],
t
,
mode
=
self
.
mode
)
def
eval_output_and_check
(
self
,
t
,
list
=
False
,
mode
=
None
):
if
mode
is
None
:
mode
=
self
.
mode
f
=
inplace_func
([],
t
,
mode
=
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
...
...
@@ -167,12 +171,8 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
n
=
self
.
shared
(
numpy
.
ones
((),
dtype
=
self
.
dtype
))
t
=
self
.
sub
([])(
n
)
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
Subtensor
))
mode
=
self
.
mode
self
.
mode
=
mode
.
excluding
(
"local_useless_subtensor"
)
try
:
self
.
eval_output_and_check
(
t
)
finally
:
self
.
mode
=
mode
self
.
eval_output_and_check
(
t
,
mode
=
self
.
mode
.
excluding
(
"local_useless_subtensor"
))
def
test1_err_invalid
(
self
):
n
=
self
.
shared
(
numpy
.
ones
(
1
,
dtype
=
self
.
dtype
))
...
...
@@ -885,16 +885,14 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
Test increment and set with broadcast
"""
X
=
tensor
.
matrix
(
dtype
=
self
.
dtype
)
X
=
self
.
shared
(
numpy
.
ones
((
9
,
9
))
.
astype
(
self
.
dtype
)
)
y
=
set_subtensor
(
X
[
1
::,
1
::],
0
)
f
=
self
.
function
([
X
],
[
y
],
f
=
self
.
function
([],
[
y
],
op
=
self
.
inc_sub
,
N
=
1
)
out
=
f
()
x_
=
numpy
.
ones
((
9
,
9
))
out
=
f
(
x_
.
astype
(
'float32'
))
res
=
x_
.
copy
()
res
=
numpy
.
ones
((
9
,
9
))
res
[
1
::,
1
::]
=
0
assert
numpy
.
allclose
(
out
,
res
)
...
...
@@ -925,9 +923,9 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
# Symbolic variable to be incremented.
# We create a new one every time in order not to
# have duplicated variables in the function's inputs
data_var
=
tensor
.
tensor
(
broadcastable
=
[
False
]
*
data_n_dims
,
dtype
=
self
.
dtype
)
data_var
=
self
.
type
(
broadcastable
=
[
False
]
*
data_n_dims
,
dtype
=
self
.
dtype
)(
)
# Symbolic variable with rows to be incremented.
idx_var
=
theano
.
tensor
.
vector
(
dtype
=
'int64'
)
n_to_inc
=
rng
.
randint
(
data_shape
[
0
])
...
...
@@ -935,9 +933,9 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
idx_num
=
rng
.
randint
(
0
,
data_shape
[
0
],
n_to_inc
)
idx_num
=
idx_num
.
astype
(
'int64'
)
# Symbolic variable with increment value.
inc_var
=
tensor
.
tensor
(
broadcastable
=
[
False
]
*
inc_n_dims
,
dtype
=
self
.
dtype
)
inc_var
=
self
.
type
(
broadcastable
=
[
False
]
*
inc_n_dims
,
dtype
=
self
.
dtype
)(
)
# Trick for the case where `inc_shape` is the same as
# `data_shape`: what we actually want is the first
# shape element to be equal to the number of rows to
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论