Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5e536853
提交
5e536853
authored
8月 19, 2015
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3299 from harlouci/numpydoc_gof
Numpydoc gof
上级
8aaf5a5f
65febf36
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
20 个修改的文件
包含
65 行增加
和
42 行删除
+65
-42
__init__.py
theano/gof/__init__.py
+7
-7
cc.py
theano/gof/cc.py
+0
-0
cmodule.py
theano/gof/cmodule.py
+0
-0
compiledir.py
theano/gof/compiledir.py
+11
-8
compilelock.py
theano/gof/compilelock.py
+36
-21
cutils.py
theano/gof/cutils.py
+4
-1
destroyhandler.py
theano/gof/destroyhandler.py
+0
-0
fg.py
theano/gof/fg.py
+0
-0
graph.py
theano/gof/graph.py
+0
-0
link.py
theano/gof/link.py
+0
-0
null_type.py
theano/gof/null_type.py
+7
-5
op.py
theano/gof/op.py
+0
-0
opt.py
theano/gof/opt.py
+0
-0
optdb.py
theano/gof/optdb.py
+0
-0
sched.py
theano/gof/sched.py
+0
-0
toolbox.py
theano/gof/toolbox.py
+0
-0
type.py
theano/gof/type.py
+0
-0
unify.py
theano/gof/unify.py
+0
-0
utils.py
theano/gof/utils.py
+0
-0
vm.py
theano/gof/vm.py
+0
-0
没有找到文件。
theano/gof/__init__.py
浏览文件 @
5e536853
"""
"""
gof.py
gof.py
gof stands for Graph Optimization Framework
gof stands for Graph Optimization Framework
.
The gof submodule of theano implements a framework
The gof submodule of theano implements a framework
for manipulating programs described as graphs. The
for manipulating programs described as graphs. The
...
@@ -9,13 +9,13 @@ gof module defines basic theano graph concepts:
...
@@ -9,13 +9,13 @@ gof module defines basic theano graph concepts:
-Apply nodes, which represent the application
-Apply nodes, which represent the application
of an Op to Variables. Together these make up a
of an Op to Variables. Together these make up a
graph.
graph.
-The Type, needed for Variables to make sense
-The Type, needed for Variables to make sense
.
-The FunctionGraph, which defines how a subgraph
-The FunctionGraph, which defines how a subgraph
should be interpreted to implement a function
should be interpreted to implement a function
.
-The Thunk, a callable object that becames part
-The Thunk, a callable object that becames part
of the executable emitted by theano
of the executable emitted by theano
.
-Linkers/VMs, the objects that call Thunks in
-Linkers/VMs, the objects that call Thunks in
sequence in order to execute a theano program
sequence in order to execute a theano program
.
Conceptually, gof is intended to be sufficiently abstract
Conceptually, gof is intended to be sufficiently abstract
that it could be used to implement a language other than
that it could be used to implement a language other than
...
@@ -32,9 +32,9 @@ functionality. Ideally this should be refactored into
...
@@ -32,9 +32,9 @@ functionality. Ideally this should be refactored into
a different submodule.
a different submodule.
For more details and discussion, see the theano-dev
For more details and discussion, see the theano-dev
e-mail thread "What is gof?"
e-mail thread "What is gof?".
"""
"""
from
theano.gof.cc
import
\
from
theano.gof.cc
import
\
CLinker
,
OpWiseCLinker
,
DualLinker
,
HideC
CLinker
,
OpWiseCLinker
,
DualLinker
,
HideC
...
...
theano/gof/cc.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/cmodule.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/compiledir.py
浏览文件 @
5e536853
...
@@ -32,10 +32,11 @@ except OSError:
...
@@ -32,10 +32,11 @@ except OSError:
def
local_bitwidth
():
def
local_bitwidth
():
"""
"""
Return 32 for 32bit arch, 64 for 64bit arch
Return 32 for 32bit arch, 64 for 64bit arch
.
By "architecture", we mean the size of memory pointers (size_t in C),
By "architecture", we mean the size of memory pointers (size_t in C),
*not* the size of long int, as it can be different.
*not* the size of long int, as it can be different.
"""
"""
# Note that according to Python documentation, `platform.architecture()` is
# Note that according to Python documentation, `platform.architecture()` is
# not reliable on OS X with universal binaries.
# not reliable on OS X with universal binaries.
...
@@ -49,6 +50,7 @@ def python_int_bitwidth():
...
@@ -49,6 +50,7 @@ def python_int_bitwidth():
Return the bit width of Python int (C long int).
Return the bit width of Python int (C long int).
Note that it can be different from the size of a memory pointer.
Note that it can be different from the size of a memory pointer.
"""
"""
# 'l' denotes a C long int, and the size is expressed in bytes.
# 'l' denotes a C long int, and the size is expressed in bytes.
return
struct
.
calcsize
(
'l'
)
*
8
return
struct
.
calcsize
(
'l'
)
*
8
...
@@ -67,7 +69,8 @@ compiledir_format_dict = {
...
@@ -67,7 +69,8 @@ compiledir_format_dict = {
def
short_platform
(
r
=
None
,
p
=
None
):
def
short_platform
(
r
=
None
,
p
=
None
):
"""Return a safe shorter version of platform.platform().
"""
Return a safe shorter version of platform.platform().
The old default Theano compiledir used platform.platform in
The old default Theano compiledir used platform.platform in
it. This use the platform.version() as a substring. This is too
it. This use the platform.version() as a substring. This is too
...
@@ -103,13 +106,11 @@ def short_platform(r=None, p=None):
...
@@ -103,13 +106,11 @@ def short_platform(r=None, p=None):
compiledir_Linux-2.6.32-220.7.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.7.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.4.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.4.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
We suppose the version are ``X.Y[.*]-(digit)*(anything)*``. We
We suppose the version are ``X.Y[.*]-(digit)*(anything)*``. We keep ``X.Y``
keep ``X.Y`` and don't keep less important digit in the part
and don't keep less important digit in the part before ``-`` and we remove
before ``-`` and we remove the leading digit after the first
the leading digit after the first ``-``.
``-``.
If the information don't fit that pattern, we do not modify
If the information don't fit that pattern, we do not modify platform.
platform.
"""
"""
if
r
is
None
:
if
r
is
None
:
...
@@ -214,6 +215,7 @@ def filter_compiledir(path):
...
@@ -214,6 +215,7 @@ def filter_compiledir(path):
def
get_home_dir
():
def
get_home_dir
():
"""
"""
Return location of the user's home directory.
Return location of the user's home directory.
"""
"""
home
=
os
.
getenv
(
'HOME'
)
home
=
os
.
getenv
(
'HOME'
)
if
home
is
None
:
if
home
is
None
:
...
@@ -269,6 +271,7 @@ def cleanup():
...
@@ -269,6 +271,7 @@ def cleanup():
3) They do not have a compile version string
3) They do not have a compile version string
If there is no key left for a compiled module, we delete the module.
If there is no key left for a compiled module, we delete the module.
"""
"""
compiledir
=
theano
.
config
.
compiledir
compiledir
=
theano
.
config
.
compiledir
for
directory
in
os
.
listdir
(
compiledir
):
for
directory
in
os
.
listdir
(
compiledir
):
...
...
theano/gof/compilelock.py
浏览文件 @
5e536853
...
@@ -47,6 +47,7 @@ hostname = socket.gethostname()
...
@@ -47,6 +47,7 @@ hostname = socket.gethostname()
def
force_unlock
():
def
force_unlock
():
"""
"""
Delete the compilation lock if someone else has it.
Delete the compilation lock if someone else has it.
"""
"""
get_lock
(
min_wait
=
0
,
max_wait
=
0.001
,
timeout
=
0
)
get_lock
(
min_wait
=
0
,
max_wait
=
0.001
,
timeout
=
0
)
release_lock
()
release_lock
()
...
@@ -67,10 +68,16 @@ def _get_lock(lock_dir=None, **kw):
...
@@ -67,10 +68,16 @@ def _get_lock(lock_dir=None, **kw):
"""
"""
Obtain lock on compilation directory.
Obtain lock on compilation directory.
:param kw: Additional arguments to be forwarded to the `lock` function when
Parameters
acquiring the lock.
----------
kw
Additional arguments to be forwarded to the `lock` function when
acquiring the lock.
Notes
-----
We can lock only on 1 directory at a time.
:note: We can lock only on 1 directory at a time.
"""
"""
if
lock_dir
is
None
:
if
lock_dir
is
None
:
lock_dir
=
os
.
path
.
join
(
config
.
compiledir
,
'lock_dir'
)
lock_dir
=
os
.
path
.
join
(
config
.
compiledir
,
'lock_dir'
)
...
@@ -125,6 +132,7 @@ get_lock = _get_lock
...
@@ -125,6 +132,7 @@ get_lock = _get_lock
def
release_lock
():
def
release_lock
():
"""
"""
Release lock on compilation directory.
Release lock on compilation directory.
"""
"""
get_lock
.
n_lock
-=
1
get_lock
.
n_lock
-=
1
assert
get_lock
.
n_lock
>=
0
assert
get_lock
.
n_lock
>=
0
...
@@ -140,8 +148,11 @@ def set_lock_status(use_lock):
...
@@ -140,8 +148,11 @@ def set_lock_status(use_lock):
by default). Disabling may make compilation slightly faster (but is not
by default). Disabling may make compilation slightly faster (but is not
recommended for parallel execution).
recommended for parallel execution).
:param use_lock: whether to use the compilation lock or not
Parameters
:type use_lock: bool
----------
use_lock : bool
Whether to use the compilation lock or not.
"""
"""
get_lock
.
lock_is_enabled
=
use_lock
get_lock
.
lock_is_enabled
=
use_lock
...
@@ -169,22 +180,22 @@ def lock(tmp_dir, timeout=notset, min_wait=None, max_wait=None, verbosity=1):
...
@@ -169,22 +180,22 @@ def lock(tmp_dir, timeout=notset, min_wait=None, max_wait=None, verbosity=1):
displayed each time we re-check for the presence of the lock. Otherwise it
displayed each time we re-check for the presence of the lock. Otherwise it
is displayed only when we notice the lock's owner has changed.
is displayed only when we notice the lock's owner has changed.
:param str tmp_dir: lock directory that will be created when
Parameters
acquiring the lock
----------
tmp_dir : str
:param timeout: time (in seconds) to wait before replacing an
Lock directory that will be created when acquiring the lock.
existing lock (default config 'compile.timeout')
timeout : int or None
:type timeout: int or None
Time (in seconds) to wait before replacing an existing lock (default
config 'compile.timeout').
:param int min_wait: minimum time (in seconds) to wait before
min_wait: int
trying again to get the lock
Minimum time (in seconds) to wait before trying again to get the lock
(default config 'compile.wait')
(default config 'compile.wait').
max_wait: int
Maximum time (in seconds) to wait before trying again to get the lock
(default 2 * min_wait).
verbosity : int
Amount of feedback displayed to screen (default 1).
:param int max_wait: maximum time (in seconds) to wait before
trying again to get the lock
(default 2 * min_wait)
:param int verbosity: amount of feedback displayed to screen (default 1)
"""
"""
if
min_wait
is
None
:
if
min_wait
is
None
:
min_wait
=
config
.
compile
.
wait
min_wait
=
config
.
compile
.
wait
...
@@ -321,6 +332,7 @@ def refresh_lock(lock_file):
...
@@ -321,6 +332,7 @@ def refresh_lock(lock_file):
"""
"""
'Refresh' an existing lock by re-writing the file containing the owner's
'Refresh' an existing lock by re-writing the file containing the owner's
unique id, using a new (randomly generated) id, which is also returned.
unique id, using a new (randomly generated) id, which is also returned.
"""
"""
unique_id
=
'
%
s_
%
s_
%
s'
%
(
unique_id
=
'
%
s_
%
s_
%
s'
%
(
os
.
getpid
(),
os
.
getpid
(),
...
@@ -348,19 +360,22 @@ class Unlocker(object):
...
@@ -348,19 +360,22 @@ class Unlocker(object):
Class wrapper around release mechanism so that the lock is automatically
Class wrapper around release mechanism so that the lock is automatically
released when the program exits (even when crashing or being interrupted),
released when the program exits (even when crashing or being interrupted),
using the __del__ class method.
using the __del__ class method.
"""
"""
def
__init__
(
self
,
tmp_dir
):
def
__init__
(
self
,
tmp_dir
):
self
.
tmp_dir
=
tmp_dir
self
.
tmp_dir
=
tmp_dir
def
unlock
(
self
,
force
=
False
):
def
unlock
(
self
,
force
=
False
):
"""Remove current lock.
"""
Remove current lock.
This function does not crash if it is unable to properly
This function does not crash if it is unable to properly
delete the lock file and directory. The reason is that it
delete the lock file and directory. The reason is that it
should be allowed for multiple jobs running in parallel to
should be allowed for multiple jobs running in parallel to
unlock the same directory at the same time (e.g. when reaching
unlock the same directory at the same time (e.g. when reaching
their timeout limit).
their timeout limit).
"""
"""
# If any error occurs, we assume this is because someone else tried to
# If any error occurs, we assume this is because someone else tried to
# unlock this directory at the same time.
# unlock this directory at the same time.
...
...
theano/gof/cutils.py
浏览文件 @
5e536853
...
@@ -194,7 +194,10 @@ fail:
...
@@ -194,7 +194,10 @@ fail:
def
compile_cutils
():
def
compile_cutils
():
"""Do just the compilation of cutils_ext"""
"""
Do just the compilation of cutils_ext.
"""
code
=
(
"""
code
=
(
"""
#include <Python.h>
#include <Python.h>
#include "numpy/arrayobject.h"
#include "numpy/arrayobject.h"
...
...
theano/gof/destroyhandler.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/fg.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/graph.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/link.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/null_type.py
浏览文件 @
5e536853
...
@@ -3,19 +3,21 @@ from theano.gof.type import Type
...
@@ -3,19 +3,21 @@ from theano.gof.type import Type
class
NullType
(
Type
):
class
NullType
(
Type
):
"""
"""
A type that allows no values.
A type that allows no values.
Used to represent expressions
Used to represent expressions
that are undefined, either because they do not exist mathematically
that are undefined, either because they do not exist mathematically
or because the code to generate the expression has not been
or because the code to generate the expression has not been
implemented yet.
implemented yet.
Parameters
----------
why_null : str
A string explaining why this variable can't take on any values.
"""
"""
def
__init__
(
self
,
why_null
=
'(no explanation given)'
):
def
__init__
(
self
,
why_null
=
'(no explanation given)'
):
"""
why_null: A string explaining why this variable
can't take on any values
"""
self
.
why_null
=
why_null
self
.
why_null
=
why_null
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
...
...
theano/gof/op.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/opt.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/optdb.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/sched.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/toolbox.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/type.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/unify.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/utils.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
theano/gof/vm.py
浏览文件 @
5e536853
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论