import tensorflow as tf

    blk_shape = tf.shape(blk_indices)
    blk_indices_ = tf.reshape(blk_indices, [-1, 3])
    ksize = tf.shape(w)

    # Calculate the block strides.
    bstrides = _calc_block_strides(blk_shape, ksize, strides)

    # Calculate the output size.
    x_shape = tf.shape(x)
    out_shape = calc_out_size_4d(x_shape, ksize, strides, padding)

    # 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.
