提交 86a5eefe authored 作者: Lijun Xue's avatar Lijun Xue

update test files

上级 130e6464
......@@ -107,5 +107,4 @@ class Test_profiling(unittest.TestCase):
if __name__ == '__main__':
Test_profiling.test_profiling()
Test_profiling.test_ifelse()
unittest.main()
"Test of reduce allocation"
import unittest
import theano
import theano.tensor as T
class Test_reallocation(unittest.TestCase):
"""
Test of Theano reallocation
"""
def test_reallocation(self):
pre_config = theano.config.allow_gc
try:
theano.config.allow_gc = False
x = T.scalar('x')
y = T.scalar('y')
z = T.tanh(x + y) + T.cosh(x + y)
if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]:
m = "FAST_RUN"
else:
m = None
m = theano.compile.get_mode(m).excluding('fusion', 'inplace')
f = theano.function([x, y], z, name="test_reduce_memory",
mode=m)
output = f(1, 2)
storage_map = f.fn.storage_map
def check_storage(storage_map):
for i in storage_map.keys():
keys_copy = storage_map.keys()[:]
keys_copy.remove(i)
for o in keys_copy:
if storage_map[i][0] == storage_map[o][0]:
return True
return False
assert check_storage(storage_map)
finally:
theano.config.allow_gc = pre_config
if __name__ == "__main__":
unittest.main()
import StringIO
import numpy
import theano
import theano.tensor as T
from theano.ifelse import ifelse
def test_reduce():
config1 = theano.config.profile
config2 = theano.config.profile_memory
try:
theano.config.profile = True
theano.config.profile_memory = True
theano.config.profiling.min_peak_memory = True
x = T.scalar('x')
y = T.scalar('y')
z = 5*y + x**2 + y**3 - 4*x
p = theano.ProfileStats(False)
if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]:
m = "FAST_RUN"
else:
m = None
m=theano.compile.get_mode(m).excluding('fusion', 'inplace')
f = theano.function([x, y], z, profile=p, name="test_profiling",
mode=m)
out = f(1, 2)
finally:
theano.config.profile = config1
theano.config.profile_memory = config2
if __name__ == "__main__":
test_reduce()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论