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')

                # op
                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))

                # python
                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
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/expr/tests/test_stochastic_pool.py/test_weighted_pool