def test_weighted_pool():
 rng = numpy.random.RandomState(220)
 for ds in [3]:
  for batch in [2]:
   for ch in [2]:
    data = rng.uniform(size=(batch, ch, ds, ds)).astype('float32')
    x = theano.tensor.tensor4()
    w_max = weighted_max_pool_bc01(x, (ds, ds), (ds, ds), (ds, ds))
    f = theano.function([x], w_max)
    op_val = numpy.asarray(f(data))
    norm = (data / data.sum(3).sum(2)[:, :, numpy.newaxis, numpy.newaxis])
    py_val = (data * norm).sum(3).sum(2)[:, :, numpy.newaxis, numpy.newaxis]
    assert numpy.allclose(op_val, py_val)

def test_weighted_pool ( ) : rng = numpy . random . RandomState ( 220 ) for ds in [ 3 ] : for batch in [ 2 ] : for ch in [ 2 ] : data = rng . uniform ( size = ( batch , ch , ds , ds ) ) . astype ( 'float32' ) x = theano . tensor . tensor4 ( ) w_max = weighted_max_pool_bc01 ( x , ( ds , ds ) , ( ds , ds ) , ( ds , ds ) ) f = theano . function ( [ x ] , w_max ) op_val = numpy . asarray ( f ( data ) ) norm = ( data / data . sum ( 3 ) . sum ( 2 ) [ : , : , numpy . newaxis , numpy . newaxis ] ) py_val = ( data * norm ) . sum ( 3 ) . sum ( 2 ) [ : , : , numpy . newaxis , numpy . newaxis ] assert numpy . allclose ( op_val , py_val )
test weighted pooling theano implementation against numpy implementation .