提交 d7860d0d authored 作者: Chiheb Trabelsi's avatar Chiheb Trabelsi

walltime.py has been modified in order to respect the flake8 style.

上级 4a076fd3
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
from __future__ import print_function from __future__ import print_function
import sys, time import sys
import time
from six import iteritems from six import iteritems
from theano.compile.pfunc import pfunc from theano.compile.pfunc import pfunc
from theano import tensor from theano import tensor
...@@ -35,35 +36,47 @@ def showtimes(times): ...@@ -35,35 +36,47 @@ def showtimes(times):
def cmp_sigmoids(shape): def cmp_sigmoids(shape):
def numpy_sigmoid(input): def numpy_sigmoid(input):
rval = 1.0 / (1.0 + numpy.exp(-input)) 1.0 / (1.0 + numpy.exp(-input))
sinput = tensor.Tensor(dtype='float32', broadcastable=(0,)*len(shape))() sinput = tensor.Tensor(
shared_input = tcn.shared_constructor(numpy.random.rand(*shape), 'shared_input') dtype='float32', broadcastable=(0,) * len(shape))()
times = compare_fns( shared_input = tcn.shared_constructor(
dict( numpy=numpy_sigmoid numpy.random.rand(*shape),
, theano_cpu=pfunc([sinput], 1.0 / (1.0 + tensor.exp(-sinput))) 'shared_input')
, theano_gpu_onboard=pfunc([sinput], [], updates=[(shared_input, 1.0 / (1.0 + tensor.exp(-shared_input)))]) times = compare_fns(dict(
), numpy=numpy_sigmoid,
input=shared_input.value) theano_cpu=pfunc([sinput], 1.0 / (1.0 + tensor.exp(-sinput))),
theano_gpu_onboard=pfunc(
[sinput],
[],
updates=[(
shared_input,
1.0 / (1.0 + tensor.exp(-shared_input)))])),
input=shared_input.value)
showtimes(times) showtimes(times)
def cmp_sigmoids_T(shape): def cmp_sigmoids_T(shape):
def numpy_sigmoid(input): def numpy_sigmoid(input):
rval = 1.0 / (1.0 + numpy.exp(-input.T)) 1.0 / (1.0 + numpy.exp(-input.T))
sinput = tensor.Tensor(dtype='float32', broadcastable=(0,)*len(shape))() sinput = tensor.Tensor(
shared_input = tcn.shared_constructor(numpy.random.rand(*shape), 'shared_input') dtype='float32', broadcastable=(0,) * len(shape))()
times = compare_fns( shared_input = tcn.shared_constructor(
dict( numpy=numpy_sigmoid numpy.random.rand(*shape),
, theano_cpu=pfunc([sinput], 1.0 / (1.0 + tensor.exp(-sinput.T))) 'shared_input')
, theano_gpu_onboard=pfunc([sinput], [], updates=[(shared_input, 1.0 / (1.0 + times = compare_fns(dict(
tensor.exp(-shared_input.T)))]) numpy=numpy_sigmoid,
), theano_cpu=pfunc([sinput], 1.0 / (1.0 + tensor.exp(-sinput.T))),
input=shared_input.value) theano_gpu_onboard=pfunc(
[sinput],
[],
updates=[(
shared_input,
1.0 / (1.0 + tensor.exp(-shared_input.T)))])),
input=shared_input.value)
showtimes(times) showtimes(times)
if __name__ == '__main__': if __name__ == '__main__':
eval(sys.argv[1]) eval(sys.argv[1])
# cmp_sigmoids((640, 64*64)) # looks great in profiler # cmp_sigmoids((640, 64*64)) # looks great in profiler
#cmp_sigmoids((173, 74*49)) # cmp_sigmoids((173, 74*49))
#cmp_sigmoids_T((173, 74*49)) # cmp_sigmoids_T((173, 74*49))
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论