Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b90abd33
提交
b90abd33
authored
9月 22, 2014
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a test for CDataType and fix a bug that was calling freefunc too often.
上级
4f1edd17
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
74 行增加
和
11 行删除
+74
-11
test_types.py
theano/gof/tests/test_types.py
+67
-1
type.py
theano/gof/type.py
+7
-10
没有找到文件。
theano/gof/tests/test_types.py
浏览文件 @
b90abd33
import
numpy
import
theano
from
theano.gof.type
import
*
from
theano
import
Op
,
Apply
from
theano.tensor
import
TensorType
from
theano.gof.type
import
CDataType
# todo: test generic
# todo: test generic
class
ProdOp
(
Op
):
__props__
=
()
def
make_node
(
self
,
i
):
return
Apply
(
self
,
[
i
],
[
CDataType
(
'void *'
,
'py_decref'
)()])
def
c_support_code
(
self
):
return
"""
void py_decref(void *p) {
Py_XDECREF((PyObject *)p);
}
"""
def
c_code
(
self
,
node
,
name
,
inps
,
outs
,
sub
):
return
"""
Py_XDECREF(
%(out)
s);
%(out)
s = (void *)
%(inp)
s;
Py_INCREF(
%(inp)
s);
"""
%
dict
(
out
=
outs
[
0
],
inp
=
inps
[
0
])
def
c_code_cache_version
(
self
):
return
(
0
,)
class
GetOp
(
Op
):
__props__
=
()
def
make_node
(
self
,
c
):
return
Apply
(
self
,
[
c
],
[
TensorType
(
'float32'
,
(
False
,))()])
def
c_support_code
(
self
):
return
"""
void py_decref(void *p) {
Py_XDECREF((PyObject *)p);
}
"""
def
c_code
(
self
,
node
,
name
,
inps
,
outs
,
sub
):
return
"""
Py_XDECREF(
%(out)
s);
%(out)
s = (PyArrayObject *)
%(inp)
s;
Py_INCREF(
%(out)
s);
"""
%
dict
(
out
=
outs
[
0
],
inp
=
inps
[
0
])
def
c_code_cache_version
(
self
):
return
(
0
,)
def
test_cdata
():
i
=
TensorType
(
'float32'
,
(
False
,))()
c
=
ProdOp
()(
i
)
i2
=
GetOp
()(
c
)
# This should be a passthrough function for vectors
f
=
theano
.
function
([
i
],
i2
)
v
=
numpy
.
random
.
randn
(
9
)
.
astype
(
'float32'
)
v2
=
f
(
v
)
assert
(
v2
==
v
)
.
all
()
theano/gof/type.py
浏览文件 @
b90abd33
...
@@ -530,13 +530,6 @@ class CDataType(Type):
...
@@ -530,13 +530,6 @@ class CDataType(Type):
"""
"""
return
s
%
dict
(
name
=
name
,
ctype
=
self
.
ctype
,
fail
=
sub
[
'fail'
])
return
s
%
dict
(
name
=
name
,
ctype
=
self
.
ctype
,
fail
=
sub
[
'fail'
])
def
c_cleanup
(
self
,
name
,
sub
):
if
self
.
freefunc
is
not
None
:
return
"
%(freefunc)
s(
%(name)
s);"
%
dict
(
freefunc
=
self
.
freefunc
,
name
=
name
)
else
:
return
""
def
c_sync
(
self
,
name
,
sub
):
def
c_sync
(
self
,
name
,
sub
):
freefunc
=
self
.
freefunc
freefunc
=
self
.
freefunc
if
freefunc
is
None
:
if
freefunc
is
None
:
...
@@ -554,16 +547,20 @@ if (%(name)s == NULL) {
...
@@ -554,16 +547,20 @@ if (%(name)s == NULL) {
}"""
}"""
else
:
else
:
s
+=
"""{
s
+=
"""{
py_
%(name)
s = PyCObject_FromVoidPtr((void *)
%(name)
s,
py_
%(name)
s = PyCObject_FromVoidPtr((void *)
%(name)
s,
(void (*)(void *))
%(freefunc)
s);
(void (*)(void *))
%(freefunc)
s);
}"""
}"""
if
self
.
freefunc
is
not
None
:
s
+=
"""
s
+=
"""
if (py_
%(name)
s
!= NULL) {
%(name)
s = NULL
; }
if (py_
%(name)
s
== NULL) {
%(freefunc)
s(
%(name)
s)
; }
"""
"""
return
s
%
dict
(
name
=
name
,
freefunc
=
freefunc
)
return
s
%
dict
(
name
=
name
,
freefunc
=
freefunc
)
def
c_cleanup
(
self
,
name
,
sub
):
return
""
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
0
,)
return
(
1
,)
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
self
.
ctype
)
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
self
.
ctype
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论