<s> '''<STR_LIT>''' <EOL> from __future__ import print_function <EOL> __authors__ = "<STR_LIT>" <EOL> import theano <EOL> import theano . tensor as T <EOL> import numpy <EOL> import time <EOL> floatX = '<STR_LIT>' <EOL> def relu ( x ) : <EOL> """<STR_LIT>""" <EOL> return T . maximum ( <NUM_LIT:0.0> , x ) <EOL> def relu_ ( x ) : <EOL> """<STR_LIT>""" <EOL> return x * ( x > <NUM_LIT:0> ) <EOL> def relu__ ( x ) : <EOL> """<STR_LIT>""" <EOL> return T . switch ( x < <NUM_LIT:0.> , <NUM_LIT:0.> , x ) <EOL> def test_scalar_rectifier ( ) : <EOL> """<STR_LIT>""" <EOL> x = T . fmatrix ( '<STR_LIT>' ) <EOL> y1 = relu ( x ) <EOL> y3 = relu_ ( x ) <EOL> y4 = relu__ ( x ) <EOL> f1 = theano . function ( inputs = [ x ] , outputs = y1 , name = '<STR_LIT>' ) <EOL> f3 = theano . function ( inputs = [ x ] , outputs = y3 , name = '<STR_LIT>' ) <EOL> f4 = theano . function ( inputs = [ x ] , outputs = y4 , name = '<STR_LIT>' ) <EOL> g1 = theano . function ( inputs = [ x ] , outputs = T . grad ( y1 . sum ( ) , x ) , <EOL> name = '<STR_LIT>' ) <EOL> g3 = theano . function ( inputs = [ x ] , outputs = T . grad ( y3 . sum ( ) , x ) , <EOL> name = '<STR_LIT>' ) <EOL> g4 = theano . function ( inputs = [ x ] , outputs = T . grad ( y4 . sum ( ) , x ) , <EOL> name = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> value = numpy . random . uniform ( - <NUM_LIT:1> , <NUM_LIT:1> , size = ( <NUM_LIT:100> , <NUM_LIT> ) ) . astype ( floatX ) <EOL> numpy . testing . assert_array_equal ( f1 ( value ) , f3 ( value ) , <EOL> err_msg = '<STR_LIT>' ) <EOL> numpy . testing . assert_array_equal ( f1 ( value ) , f4 ( value ) , <EOL> err_msg = '<STR_LIT>' ) <EOL> numpy . testing . assert_array_equal ( g1 ( value ) , g3 ( value ) , <EOL> err_msg = '<STR_LIT>' ) <EOL> numpy . testing . assert_array_equal ( g1 ( value ) , g4 ( value ) , <EOL> err_msg = '<STR_LIT>' ) <EOL> def benchmark_relu ( ) : <EOL> """<STR_LIT>""" <EOL> x = T . ftensor4 ( '<STR_LIT>' ) <EOL> ops = [ <EOL> relu_ ( x ) . sum ( ) , <EOL> relu ( x ) . sum ( ) , <EOL> relu__ ( x ) . sum ( ) , <EOL> T . grad ( relu_ ( x ) . sum ( ) , x ) , <EOL> T . grad ( relu ( x ) . sum ( ) , x ) , <EOL> T . grad ( relu__ ( x ) . sum ( ) , x ) , <EOL> ] <EOL> names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> value = numpy . random . uniform ( size = ( <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT:32> , <NUM_LIT:100> ) ) . astype ( floatX ) <EOL> times = [ ] <EOL> for op , name in zip ( ops , names ) : <EOL> f = theano . function ( inputs = [ x ] , outputs = op , name = name ) <EOL> n_loops = <NUM_LIT:10> <EOL> t0 = time . time ( ) <EOL> for i in range ( n_loops ) : <EOL> f ( value ) <EOL> t1 = time . time ( ) <EOL> benchmark = t1 - t0 <EOL> times . append ( benchmark ) <EOL> print ( name ) <EOL> theano . printing . debugprint ( f , print_type = True ) <EOL> print ( names ) <EOL> print ( times ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> benchmark_relu ( ) </s>
