Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f881f23c
提交
f881f23c
authored
9月 14, 2017
作者:
Frédéric Bastien
提交者:
GitHub
9月 14, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6410 from notoraptor/fix-cenumtype-test
Fix unit tests for CEnumType.
上级
b602f833
37566d42
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
42 行增加
和
31 行删除
+42
-31
test_cenum.h
theano/gof/tests/c_code/test_cenum.h
+8
-0
test_types.py
theano/gof/tests/test_types.py
+33
-30
type.py
theano/gof/type.py
+1
-1
没有找到文件。
theano/gof/tests/c_code/test_cenum.h
0 → 100644
浏览文件 @
f881f23c
#ifndef THEANO_TEST_CENUM
#define THEANO_TEST_CENUM
#define MILLION 1000000
#define BILLION 1000000000
#define TWO_BILLIONS 2000000000
#endif
theano/gof/tests/test_types.py
浏览文件 @
f881f23c
from
__future__
import
absolute_import
,
print_function
,
division
import
os
import
numpy
as
np
import
theano
...
...
@@ -145,43 +146,39 @@ class MyOpEnumList(Op):
class
MyOpCEnumType
(
Op
):
__props__
=
(
'ctype_index'
,)
params_type
=
CEnumType
(
'SIZE_INT'
,
'SIZE_FLOAT'
,
'SIZE_LONG_LONG'
,
ctype
=
'size_t'
)
__props__
=
(
'python_value'
,)
params_type
=
CEnumType
((
'MILLION'
,
'million'
),
(
'BILLION'
,
'billion'
),
(
'TWO_BILLIONS'
,
'two_billions'
),
ctype
=
'size_t'
)
# Just for testing, we define our own macros.
def
c_support_code
(
self
):
return
"""
#define SIZE_INT sizeof(int)
#define SIZE_FLOAT sizeof(float)
#define SIZE_LONG_LONG sizeof(long long)
"""
def
__init__
(
self
,
ctype
):
# As we see, Python values of constants are not related to real C values
# (sizeof(int) will never be 0).
assert
self
.
params_type
.
SIZE_INT
==
0
assert
self
.
params_type
.
SIZE_FLOAT
==
1
assert
self
.
params_type
.
SIZE_LONG_LONG
==
2
d
=
{
'int'
:
self
.
params_type
.
SIZE_INT
,
'float'
:
self
.
params_type
.
SIZE_FLOAT
,
'long long'
:
self
.
params_type
.
SIZE_LONG_LONG
}
self
.
ctype_index
=
d
[
ctype
]
def
c_header_dirs
(
self
):
return
[
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'c_code'
)]
def
c_headers
(
self
):
return
[
'test_cenum.h'
]
def
__init__
(
self
,
value_name
):
# As we see, Python values of constants are not related to real C values.
assert
self
.
params_type
.
MILLION
==
0
assert
self
.
params_type
.
BILLION
==
1
assert
self
.
params_type
.
TWO_BILLIONS
==
2
assert
self
.
params_type
.
has_alias
(
value_name
)
self
.
python_value
=
self
.
params_type
.
fromalias
(
value_name
)
def
get_params
(
self
,
node
):
return
self
.
ctype_index
return
self
.
python_value
def
make_node
(
self
):
return
Apply
(
self
,
[],
[
scalar
.
uint32
()])
def
c_code_cache_version
(
self
):
return
(
1
,)
return
(
3
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
return
"""
%(o)
s =
%(
sizeof_ctype
)
s;
%(o)
s =
%(
val
)
s;
"""
%
dict
(
o
=
outputs
[
0
],
# params in C code will already contains expected C constant value.
sizeof_ctype
=
sub
[
'params'
])
val
=
sub
[
'params'
])
class
TestEnumTypes
(
TestCase
):
...
...
@@ -254,9 +251,15 @@ class TestEnumTypes(TestCase):
def
test_op_with_cenumtype
(
self
):
if
theano
.
config
.
cxx
==
''
:
raise
SkipTest
(
'need c++'
)
sizeof_int
=
MyOpCEnumType
(
'int'
)()
sizeof_float
=
MyOpCEnumType
(
'float'
)()
sizeof_long_long
=
MyOpCEnumType
(
'long long'
)()
f
=
theano
.
function
([],
[
sizeof_int
,
sizeof_float
,
sizeof_long_long
])
out
=
f
()
print
(
'(sizeof(int): '
,
out
[
0
],
', sizeof(float): '
,
out
[
1
],
', sizeof(long long): '
,
out
[
2
],
') '
,
sep
=
''
)
million
=
MyOpCEnumType
(
'million'
)()
billion
=
MyOpCEnumType
(
'billion'
)()
two_billions
=
MyOpCEnumType
(
'two_billions'
)()
f
=
theano
.
function
([],
[
million
,
billion
,
two_billions
])
val_million
,
val_billion
,
val_two_billions
=
f
()
assert
val_million
==
1000000
assert
val_billion
==
val_million
*
1000
assert
val_two_billions
==
val_billion
*
2
@theano.change_flags
(
**
{
'cmodule.debug'
:
True
})
def
test_op_with_cenumtype_debug
(
self
):
self
.
test_op_with_cenumtype
()
theano/gof/type.py
浏览文件 @
f881f23c
...
...
@@ -1211,7 +1211,7 @@ class CEnumType(EnumList):
Like :class:`EnumList`, you can also add an alias to a constant, with same syntax as in :class:`EnumList`.
See test
class :class:`theano.gof.tests.test_types.TestOpCEnumT
ype` for a working example.
See test
:func:`theano.gof.tests.test_types.TestEnumTypes.test_op_with_cenumt
ype` for a working example.
.. note::
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论