Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
58a674a3
提交
58a674a3
authored
1月 26, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
yeaaaaaa
上级
57c452cf
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
62 行增加
和
56 行删除
+62
-56
.hgignore
.hgignore
+1
-0
compile.py
compile.py
+11
-10
core.py
core.py
+0
-0
lib.py
gof/lib.py
+1
-1
type_spec.py
type_spec.py
+49
-45
没有找到文件。
.hgignore
浏览文件 @
58a674a3
...
...
@@ -5,3 +5,4 @@ syntax: glob
*.so
*~
\#*\#
compiled/*.cpp
compile.py
浏览文件 @
58a674a3
...
...
@@ -10,34 +10,35 @@ from copy import copy
def
experimental_linker
(
env
,
target
=
None
):
def
fetch
(
op
):
try
:
thunk
=
op
.
c_thunk_creator
()
factory
=
op
.
c_thunk_factory
()
# print "yea %s" % op
return
lambda
:
cutils
.
run_cthunk
(
thunk
())
thunk
=
factory
()
return
lambda
:
cutils
.
run_cthunk
(
thunk
)
except
NotImplementedError
:
# print "nope %s" % op
return
op
.
_perform
order
=
env
.
toposort
()
for
op
in
order
:
op
.
refresh
()
# for op in order:
# print op
# print 'ispecs: ', [input.spec for input in op.inputs]
# print 'ospecs: ', [output.spec for output in op.outputs]
#
for op in order:
#
print op
#
print 'ispecs: ', [input.spec for input in op.inputs]
#
print 'ospecs: ', [output.spec for output in op.outputs]
thunks
=
[
fetch
(
op
)
for
op
in
order
]
def
ret
():
for
thunk
,
op
in
zip
(
thunks
,
order
):
# print "=================================================="
# for thunk, op in zip(thunks, order):
# print op
# print 'in: ', [id(input.data) for input in op.inputs]
# print 'out:', [id(output.data) for output in op.outputs]
thunk
()
# for thunk in thunks:
# thunk()
for
thunk
in
thunks
:
thunk
()
if
not
target
:
return
ret
else
:
raise
NotImplementedError
(
"Cannot write thunk representation to a file."
)
class
profile_linker
:
def
__init__
(
self
,
env
):
self
.
order
=
env
.
toposort
()
...
...
core.py
浏览文件 @
58a674a3
差异被折叠。
点击展开。
gof/lib.py
浏览文件 @
58a674a3
...
...
@@ -85,7 +85,7 @@ class PythonR(Result):
__slots__
=
[
'data'
,
'spec'
,
'constant'
,
'up_to_date'
]
def
__init__
(
self
,
x
=
None
,
constant
=
False
):
def
__init__
(
self
,
x
=
UNCOMPUTED
,
constant
=
False
):
self
.
constant
=
False
self
.
set_value
(
x
)
self
.
constant
=
constant
...
...
type_spec.py
浏览文件 @
58a674a3
...
...
@@ -4,21 +4,21 @@ from scipy.weave import c_spec, standard_array_spec
class
omega_type_converter_extension
:
def
provides
(
self
):
"""
Returns a list of (c_type, name, init_code) tuples that represent variables
the type converter provides to the user's code.
"""
tvars
=
self
.
template_vars
()
return
[(
tvars
[
'c_type'
],
tvars
[
'name'
],
tvars
[
'var_convert'
])]
# def provides(self):
# """
# Returns a list of (c_type, name, init_code) tuples that represent variables
# the type converter provides to the user's code.
# """
# return []
# def format_provide(self, x):
# return '%s %s = %s;\n' % x
def
format_provide
(
self
,
x
):
return
'
%
s
%
s =
%
s;
\n
'
%
x
def
declaration_code
(
self
,
templatize
=
0
,
inline
=
0
):
tvars
=
self
.
template_vars
(
inline
=
inline
)
code
=
'
%(py_var)
s =
%(var_lookup)
s;
\n
'
%
tvars
code
+=
'
'
.
join
([
self
.
format_provide
(
export
)
for
export
in
self
.
provides
()])
code
+=
'
%(c_type)
s
%(name)
s =
%(var_convert)
s;
\n
'
%
tvars
return
code
def
struct_init_code
(
self
):
...
...
@@ -28,18 +28,21 @@ class omega_type_converter_extension:
return
"Py_DECREF(py_
%
s);"
%
self
.
name
def
struct_members_code
(
self
):
tvars
=
self
.
template_vars
()
res
=
"PyObject* py_
%
s;
\n
"
%
self
.
name
return
res
+
''
.
join
([
'
%
s_type
%
s;
\n
'
%
(
name
,
name
)
for
c_type
,
name
,
init
in
self
.
provides
()])
res
+=
"
%(c_type)
s
%(name)
s;
\n
"
%
tvars
return
res
def
struct_import_code
(
self
):
res
=
"__STRUCT_P->py_
%
s = py_
%
s;
\n
"
%
(
self
.
name
,
self
.
name
)
return
res
+
''
.
join
([
'__STRUCT_P->
%
s =
%
s;
\n
'
%
(
name
,
name
)
for
c_type
,
name
,
init
in
self
.
provides
()])
res
+=
"__STRUCT_P->
%
s =
%
s;
\n
"
%
(
self
.
name
,
self
.
name
)
return
res
def
struct_support_code
(
self
):
return
""
def
struct_typedefs
(
self
):
return
''
.
join
([
"typedef
%
s
%
s_type;
\n
"
%
(
c_type
,
name
)
for
c_type
,
name
,
init
in
self
.
provides
()])
return
""
class
int_converter
(
omega_type_converter_extension
,
c_spec
.
int_converter
):
...
...
@@ -52,9 +55,10 @@ class complex_converter(omega_type_converter_extension, c_spec.complex_converter
pass
class
unicode_converter
(
omega_type_converter_extension
,
c_spec
.
unicode_converter
):
def
provides
(
self
):
tvars
=
self
.
template_vars
()
return
omega_type_converter_extension
.
provides
()
+
[(
'int'
,
'N
%(name)
s'
%
tvars
,
'PyUnicode_GET_SIZE(
%(py_var)
s)'
%
tvars
)]
pass
# def provides(self):
# tvars = self.template_vars()
# return omega_type_converter_extension.provides() + [('int', 'N%(name)s' % tvars, 'PyUnicode_GET_SIZE(%(py_var)s)' % tvars)]
class
string_converter
(
omega_type_converter_extension
,
c_spec
.
string_converter
):
pass
...
...
@@ -75,39 +79,39 @@ class instance_converter(omega_type_converter_extension, c_spec.instance_convert
pass
class
array_converter
(
omega_type_converter_extension
,
standard_array_spec
.
array_converter
):
def
provides
(
self
):
tvars
=
self
.
template_vars
()
ret
=
[]
ret
.
append
((
tvars
[
'c_type'
],
tvars
[
'array_name'
],
tvars
[
'var_convert'
]))
ret
.
append
((
'npy_intp*'
,
'N
%(name)
s'
%
tvars
,
'
%(array_name)
s->dimensions'
%
tvars
))
ret
.
append
((
'npy_intp*'
,
'S
%(name)
s'
%
tvars
,
'
%(array_name)
s->strides'
%
tvars
))
ret
.
append
((
'int'
,
'D
%(name)
s'
%
tvars
,
'
%(array_name)
s->nd'
%
tvars
))
ret
.
append
((
'
%(num_type)
s*'
%
tvars
,
'
%(name)
s'
%
tvars
,
'(
%(num_type)
s*)
%(array_name)
s->data'
%
tvars
))
return
ret
def
declaration_code
(
self
,
templatize
=
0
,
inline
=
0
):
tvars
=
self
.
template_vars
(
inline
=
inline
)
tvars
[
'cap_name'
]
=
self
.
name
.
upper
()
prov
=
self
.
provides
()
code
=
'
%(py_var)
s =
%(var_lookup)
s;
\n
'
%
tvars
code
+=
"
\n
"
.
join
(
self
.
format_provide
(
export
)
for
export
in
prov
[:
1
])
code
+=
'
\n
conversion_numpy_check_type(
%(array_name)
s,
%(num_typecode)
s,"
%(name)
s");
\n
'
%
tvars
code
+=
"
\n
"
.
join
(
self
.
format_provide
(
export
)
for
export
in
prov
[
1
:])
return
code
#
def provides(self):
#
tvars = self.template_vars()
#
ret = []
#
ret.append((tvars['c_type'], tvars['array_name'], tvars['var_convert']))
#
ret.append(('npy_intp*', 'N%(name)s' % tvars, '%(array_name)s->dimensions' % tvars))
#
ret.append(('npy_intp*', 'S%(name)s' % tvars, '%(array_name)s->strides' % tvars))
#
ret.append(('int', 'D%(name)s' % tvars, '%(array_name)s->nd' % tvars))
#
ret.append(('%(num_type)s*' % tvars, '%(name)s' % tvars, '(%(num_type)s*) %(array_name)s->data' % tvars))
#
return ret
#
def declaration_code(self, templatize = 0, inline = 0):
#
tvars = self.template_vars(inline=inline)
#
tvars['cap_name'] = self.name.upper()
#
prov = self.provides()
#
code = '%(py_var)s = %(var_lookup)s;\n' % tvars
#
code += "\n".join(self.format_provide(export) for export in prov[:1])
#
code += '\nconversion_numpy_check_type(%(array_name)s,%(num_typecode)s,"%(name)s");\n' % tvars
#
code += "\n".join(self.format_provide(export) for export in prov[1:])
#
return code
def
struct_support_code
(
self
,
templatize
=
0
,
inline
=
0
):
tvars
=
self
.
template_vars
(
inline
=
inline
)
cap_name
=
self
.
name
.
upper
()
tvars
[
'cap_name'
]
=
cap_name
code
=
'inline
%(num_type)
s&
%(cap_name)
s1(int i) { return (*((
%(num_type)
s*)(
%(array_name)
s->data + (i)*S
%(name)
s[0])));}
\n
'
\
'inline
%(num_type)
s&
%(cap_name)
s2(int i, int j) { return (*((
%(num_type)
s*)(
%(array_name)
s->data + (i)*S
%(name)
s[0] + (j)*S
%(name)
s[1])));}
\n
'
\
'inline
%(num_type)
s&
%(cap_name)
s3(int i, int j, int k) { return (*((
%(num_type)
s*)(
%(array_name)
s->data + (i)*S
%(name)
s[0] + (j)*S
%(name)
s[1] + (k)*S
%(name)
s[2])));}
\n
'
\
'inline
%(num_type)
s&
%(cap_name)
s4(int i, int j, int k, int l) { return (*((
%(num_type)
s*)(
%(array_name)
s->data + (i)*S
%(name)
s[0] + (j)*S
%(name)
s[1] + (k)*S
%(name)
s[2] + (l)*S
%(name)
s[3])));}
\n
'
return
code
%
tvars
#
def struct_support_code(self, templatize = 0, inline = 0):
#
tvars = self.template_vars(inline=inline)
#
cap_name = self.name.upper()
#
tvars['cap_name'] = cap_name
#
code = 'inline %(num_type)s& %(cap_name)s1(int i) { return (*((%(num_type)s*)(%(array_name)s->data + (i)*S%(name)s[0])));}\n' \
#
'inline %(num_type)s& %(cap_name)s2(int i, int j) { return (*((%(num_type)s*)(%(array_name)s->data + (i)*S%(name)s[0] + (j)*S%(name)s[1])));}\n' \
#
'inline %(num_type)s& %(cap_name)s3(int i, int j, int k) { return (*((%(num_type)s*)(%(array_name)s->data + (i)*S%(name)s[0] + (j)*S%(name)s[1] + (k)*S%(name)s[2])));}\n' \
#
'inline %(num_type)s& %(cap_name)s4(int i, int j, int k, int l) { return (*((%(num_type)s*)(%(array_name)s->data + (i)*S%(name)s[0] + (j)*S%(name)s[1] + (k)*S%(name)s[2] + (l)*S%(name)s[3])));}\n'
#
return code % tvars
def
struct_typedefs
(
self
):
tvars
=
self
.
template_vars
()
return
omega_type_converter_extension
.
struct_typedefs
(
self
)
+
"
\n
"
+
"typedef
%(num_type)
s
%(name)
s_dtype;
"
%
tvars
return
"typedef
%(num_type)
s
%(name)
s_dtype;
\n
"
%
tvars
# return "\n".join(["typedef %s %s_type;" % (c_type, name)])
# def struct_template_types(self):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论