def test_constrain_filter_max_norm():
    """
    Test that ConstrainFilterNorm matches a manual implementation.
    """

    limit = 1.
    ext = ConstrainFilterMaxNorm(limit)

    W = np.zeros((2, 4))
    # Column 0 tests the case where an element has zero norm
    # Column 1 tests the case where an element is smaller than the limit
    W[0, 1] = .5
    # Column 2 tests the case where an element is on the limit
    W[0, 2] = 1.
    # Column 3 tests the case where an element is too big
    W[0, 3] = 2.

    W = sharedX(2. / W)
    model = ModelWithW(W)
    model.extensions.append(ext)

    updates = OrderedDict()
    updates[W] = W * 2.
    model.modify_updates(updates)
    f = function([], updates=updates)
    f()
    W = W.get_value()

    assert W.shape == (2, 4)
    assert np.abs(W[1, :]).max() == 0
    assert W[0, 0] == 0.
    assert W[0, 1] == 0.5
    assert W[0, 2] == 1.
    assert W[0, 3] == 1., W[0, 3]
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/model_extensions/tests/test_norm_constraint.py/test_constrain_filter_max_norm/swapped operands of `/`