Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5147d5fc
提交
5147d5fc
authored
3月 04, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code in cc.py
上级
834c5aa3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
69 行增加
和
25 行删除
+69
-25
cc.py
gof/cc.py
+68
-0
result.py
gof/result.py
+0
-24
scalar_ops.py
scalar_ops.py
+1
-1
没有找到文件。
gof/cc.py
浏览文件 @
5147d5fc
from
link
import
Linker
from
link
import
Linker
from
copy
import
copy
class
CodeBlock
:
def
__init__
(
self
,
declare
,
behavior
,
cleanup
,
sub
):
self
.
declare
=
declare
%
sub
behavior_sub
=
copy
(
sub
)
behavior_sub
[
'fail'
]
=
"{goto __label_
%(id)
i}"
%
sub
self
.
behavior
=
behavior
%
behavior_sub
self
.
cleanup
=
(
"__label_
%(id)
i:
\n
"
+
cleanup
)
%
sub
def
code_gen
(
blocks
):
decl
=
""
head
=
""
tail
=
""
for
block
in
blocks
:
decl
+=
block
.
declare
head
=
head
+
(
"
\n
{
\n
%
s"
%
block
.
behavior
)
tail
=
(
"
%
s
\n
}
\n
"
%
block
.
cleanup
)
+
tail
return
decl
+
head
+
tail
def
struct_gen
(
args
,
struct_builders
,
blocks
,
sub
):
struct_decl
=
""
struct_init_head
=
""
struct_init_tail
=
""
struct_cleanup
=
""
for
block
in
blocks
:
struct_decl
+=
block
.
declare
struct_init_head
=
struct_init_head
+
(
"
\n
{
\n
%
s"
%
block
.
behavior
)
struct_init_tail
=
(
"
%
s
\n
}
\n
"
%
block
.
cleanup
)
+
struct_init_tail
struct_cleanup
+=
block
.
cleanup
behavior
=
code_gen
(
blocks
)
args
=
", "
.
join
([
"PyObject*
%
s"
%
arg
for
arg
in
args
])
struct_code
=
"""
struct __struct_
%%(id)
s {
%(struct_decl)
s
__struct_
%%(id)
s(void) {}
~__struct_
%%(id)
s(void) {
cleanup();
}
void init(
%(args)
s) {
%(struct_init_head)
s
return;
%(struct_init_tail)
s
}
void cleanup(void) {
%(struct_cleanup)
s
}
void run(void) {
%(behavior)
s
}
};
"""
%
locals
()
return
struct_code
class
CLinker
(
Linker
):
class
CLinker
(
Linker
):
...
@@ -7,6 +72,9 @@ class CLinker(Linker):
...
@@ -7,6 +72,9 @@ class CLinker(Linker):
def
__init__
(
self
,
env
):
def
__init__
(
self
,
env
):
self
.
env
=
env
self
.
env
=
env
def
extract_sync
(
self
,
to_extract
,
to_sync
,
to_cleanup
):
pass
def
code_gen
(
self
):
def
code_gen
(
self
):
env
=
self
.
env
env
=
self
.
env
order
=
env
.
toposort
()
order
=
env
.
toposort
()
...
...
gof/result.py
浏览文件 @
5147d5fc
...
@@ -145,30 +145,6 @@ class ResultBase(object):
...
@@ -145,30 +145,6 @@ class ResultBase(object):
raise
AbstractFunctionError
()
raise
AbstractFunctionError
()
# #
# # alloc
# #
# def alloc(self):
# """Create self.data from data_alloc, and set state to Allocated
# Graph routines like the linker will ask Ops to allocate outputs. The
# Ops, in turn, usually call this function. Results that are involved in
# destroy maps and view maps are exceptions to the usual case.
# """
# self.data = self.data_alloc() #might raise exception
# self.state = Allocated
# def data_alloc(self):
# """(abstract) Return an appropriate _data based on self.
# If a subclass overrides this function, then that overriding
# implementation will be used in alloc() to produce a data object.
# """
# raise AbstractFunctionError()
#
#
# C code generators
# C code generators
#
#
...
...
scalar_ops.py
浏览文件 @
5147d5fc
...
@@ -23,7 +23,7 @@ class Mul(BinaryScalarOp):
...
@@ -23,7 +23,7 @@ class Mul(BinaryScalarOp):
def
impl
(
self
,
x
,
y
):
def
impl
(
self
,
x
,
y
):
return
x
*
y
return
x
*
y
def
c_impl
(
self
,
(
x
,
y
),
z
):
def
c_impl
(
self
,
(
x
,
y
),
z
):
return
"
%(z)
s =
%(x)
s
*
%(y)
s;"
return
"
%(z)
s =
%(x)
s
+
%(y)
s;"
def
grad
(
self
,
(
x
,
y
),
gz
):
def
grad
(
self
,
(
x
,
y
),
gz
):
return
mul
(
y
,
gz
),
mul
(
x
,
gz
)
return
mul
(
y
,
gz
),
mul
(
x
,
gz
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论