import tensorflow as tf

    :param padding:   [string]    Convolution padding method, `VALID` or `SAME`.
    """
    assert len(mask.get_shape()) in [3, 4], 'Mask shape must be 3D or 4D.'
    if len(mask.get_shape()) == 3:
        mask_ = tf.expand_dims(mask, 3)
    elif len(mask.get_shape()) == 4:
        mask_ = mask
        assert mask.get_shape()[-1] == 1, '4D mask last dimension must be 1.'
    ksize = [int(ss) for ss in w.get_shape()]
    psize = [1, ksize[0], ksize[1], 1]
    mask_ = tf.nn.max_pool(mask_, psize, strides, padding)
    return tf.nn.conv2d(x, w, strides, padding) * mask_
