Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
23d7f12f
提交
23d7f12f
authored
9月 13, 2017
作者:
notoraptor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix unit tests for CEnumType.
上级
82284b21
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
31 行增加
和
11 行删除
+31
-11
test_cenum.h
theano/gof/tests/c_code/test_cenum.h
+17
-0
test_types.py
theano/gof/tests/test_types.py
+13
-10
type.py
theano/gof/type.py
+1
-1
没有找到文件。
theano/gof/tests/c_code/test_cenum.h
0 → 100644
浏览文件 @
23d7f12f
#ifndef THEANO_TEST_CENUM
#define THEANO_TEST_CENUM
#define SIZE_INT 0
#define SIZE_FLOAT 1
#define SIZE_LONG_LONG 2
/* 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
theano/gof/tests/test_types.py
浏览文件 @
23d7f12f
from
__future__
import
absolute_import
,
print_function
,
division
import
os
import
numpy
as
np
import
theano
...
...
@@ -148,13 +149,11 @@ class MyOpCEnumType(Op):
__props__
=
(
'ctype_index'
,)
params_type
=
CEnumType
(
'SIZE_INT'
,
'SIZE_FLOAT'
,
'SIZE_LONG_LONG'
,
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
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
,
ctype
):
# As we see, Python values of constants are not related to real C values
...
...
@@ -174,14 +173,14 @@ class MyOpCEnumType(Op):
return
Apply
(
self
,
[],
[
scalar
.
uint32
()])
def
c_code_cache_version
(
self
):
return
(
1
,)
return
(
2
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
return
"""
%(o)
s =
%(sizeof_ctype)
s
;
%(o)
s =
type_sizes[
%(typecode)
s]
;
"""
%
dict
(
o
=
outputs
[
0
],
# params in C code will already contains expected C constant value.
sizeof_ctyp
e
=
sub
[
'params'
])
typecod
e
=
sub
[
'params'
])
class
TestEnumTypes
(
TestCase
):
...
...
@@ -260,3 +259,7 @@ class TestEnumTypes(TestCase):
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
=
''
)
@theano.change_flags
(
**
{
'cmodule.debug'
:
True
})
def
test_op_with_cenumtype_debug
(
self
):
self
.
test_op_with_cenumtype
()
theano/gof/type.py
浏览文件 @
23d7f12f
...
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论