Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0f2d75be
提交
0f2d75be
authored
3月 28, 2017
作者:
notoraptor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix typos and move tests into a class.
上级
220e6ddb
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
23 行删除
+21
-23
test_types.py
theano/gof/tests/test_types.py
+21
-23
没有找到文件。
theano/gof/tests/test_types.py
浏览文件 @
0f2d75be
...
@@ -5,6 +5,7 @@ import theano
...
@@ -5,6 +5,7 @@ import theano
from
theano
import
Op
,
Apply
,
scalar
from
theano
import
Op
,
Apply
,
scalar
from
theano.tensor
import
TensorType
from
theano.tensor
import
TensorType
from
theano.gof.type
import
CDataType
,
EnumType
,
EnumList
,
CEnumType
from
theano.gof.type
import
CDataType
,
EnumType
,
EnumList
,
CEnumType
from
unittest
import
TestCase
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
...
@@ -78,7 +79,7 @@ def test_cdata():
...
@@ -78,7 +79,7 @@ def test_cdata():
assert
(
v2
==
v
)
.
all
()
assert
(
v2
==
v
)
.
all
()
class
Test
OpEnumList
(
Op
):
class
My
OpEnumList
(
Op
):
__props__
=
(
'op_chosen'
,)
__props__
=
(
'op_chosen'
,)
params_type
=
EnumList
(
'ADD'
,
'SUB'
,
'MULTIPLY'
,
'DIVIDE'
,
ctype
=
'unsigned long long'
)
params_type
=
EnumList
(
'ADD'
,
'SUB'
,
'MULTIPLY'
,
'DIVIDE'
,
ctype
=
'unsigned long long'
)
...
@@ -120,10 +121,6 @@ class TestOpEnumList(Op):
...
@@ -120,10 +121,6 @@ class TestOpEnumList(Op):
return
(
1
,)
return
(
1
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
a
,
b
=
inputs
o
,
=
outputs
fail
=
sub
[
'fail'
]
op
=
sub
[
'params'
]
return
"""
return
"""
switch(
%(op)
s) {
switch(
%(op)
s) {
case ADD:
case ADD:
...
@@ -142,10 +139,10 @@ class TestOpEnumList(Op):
...
@@ -142,10 +139,10 @@ class TestOpEnumList(Op):
{
%(fail)
s}
{
%(fail)
s}
break;
break;
}
}
"""
%
locals
(
)
"""
%
dict
(
op
=
sub
[
'params'
],
o
=
outputs
[
0
],
a
=
inputs
[
0
],
b
=
inputs
[
1
],
fail
=
sub
[
'fail'
]
)
class
Test
OpCEnumType
(
Op
):
class
My
OpCEnumType
(
Op
):
__props__
=
(
'ctype_index'
,)
__props__
=
(
'ctype_index'
,)
params_type
=
CEnumType
(
'SIZE_INT'
,
'SIZE_FLOAT'
,
'SIZE_LONG_LONG'
,
ctype
=
'size_t'
)
params_type
=
CEnumType
(
'SIZE_INT'
,
'SIZE_FLOAT'
,
'SIZE_LONG_LONG'
,
ctype
=
'size_t'
)
...
@@ -178,15 +175,16 @@ class TestOpCEnumType(Op):
...
@@ -178,15 +175,16 @@ class TestOpCEnumType(Op):
return
(
1
,)
return
(
1
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
o
,
=
outputs
# params in C code will already contains expected C constant value.
sizeof_ctype
=
sub
[
'params'
]
return
"""
return
"""
%(o)
s =
%(sizeof_ctype)
s;
%(o)
s =
%(sizeof_ctype)
s;
"""
%
locals
()
"""
%
dict
(
o
=
outputs
[
0
],
# params in C code will already contains expected C constant value.
sizeof_ctype
=
sub
[
'params'
])
class
TestEnumTypes
(
TestCase
):
def
test_enum_class
(
):
def
test_enum_class
(
self
):
# Check that invalid enum name raises exception.
# Check that invalid enum name raises exception.
for
invalid_name
in
(
'a'
,
'_A'
,
'0'
):
for
invalid_name
in
(
'a'
,
'_A'
,
'0'
):
try
:
try
:
...
@@ -217,15 +215,16 @@ def test_enum_class():
...
@@ -217,15 +215,16 @@ def test_enum_class():
assert
e1
==
e2
assert
e1
==
e2
assert
not
(
e1
!=
e2
)
assert
not
(
e1
!=
e2
)
assert
hash
(
e1
)
==
hash
(
e2
)
assert
hash
(
e1
)
==
hash
(
e2
)
# Check access to attributes.
assert
len
((
e1
.
ctype
,
e1
.
C1
,
e1
.
C2
,
e1
.
C3
,
e1
.
C4
,
e1
.
C5
,
e1
.
C6
))
==
7
def
test_op_with_enumlist
(
self
):
def
test_op_with_enumlist
():
a
=
scalar
.
int32
()
a
=
scalar
.
int32
()
b
=
scalar
.
int32
()
b
=
scalar
.
int32
()
c_add
=
Test
OpEnumList
(
'+'
)(
a
,
b
)
c_add
=
My
OpEnumList
(
'+'
)(
a
,
b
)
c_sub
=
Test
OpEnumList
(
'-'
)(
a
,
b
)
c_sub
=
My
OpEnumList
(
'-'
)(
a
,
b
)
c_multiply
=
Test
OpEnumList
(
'*'
)(
a
,
b
)
c_multiply
=
My
OpEnumList
(
'*'
)(
a
,
b
)
c_divide
=
Test
OpEnumList
(
'/'
)(
a
,
b
)
c_divide
=
My
OpEnumList
(
'/'
)(
a
,
b
)
f
=
theano
.
function
([
a
,
b
],
[
c_add
,
c_sub
,
c_multiply
,
c_divide
])
f
=
theano
.
function
([
a
,
b
],
[
c_add
,
c_sub
,
c_multiply
,
c_divide
])
va
=
12
va
=
12
vb
=
15
vb
=
15
...
@@ -233,11 +232,10 @@ def test_op_with_enumlist():
...
@@ -233,11 +232,10 @@ def test_op_with_enumlist():
out
=
f
(
va
,
vb
)
out
=
f
(
va
,
vb
)
assert
ref
==
out
,
(
ref
,
out
)
assert
ref
==
out
,
(
ref
,
out
)
def
test_op_with_cenumtype
(
self
):
def
test_op_with_cenumtype
():
sizeof_int
=
MyOpCEnumType
(
'int'
)()
sizeof_int
=
TestOpCEnumType
(
'int'
)()
sizeof_float
=
MyOpCEnumType
(
'float'
)()
sizeof_float
=
TestOpCEnumType
(
'float'
)()
sizeof_long_long
=
MyOpCEnumType
(
'long long'
)()
sizeof_long_long
=
TestOpCEnumType
(
'long long'
)()
f
=
theano
.
function
([],
[
sizeof_int
,
sizeof_float
,
sizeof_long_long
])
f
=
theano
.
function
([],
[
sizeof_int
,
sizeof_float
,
sizeof_long_long
])
out
=
f
()
out
=
f
()
print
(
'(sizeof(int): '
,
out
[
0
],
', sizeof(float): '
,
out
[
1
],
', sizeof(long long): '
,
out
[
2
],
') '
,
sep
=
''
)
print
(
'(sizeof(int): '
,
out
[
0
],
', sizeof(float): '
,
out
[
1
],
', sizeof(long long): '
,
out
[
2
],
') '
,
sep
=
''
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论