def test_max_pool_options():
    if not cuda.cuda_available:
        raise SkipTest('Optional package cuda disabled.')
    if not dnn_available():
        raise SkipTest('Optional package cuDNN disabled.')

    mode = copy.copy(theano.compile.get_default_mode())
    mode.check_isfinite = False

    X_sym = tensor.ftensor4('X')
    # Case 1: shape > stride
    shp = (3, 3)
    strd = (2, 2)
    im_shp = (6, 4)
    pool_it = max_pool(X_sym, pool_shape=shp, pool_stride=strd,
                       image_shape=im_shp, try_dnn=False)
    pool_dnn = max_pool(X_sym, pool_shape=shp, pool_stride=strd,
                        image_shape=im_shp)
    # Make sure that different ops were used.
    assert pool_it.owner.op != pool_dnn.owner.op
    f = theano.function(inputs=[X_sym], outputs=[pool_it, pool_dnn],
                        mode=mode)

    X = np.array([[2, 1, 3, 4],
                  [1, 1, 3, 3],
                  [5, 5, 7, 8],
                  [5, 6, 8, 7],
                  [9, 10, 11, 12],
                  [9, 10, 14, 15]],
                 dtype="float32")[np.newaxis, np.newaxis, ...]

    expected = np.array([[7, 8],
                         [11, 12],
                         [14, 15]],
                        dtype="float32")[np.newaxis,
                                         np.newaxis,
                                         ...]
    actual, actual_dnn = f(X)
    actual_dnn = np.array(actual_dnn)
    assert np.allclose(expected, actual)
    assert np.allclose(actual, actual_dnn)

    # Case 2: shape < stride
    shp = (2, 2)
    strd = (3, 3)
    im_shp = (6, 4)
    pool_it = max_pool(X_sym, pool_shape=shp, pool_stride=strd,
                       image_shape=im_shp, try_dnn=False)
    pool_dnn = max_pool(X_sym, pool_shape=shp, pool_stride=strd,
                        image_shape=im_shp)
    # Make sure that different ops were used.
    assert pool_it.owner.op != pool_dnn.owner.op

    f = theano.function(inputs=[X_sym], outputs=[pool_it, pool_dnn],
                        mode=mode)

    X = np.array([[2, 1, 3, 4],
                  [1, 1, 3, 3],
                  [5, 5, 7, 8],
                  [5, 6, 8, 7],
                  [9, 10, 11, 12],
                  [9, 10, 14, 15]],
                 dtype="float32")[np.newaxis, np.newaxis, ...]

    expected = np.array([[2, 4],
                         [10, 12]],
                        dtype="float32")[np.newaxis,
                                         np.newaxis,
                                         ...]
    actual, actual_dnn = f(X)
    actual_dnn = np.array(actual_dnn)
    assert np.allclose(expected, actual)
    assert np.allclose(actual, actual_dnn)

    # Case 3: shape == stride
    shp = (2, 2)
    strd = (2, 2)
    im_shp = (6, 4)
    pool_it = max_pool(X_sym, pool_shape=shp, pool_stride=strd,
                       image_shape=im_shp, try_dnn=False)
    pool_dnn = max_pool(X_sym, pool_shape=shp, pool_stride=strd,
                        image_shape=im_shp)
    # Make sure that different ops were used.
    assert pool_it.owner.op != pool_dnn.owner.op

    f = theano.function(inputs=[X_sym], outputs=[pool_it, pool_dnn],
                        mode=mode)

    X = np.array([[2, 1, 3, 4],
                  [1, 1, 3, 3],
                  [5, 5, 7, 8],
                  [5, 6, 8, 7],
                  [9, 10, 11, 12],
                  [9, 10, 14, 15]],
                 dtype="float32")[np.newaxis, np.newaxis, ...]

    expected = np.array([[2, 4],
                         [6, 8],
                         [10, 15]],
                        dtype="float32")[np.newaxis,
                                         np.newaxis,
                                         ...]
    actual, actual_dnn = f(X)
    actual_dnn = np.array(actual_dnn)
    assert np.allclose(expected, actual)
    assert np.allclose(actual, actual_dnn)

    # Case 4: row shape < row stride
    shp = (2, 2)
    strd = (3, 2)
    im_shp = (6, 4)
    pool_it = max_pool(X_sym, pool_shape=shp, pool_stride=strd,
                       image_shape=im_shp, try_dnn=False)
    pool_dnn = max_pool(X_sym, pool_shape=shp, pool_stride=strd,
                        image_shape=im_shp)
    # Make sure that different ops were used.
    assert pool_it.owner.op != pool_dnn.owner.op

    f = theano.function(inputs=[X_sym], outputs=[pool_it, pool_dnn],
                        mode=mode)

    X = np.array([[2, 1, 3, 4],
                  [1, 1, 3, 3],
                  [5, 5, 7, 8],
                  [5, 6, 8, 7],
                  [9, 10, 11, 12],
                  [9, 10, 14, 15]],
                 dtype="float32")[np.newaxis, np.newaxis, ...]

    expected = np.array([[2, 4],
                         [10, 12]],
                        dtype="float32")[np.newaxis,
                                         np.newaxis,
                                         ...]
    actual, actual_dnn = f(X)
    actual_dnn = np.array(actual_dnn)
    assert np.allclose(expected, actual)
    assert np.allclose(actual, actual_dnn)

    # Case 5: col shape < col stride
    shp = (2, 2)
    strd = (2, 3)
    im_shp = (6, 4)
    pool_it = max_pool(X_sym, pool_shape=shp, pool_stride=strd,
                       image_shape=im_shp, try_dnn=False)
    pool_dnn = max_pool(X_sym, pool_shape=shp, pool_stride=strd,
                        image_shape=im_shp)
    # Make sure that different ops were used.
    assert pool_it.owner.op != pool_dnn.owner.op

    f = theano.function(inputs=[X_sym], outputs=[pool_it, pool_dnn],
                        mode=mode)

    X = np.array([[2, 1, 3, 4],
                  [1, 1, 3, 3],
                  [5, 5, 7, 8],
                  [5, 6, 8, 7],
                  [9, 10, 11, 12],
                  [9, 10, 14, 15]],
                 dtype="float32")[np.newaxis, np.newaxis, ...]

    expected = np.array([[2, 4],
                         [6, 8],
                         [10, 15]],
                        dtype="float32")[np.newaxis,
                                         np.newaxis,
                                         ...]
    actual, actual_dnn = f(X)
    actual_dnn = np.array(actual_dnn)
    assert np.allclose(expected, actual)
    assert np.allclose(actual, actual_dnn)
Get RDF for citations
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/models/tests/test_mlp.py/test_max_pool_options--crossover with--dataset/ETHPy150Open upconsulting/IsisCB/isiscb/isisdata/views.py/rdf_authority_view