提交 5e536853 authored 作者: abergeron's avatar abergeron

Merge pull request #3299 from harlouci/numpydoc_gof

Numpydoc gof
""" """
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
......
差异被折叠。
差异被折叠。
...@@ -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):
......
...@@ -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.
......
...@@ -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"
......
差异被折叠。
差异被折叠。
差异被折叠。
...@@ -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):
......
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论