提交 5c576b65 authored 作者: lamblin's avatar lamblin

Merge pull request #420 from nouiz/mixed

Mixed
...@@ -39,27 +39,28 @@ def filter_compiledir(path): ...@@ -39,27 +39,28 @@ def filter_compiledir(path):
# 2. The path is stable w.r.t. e.g. symlinks (which makes it easier # 2. The path is stable w.r.t. e.g. symlinks (which makes it easier
# to re-use compiled modules). # to re-use compiled modules).
path = os.path.realpath(path) path = os.path.realpath(path)
valid = True if os.access(path, os.F_OK): # Do it exist?
if not os.access(path, os.R_OK | os.W_OK): if not os.access(path, os.R_OK | os.W_OK | os.X_OK):
# If it exist we need read, write and listing access
raise ValueError(
"compiledir '%s' exists but you don't have read, write"
" or listing permissions." % path)
else:
try: try:
os.makedirs(path, 0770) # read-write-execute for user and group os.makedirs(path, 0770) # read-write-execute for user and group
except OSError, e: except OSError, e:
# Maybe another parallel execution of theano was trying to create # Maybe another parallel execution of theano was trying to create
# the same directory at the same time. # the same directory at the same time.
if e.errno != errno.EEXIST: if e.errno != errno.EEXIST:
valid = False raise ValueError(
"Unable to create to create the compiledir directory"
" '%s'. Check the permissions." % path)
if valid: # PROBLEM: sometimes the initial approach based on
try: # os.system('touch') returned -1 for an unknown reason; the
# PROBLEM: sometimes the initial approach based on # alternate approach here worked in all cases... it was weird.
# os.system('touch') returned -1 for an unknown reason; the # No error should happen as we checked the permissions.
# alternate approach here worked in all cases... it was weird. open(os.path.join(path, '__init__.py'), 'w').close()
open(os.path.join(path, '__init__.py'), 'w').close()
except:
valid = False
if not valid:
raise ValueError('Invalid value for compiledir: %s' % path)
return path return path
...@@ -116,11 +117,9 @@ def print_compiledir_content(): ...@@ -116,11 +117,9 @@ def print_compiledir_content():
return [a] return [a]
compiledir = theano.config.compiledir compiledir = theano.config.compiledir
print "List compiled ops in this theano cache:", compiledir
print "sub directory/Op/Associated Type"
print
table = [] table = []
more_then_one_ops = 0
zeros_op = 0
for dir in os.listdir(compiledir): for dir in os.listdir(compiledir):
file = None file = None
try: try:
...@@ -129,16 +128,38 @@ def print_compiledir_content(): ...@@ -129,16 +128,38 @@ def print_compiledir_content():
keydata = cPickle.load(file) keydata = cPickle.load(file)
ops = list(set([x for x in flatten(keydata.keys) ops = list(set([x for x in flatten(keydata.keys)
if isinstance(x, theano.gof.Op)])) if isinstance(x, theano.gof.Op)]))
assert len(ops) == 1 if len(ops) == 0:
types = list(set([x for x in flatten(keydata.keys) zeros_op += 1
if isinstance(x, theano.gof.Type)])) elif len(ops) > 1:
table.append((dir, ops[0], types)) more_then_one_ops += 1
else:
types = list(set([x for x in flatten(keydata.keys)
if isinstance(x, theano.gof.Type)]))
table.append((dir, ops[0], types))
except IOError: except IOError:
pass pass
finally: finally:
if file is not None: if file is not None:
file.close() file.close()
print "List %d compiled individual op in this theano cache %s:" % (
len(table), compiledir)
print "sub directory/Op/a set of the different associated Theano type"
table = sorted(table, key=lambda t: str(t[1])) table = sorted(table, key=lambda t: str(t[1]))
table_op_class = {}
for dir, op, types in table: for dir, op, types in table:
print dir, op, types print dir, op, types
table_op_class.setdefault(op.__class__, 0)
table_op_class[op.__class__] += 1
print
print "List %d of individual compiled Op class and" % (len(table_op_class)),
print " the number of time it got compiled"
table_op_class = sorted(table_op_class.iteritems(), key=lambda t: t[1])
for op_class, nb in table_op_class:
print op_class, nb
print ("Skipped %d files that contained more then"
" 1 op (was compiled with the c linker)" % (more_then_one_ops))
print ("Skipped %d files that contained 0 op"
"(Are they always theano.scalar ops?)" % (
more_then_one_ops))
...@@ -720,6 +720,9 @@ dense_from_sparse = DenseFromSparse() ...@@ -720,6 +720,9 @@ dense_from_sparse = DenseFromSparse()
class SparseFromDense(gof.op.Op): class SparseFromDense(gof.op.Op):
"""
Convert an `ndarray` matrix to a sparse matrix.
"""
def __init__(self, format): def __init__(self, format):
self.format = format self.format = format
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论