Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
37566d42
提交
37566d42
authored
9月 13, 2017
作者:
notoraptor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update CEnumType testing.
上级
23d7f12f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
25 行增加
和
34 行删除
+25
-34
test_cenum.h
theano/gof/tests/c_code/test_cenum.h
+3
-12
test_types.py
theano/gof/tests/test_types.py
+22
-22
没有找到文件。
theano/gof/tests/c_code/test_cenum.h
浏览文件 @
37566d42
#ifndef THEANO_TEST_CENUM
#ifndef THEANO_TEST_CENUM
#define THEANO_TEST_CENUM
#define THEANO_TEST_CENUM
#define SIZE_INT 0
#define MILLION 1000000
#define SIZE_FLOAT 1
#define BILLION 1000000000
#define SIZE_LONG_LONG 2
#define TWO_BILLIONS 2000000000
/* NB:
For this specific test, we can not directly use macros with corresponding values (e.g. `SIZEOF_INT == sizeof(int)`)
because different types may have same size (e.g. sizeof(int) and sizeof(float) will be 4 on most machines),
leading to compilation errors in debug mode (inside a switch loop, SIZE_INT and SIZE_FLOAT would have the same
value, so that it is impossible to distinguish them, for e.g. to print macro name).
*/
static
size_t
type_sizes
[]
=
{
sizeof
(
int
),
sizeof
(
float
),
sizeof
(
long
long
)};
#endif
#endif
theano/gof/tests/test_types.py
浏览文件 @
37566d42
...
@@ -146,8 +146,9 @@ class MyOpEnumList(Op):
...
@@ -146,8 +146,9 @@ class MyOpEnumList(Op):
class
MyOpCEnumType
(
Op
):
class
MyOpCEnumType
(
Op
):
__props__
=
(
'ctype_index'
,)
__props__
=
(
'python_value'
,)
params_type
=
CEnumType
(
'SIZE_INT'
,
'SIZE_FLOAT'
,
'SIZE_LONG_LONG'
,
ctype
=
'size_t'
)
params_type
=
CEnumType
((
'MILLION'
,
'million'
),
(
'BILLION'
,
'billion'
),
(
'TWO_BILLIONS'
,
'two_billions'
),
ctype
=
'size_t'
)
def
c_header_dirs
(
self
):
def
c_header_dirs
(
self
):
return
[
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'c_code'
)]
return
[
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'c_code'
)]
...
@@ -155,32 +156,29 @@ class MyOpCEnumType(Op):
...
@@ -155,32 +156,29 @@ class MyOpCEnumType(Op):
def
c_headers
(
self
):
def
c_headers
(
self
):
return
[
'test_cenum.h'
]
return
[
'test_cenum.h'
]
def
__init__
(
self
,
ctype
):
def
__init__
(
self
,
value_name
):
# As we see, Python values of constants are not related to real C values
# As we see, Python values of constants are not related to real C values.
# (sizeof(int) will never be 0).
assert
self
.
params_type
.
MILLION
==
0
assert
self
.
params_type
.
SIZE_INT
==
0
assert
self
.
params_type
.
BILLION
==
1
assert
self
.
params_type
.
SIZE_FLOAT
==
1
assert
self
.
params_type
.
TWO_BILLIONS
==
2
assert
self
.
params_type
.
SIZE_LONG_LONG
==
2
assert
self
.
params_type
.
has_alias
(
value_name
)
d
=
{
'int'
:
self
.
params_type
.
SIZE_INT
,
self
.
python_value
=
self
.
params_type
.
fromalias
(
value_name
)
'float'
:
self
.
params_type
.
SIZE_FLOAT
,
'long long'
:
self
.
params_type
.
SIZE_LONG_LONG
}
self
.
ctype_index
=
d
[
ctype
]
def
get_params
(
self
,
node
):
def
get_params
(
self
,
node
):
return
self
.
ctype_index
return
self
.
python_value
def
make_node
(
self
):
def
make_node
(
self
):
return
Apply
(
self
,
[],
[
scalar
.
uint32
()])
return
Apply
(
self
,
[],
[
scalar
.
uint32
()])
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
2
,)
return
(
3
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
return
"""
return
"""
%(o)
s =
type_sizes[
%(typecode)
s]
;
%(o)
s =
%(val)
s
;
"""
%
dict
(
o
=
outputs
[
0
],
"""
%
dict
(
o
=
outputs
[
0
],
# params in C code will already contains expected C constant value.
# params in C code will already contains expected C constant value.
typecode
=
sub
[
'params'
])
val
=
sub
[
'params'
])
class
TestEnumTypes
(
TestCase
):
class
TestEnumTypes
(
TestCase
):
...
@@ -253,12 +251,14 @@ class TestEnumTypes(TestCase):
...
@@ -253,12 +251,14 @@ class TestEnumTypes(TestCase):
def
test_op_with_cenumtype
(
self
):
def
test_op_with_cenumtype
(
self
):
if
theano
.
config
.
cxx
==
''
:
if
theano
.
config
.
cxx
==
''
:
raise
SkipTest
(
'need c++'
)
raise
SkipTest
(
'need c++'
)
sizeof_int
=
MyOpCEnumType
(
'int'
)()
million
=
MyOpCEnumType
(
'million'
)()
sizeof_float
=
MyOpCEnumType
(
'float'
)()
billion
=
MyOpCEnumType
(
'billion'
)()
sizeof_long_long
=
MyOpCEnumType
(
'long long'
)()
two_billions
=
MyOpCEnumType
(
'two_billions'
)()
f
=
theano
.
function
([],
[
sizeof_int
,
sizeof_float
,
sizeof_long_long
])
f
=
theano
.
function
([],
[
million
,
billion
,
two_billions
])
out
=
f
()
val_million
,
val_billion
,
val_two_billions
=
f
()
print
(
'(sizeof(int): '
,
out
[
0
],
', sizeof(float): '
,
out
[
1
],
', sizeof(long long): '
,
out
[
2
],
') '
,
sep
=
''
)
assert
val_million
==
1000000
assert
val_billion
==
val_million
*
1000
assert
val_two_billions
==
val_billion
*
2
@theano.change_flags
(
**
{
'cmodule.debug'
:
True
})
@theano.change_flags
(
**
{
'cmodule.debug'
:
True
})
def
test_op_with_cenumtype_debug
(
self
):
def
test_op_with_cenumtype_debug
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论