<s> from __future__ import print_function <EOL> import copy <EOL> import numpy <EOL> import theano <EOL> from theano . tensor import grad <EOL> from theano . tests import unittest_tools <EOL> import theano . sandbox . cuda as tcn <EOL> import warnings <EOL> if not tcn . cuda_available : <EOL> from nose . plugins . skip import SkipTest <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> from pylearn2 . sandbox . cuda_convnet . pool import MaxPool , MaxPoolGrad <EOL> from pylearn2 . models . mlp import max_pool_c01b as gold_max_pool_c01b <EOL> if theano . config . mode == '<STR_LIT>' : <EOL> mode_with_gpu = theano . compile . mode . get_mode ( '<STR_LIT>' ) . including ( '<STR_LIT>' ) <EOL> mode_without_gpu = theano . compile . mode . get_mode ( <EOL> '<STR_LIT>' ) . excluding ( '<STR_LIT>' ) <EOL> else : <EOL> mode_with_gpu = theano . compile . mode . get_default_mode ( ) . including ( '<STR_LIT>' ) <EOL> mode_without_gpu = theano . compile . mode . get_default_mode ( ) . excluding ( '<STR_LIT>' ) <EOL> mode_with_gpu = copy . copy ( mode_with_gpu ) <EOL> mode_without_gpu = copy . copy ( mode_without_gpu ) <EOL> mode_with_gpu . check_py_code = False <EOL> mode_without_gpu . check_py_code = False <EOL> def my_rand ( * shape ) : <EOL> return theano . _asarray ( numpy . random . rand ( * shape ) , dtype = '<STR_LIT>' ) <EOL> def test_pool ( ) : <EOL> shps = [ ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> ) , <EOL> ] <EOL> shps = [ ( channel , x , y , batch ) for ( batch , channel , x , y ) in shps ] <EOL> warnings . warn ( "<STR_LIT>" ) <EOL> for shp in shps : <EOL> for ds in range ( <NUM_LIT:1> , min ( <NUM_LIT:4> , shp [ <NUM_LIT:2> ] + <NUM_LIT:1> ) ) : <EOL> for start in [ <NUM_LIT:0> ] : <EOL> for stride in range ( <NUM_LIT:1> , min ( shp [ <NUM_LIT:2> ] , ds , <NUM_LIT:4> ) + <NUM_LIT:1> ) : <EOL> va = my_rand ( * shp ) <EOL> tva = va . flatten ( ) <EOL> vb = my_rand ( * shp ) <EOL> tvb = vb . flatten ( ) <EOL> a = tcn . shared_constructor ( va , '<STR_LIT:a>' ) <EOL> b = tcn . shared_constructor ( vb , '<STR_LIT:b>' ) <EOL> op = MaxPool ( ds = ds , stride = stride ) <EOL> v = op ( a ) <EOL> rval = theano . tensor . Rop ( v , a , b ) <EOL> f = theano . function ( [ ] , rval , <EOL> mode = mode_with_gpu ) <EOL> print ( f . maker . fgraph . toposort ( ) ) <EOL> out = numpy . asarray ( f ( ) ) </s>
