# Buggy code
def tile(cls, op):
    tensor = op.outputs[0]
    value = op.value
    is_value_tensor = isinstance(value, TENSOR_TYPE)

    index_tensor_op = TensorIndex(dtype=tensor.dtype, sparse=op.sparse)
    index_tensor = index_tensor_op.new_tensor(
        [op.input, op.indexes], tensor.shape
    ).single_tiles()

    nsplits = index_tensor.nsplits
    if any(any(np.isnan(ns) for ns in nsplit) for nsplit in nsplits):
        raise NotImplementedError

    if is_value_tensor:
        value = op.value.rechunk(nsplits).single_tiles()

    chunk_mapping = {c.op.input.index: c for c in index_tensor.chunks}
    out_chunks = []
    for chunk in op.input.chunks:
        index_chunk = chunk_mapping.get(chunk.index)
        if index_chunk is None:
            out_chunks.append(chunk)
            continue

        value_chunk = value.cix[index_chunk.index] if is_value_tensor else value
        chunk_op = op.copy().reset_key()
        out_chunk = chunk_op.new_chunk(
            [chunk, index_chunk.op.indexes, value_chunk], chunk.shape, index=chunk.index
        )
        out_chunks.append(out_chunk)

    new_op = op.copy()
    return new_op.new_tensors(
        [op.input, op.indexes, op.value],
        tensor.shape,
        chunks=out_chunks,
        nsplits=op.input.nsplits,
    )


# Traceback (ValueError)
In [1]: from mars.deploy.local import new_cluster

In [2]: cluster = new_cluster(scheduler_n_process=2, worker_n_process=3, web=True)

In [3]: import mars.tensor as mt

In [4]: t = mt.random.rand(10, 10)

In [5]: mt.split(t, 5).execute()
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/scheduler/graph.py", line 527, in get_executable_operand_dag
kws=kws)
File "/Users/hekaisheng/Documents/mars_dev/mars/mars/tensor/expressions/indexing/getitem.py", line 58, in new_chunks
chunk, indexes = inputs
ValueError: not enough values to unpack (expected 2, got 1)
2018-12-25T02:23:13Z <Greenlet "Greenlet-0" at 0x11a9f47b8: <built-in method fire_run of mars.actors.pool.gevent_pool.ActorExecutionContext object at 0x11b154458>> failed with ValueError

# Fixed code
def tile(cls, op):
    tensor = op.outputs[0]
    value = op.value
    is_value_tensor = isinstance(value, TENSOR_TYPE)

    index_tensor_op = TensorIndex(dtype=tensor.dtype, sparse=op.sparse)
    index_tensor = index_tensor_op.new_tensor(
        [op.input], tensor.shape, indexes=op.indexes
    ).single_tiles()

    nsplits = index_tensor.nsplits
    if any(any(np.isnan(ns) for ns in nsplit) for nsplit in nsplits):
        raise NotImplementedError

    if is_value_tensor:
        value = op.value.rechunk(nsplits).single_tiles()

    chunk_mapping = {c.op.input.index: c for c in index_tensor.chunks}
    out_chunks = []
    for chunk in op.input.chunks:
        index_chunk = chunk_mapping.get(chunk.index)
        if index_chunk is None:
            out_chunks.append(chunk)
            continue

        value_chunk = value.cix[index_chunk.index] if is_value_tensor else value
        chunk_op = op.copy().reset_key()
        out_chunk = chunk_op.new_chunk(
            [chunk],
            chunk.shape,
            indexes=index_chunk.op.indexes,
            value=value_chunk,
            index=chunk.index,
        )
        out_chunks.append(out_chunk)

    new_op = op.copy()
    return new_op.new_tensors(
        [op.input],
        tensor.shape,
        indexes=op.indexes,
        value=op.value,
        chunks=out_chunks,
        nsplits=op.input.nsplits,
    )