提交 9d0f6f8b authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Better use of @memoize to avoid caching config flag

Now, theano.config.blas.ldflags will be read each time. Also cache the result of equivalent calls when specifying default values explicitly.
上级 fae5d713
......@@ -529,20 +529,59 @@ ger = Ger(destructive=False)
ger_destructive = Ger(destructive=True)
@utils.memoize
def ldflags(libs=True, flags=False, libs_dir=False, include_dir=False):
"""Return a list of libraries against which an Op's object file should be
linked to benefit from a BLAS implementation.
"""Extract a list of compilation flags from config.blas.ldflags.
Depending on the options, different type of flags will be kept.
It returns a list of libraries against which an Op's object file
should be linked to benefit from a BLAS implementation.
:type libs: bool, defaults to True
:param libs: extract flags starting with "-l"
:type libs_dir: bool, defaults to False
:param libs_dir: extract flags starting with "-L"
:type include_dir: bool, defaults to False
:param include_dir: extract flags starting with "-I"
:type flags: bool, defaults to False
:param flags: extract all the other flags
:rtype: list of strings
:returns: extracted flags
"""
ldflags_str = theano.config.blas.ldflags
return _ldflags(ldflags_str=ldflags_str,
libs=libs,
flags=flags,
libs_dir=libs_dir,
include_dir=include_dir)
Default: ['blas'], but configuration variable config.blas.ldflags
overrides this.
@utils.memoize
def _ldflags(ldflags_str, libs, flags, libs_dir, include_dir):
"""Extract list of compilation flags from a string.
Depending on the options, different type of flags will be kept.
:type ldflags_str: string
:param ldflags_str: the string to process. Typically, this will
be the content of `theano.config.blas.ldflags`
:type libs: bool
:param libs: extract flags starting with "-l"
:type libs_dir: bool
:param libs_dir: extract flags starting with "-L"
:type include_dir: bool
:param include_dir: extract flags starting with "-I"
:type flags: bool
:param flags: extract all the other flags
:rtype: list of strings
:returns: extracted flags
"""
rval = []
if libs_dir:
found_dyn = False
dirs = [x[2:] for x in config.blas.ldflags.split()
dirs = [x[2:] for x in ldflags_str.split()
if x.startswith('-L')]
l = ldflags()
l = _ldflags(ldflags_str=ldflags_str, libs=True,
flags=False, libs_dir=False, include_dir=False)
for d in dirs:
for f in os.listdir(d):
if (f.endswith('.so') or f.endswith('.dylib') or
......@@ -554,7 +593,7 @@ def ldflags(libs=True, flags=False, libs_dir=False, include_dir=False):
"library_dir of the library we use for blas. If you use "
"ATLAS, make sure to compile it with dynamics library.")
for t in config.blas.ldflags.split():
for t in ldflags_str.split():
# Remove extra quote.
if t.startswith("'") or t.startswith('"'):
t = t[1:]
......@@ -565,7 +604,8 @@ def ldflags(libs=True, flags=False, libs_dir=False, include_dir=False):
t0, t1, t2 = t[0:3]
assert t0 == '-'
except Exception:
raise ValueError('invalid token in config.blas.ldflags', t)
raise ValueError('invalid token "%s" in ldflags_str: "%s"'
% (t, ldflags_str))
if libs_dir and t1 == 'L':
rval.append(t[2:])
elif include_dir and t1 == 'I':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论