import tensorflow as tf

    # Pad input.
    x_ = _pad_input(
        x, ksize, strides, padding, bsize=[1, blk_shape[1], blk_shape[2], 1], bstrides=bstrides)

    # Convolution when number of indices is larger than zero.
    def _conv_nonzero():
        # Gather patches.
        p = tf.gather_nd(x_, blk_indices_)

        # Reshape patches.
        p = tf.reshape(p, [blk_shape[0], blk_shape[1], blk_shape[2], -1])

        # Convolution on patches.
        q = tf.nn.conv2d(p, w, strides, 'VALID', use_cudnn_on_gpu=True)
