提交 6922c2f9 authored 作者: Frederic's avatar Frederic

pep8

上级 3c02813f
......@@ -20,30 +20,35 @@ def test_no_reuse():
return
assert not 'should not get here'
def test_gc_never_pickles_temporaries():
x = T.dvector()
#print >> sys.stderr, 'BUILDING GRAPH'
for i in xrange(2): #TODO: 30 causes like LONG compilation due to MERGE
if i :
for i in xrange(2): # TODO: 30 causes like LONG compilation due to MERGE
if i:
r = r + r/10
else:
r = x
optimizer=None
optimizer='fast_run'
optimizer = None
optimizer = 'fast_run'
for f_linker, g_linker in [
(theano.PerformLinker(allow_gc = True), theano.PerformLinker(allow_gc=False)),
(theano.OpWiseCLinker(allow_gc = True), theano.OpWiseCLinker(allow_gc=False))]:
(theano.PerformLinker(allow_gc=True),
theano.PerformLinker(allow_gc=False)),
(theano.OpWiseCLinker(allow_gc=True),
theano.OpWiseCLinker(allow_gc=False))]:
#f_linker has garbage collection
#g_linker has no garbage collection
#print >> sys.stderr, 'COMPILING'
f = theano.function([x], r,mode=theano.Mode(optimizer=optimizer, linker=f_linker))
g = theano.function([x], r,mode=theano.Mode(optimizer=optimizer, linker=g_linker))
f = theano.function([x], r, mode=theano.Mode(optimizer=optimizer,
linker=f_linker))
g = theano.function([x], r, mode=theano.Mode(optimizer=optimizer,
linker=g_linker))
len_pre_f = len(cPickle.dumps(f))
len_pre_g = len(cPickle.dumps(g))
......@@ -55,21 +60,20 @@ def test_gc_never_pickles_temporaries():
def a(fn):
return len(cPickle.dumps(fn.maker))
assert a(f) == a(f) # some sanity checks on the pickling mechanism
assert a(g) == a(g) # some sanity checks on the pickling mechanism
assert a(f) == a(f) # some sanity checks on the pickling mechanism
assert a(g) == a(g) # some sanity checks on the pickling mechanism
def b(fn):
return len(
cPickle.dumps(
theano.compile.function_module._pickle_Function(
fn)))
assert b(f) == b(f) # some sanity checks on the pickling mechanism
cPickle.dumps(
theano.compile.function_module._pickle_Function(
fn)))
assert b(f) == b(f) # some sanity checks on the pickling mechanism
def c(fn):
return len(cPickle.dumps(fn))
assert c(f) == c(f) # some sanity checks on the pickling mechanism
assert c(g) == c(g) # some sanity checks on the pickling mechanism
assert c(f) == c(f) # some sanity checks on the pickling mechanism
assert c(g) == c(g) # some sanity checks on the pickling mechanism
# now run the function once to create temporaries within the no-gc
# linker
......@@ -86,28 +90,32 @@ def test_gc_never_pickles_temporaries():
# allow_gc should leave the function un-changed by calling
assert len_pre_f == len_post_f
#assert that g() didn't cause g to grow
# because temporaries that weren't collected shouldn't be pickled anyway
#assert that g() didn't cause g to grow because temporaries
# that weren't collected shouldn't be pickled anyway
assert len_post_f == len_post_g, (f_linker, len_post_f, len_post_g)
def test_merge_opt_runtime():
"""In the original merge optimization, the following graph took like caused the MERGE
optimizer to exhibit really bad performance (quadratic? exponential?)
"""In the original merge optimization, the following graph took
like caused the MERGE optimizer to exhibit really bad performance
(quadratic? exponential?)
Ironically, there is actually no merging to do in this graph.
"""
x = T.dvector()
for i in xrange(50):
if i :
if i:
r = r + r/10
else:
r = x
t = time.time()
f = theano.function([x], r, mode='FAST_COMPILE')
# FAST_RUN does in-place optimizer which requires a lot of toposorting, which is actually
# pretty slow at the moment. This test was designed to test MergeOptimizer... so I'm
# leaving toposort optimizations for a later date.
# FAST_RUN does in-place optimizer which requires a lot of
# toposorting, which is actually pretty slow at the moment. This
# test was designed to test MergeOptimizer... so I'm leaving
# toposort optimizations for a later date.
dt = time.time() - t
assert dt < 5.0 #it should never take longer than 5 seconds to compile this graph
# it should never take longer than 5 seconds to compile this graph
assert dt < 5.0
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论