def METHOD_NAME(
    self, batch_size, dense_last_dim, default_value, gc, dc
):
    L = np.random.randint(1, dense_last_dim + 1, size=(batch_size))
    num_data = L.sum()
    # The following logic ensure that indices in each batch will not be duplicated
    I = np.array([]).astype(np.int32)
    for l in L:
        I_l = np.random.choice(dense_last_dim, l, replace=False)
        I = np.concatenate((I, I_l))
    V = np.random.rand(num_data).astype(np.float32)
    op = core.CreateOperator(
        'BatchSparseToDense',
        ['L', 'I', 'V'],
        ['O'],
        dense_last_dim=dense_last_dim,
        default_value=default_value,
    )
    S = np.random.rand(batch_size, dense_last_dim).astype(np.float32)
    op2 = core.CreateOperator(
        'BatchSparseToDense',
        ['L', 'I', 'V', 'S'],
        ['O'],
        default_value=default_value,
    )
    def batch_sparse_to_dense_ref(L, I, V, S=None):
        if S is None:
            ret = np.zeros((batch_size, dense_last_dim))
        else:
            ret = np.zeros(S.shape)
        ret.fill(default_value)
        batch = 0
        v_idx = 0
        for length in L:
            for _ in range(length):
                ret[batch][I[v_idx]] = V[v_idx]
                v_idx += 1
            batch += 1
        return [ret]
    self.assertDeviceChecks(dc, op, [L, I, V], [0])
    self.assertReferenceChecks(gc, op, [L, I, V], batch_sparse_to_dense_ref)
    self.assertGradientChecks(gc, op, [L, I, V], 2, [0])
    self.assertDeviceChecks(dc, op2, [L, I, V, S], [0])
    self.assertReferenceChecks(gc, op2, [L, I, V, S], batch_sparse_to_dense_ref)
    self.assertGradientChecks(gc, op2, [L, I, V, S], 2, [0])
    self.assertDeviceChecks(dc, op, [L.astype(np.int32), I, V], [0])
    self.assertReferenceChecks(gc, op, [L.astype(np.int32), I, V], batch_sparse_to_dense_ref)
    self.assertGradientChecks(gc, op, [L.astype(np.int32), I, V], 2, [0])