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

    out_chunks = []
    for c in op.inputs[0].chunks:
        chunk_op = op.copy().reset_key()
        chunk_shape = _reorder(c.shape, op.axes)
        chunk_idx = _reorder(c.index, op.axes)
        out_chunk = chunk_op.new_chunk(
            [c], shape=chunk_shape, index=chunk_idx, order=tensor.order
        )
        out_chunks.append(out_chunk)

    new_op = op.copy()
    nsplits = _reorder(op.inputs[0].nsplits, op.axes)
    return new_op.new_tensors(
        op.inputs,
        op.outputs[0].shape,
        order=tensor.order,
        chunks=out_chunks,
        nsplits=nsplits,
    )


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field()
648             try:
--> 649                 self._set_tuple(value, field_obj, tp=field.type, weak_ref=field.weak_ref)
650             except TypeError:

~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider._set_tuple()
364                     it_obj = Value()
--> 365                     self._set_value(val, it_obj, tp=tp.type if tp is not None else tp)
366                     res.append(it_obj)

~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider._set_value()
559         else:
--> 560             cls._set_typed_value(value, obj, tp, weak_ref=weak_ref)
561

~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider._set_typed_value()
443             value_field = PRIMITIVE_TYPE_TO_VALUE_FIELD[tp]
--> 444             setattr(obj, value_field, value)
445         elif tp is ValueType.slice:

TypeError: 10.0 has type float, but expected one of: int, long

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
/home/admin/work/public-mars-0.5.1.zip/mars/scheduler/graph.py in _execute_graph()

/home/admin/work/public-mars-0.5.1.zip/mars/utils.py in _wrapped()

/home/admin/work/public-mars-0.5.1.zip/mars/scheduler/graph.py in create_operand_actors()

/home/admin/work/public-mars-0.5.1.zip/mars/utils.py in _wrapped()

/home/admin/work/public-mars-0.5.1.zip/mars/scheduler/graph.py in get_executable_operand_dag()

/home/admin/work/public-mars-0.5.1.zip/mars/utils.py in serialize_graph()

~/Workspace/mars/mars/graph.pyx in mars.graph.DirectedGraph.to_pb()
420         return graph
--> 421
422     def to_pb(self, pb_obj=None, data_serial_type=None, pickle_protocol=None):

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Serializable.to_pb()
686                                              pickle_protocol=pickle_protocol)
--> 687         return self.serialize(provider, obj=obj)
688

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Serializable.serialize()
669     def serialize(self, Provider provider, obj=None):
--> 670         return provider.serialize_model(self, obj=obj)
671

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Provider.serialize_model()
797         for name, field in model_instance._FIELDS.items():
--> 798             field.serialize(self, model_instance, obj)
799

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Field.serialize()
154
--> 155     cpdef serialize(self, Provider provider, model_instance, obj):
156         return provider.serialize_field(self, model_instance, obj)

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Field.serialize()
155     cpdef serialize(self, Provider provider, model_instance, obj):
--> 156         return provider.serialize_field(self, model_instance, obj)
157

~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field()
630                     if val is not None:
--> 631                         self._serial_reference_value(tag, field.type.type.model, val, it_obj)
632                     elif isinstance(it_obj, Value):

~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider._serial_reference_value()
572                 field_obj = value.cls(self)()
--> 573                 value.serialize(self, obj=field_obj)
574                 value_pb.type_id = value.__serializable_index__

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Serializable.serialize()
669     def serialize(self, Provider provider, obj=None):
--> 670         return provider.serialize_model(self, obj=obj)
671

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Provider.serialize_model()
797         for name, field in model_instance._FIELDS.items():
--> 798             field.serialize(self, model_instance, obj)
799

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Field.serialize()
154
--> 155     cpdef serialize(self, Provider provider, model_instance, obj):
156         return provider.serialize_field(self, model_instance, obj)

~/Workspace/mars/mars/serialize/core.pyx in mars.serialize.core.Field.serialize()
155     cpdef serialize(self, Provider provider, model_instance, obj):
--> 156         return provider.serialize_field(self, model_instance, obj)
157

~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field()
651                 exc_info = sys.exc_info()
--> 652                 raise TypeError(f'Failed to set field `{tag}` for {model_instance} with '
653                                 f'value {value}, reason: {exc_info[1]}') \

~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider.serialize_field()
648             try:
--> 649                 self._set_tuple(value, field_obj, tp=field.type, weak_ref=field.weak_ref)
650             except TypeError:

~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider._set_tuple()
364                     it_obj = Value()
--> 365                     self._set_value(val, it_obj, tp=tp.type if tp is not None else tp)
366                     res.append(it_obj)

~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider._set_value()
559         else:
--> 560             cls._set_typed_value(value, obj, tp, weak_ref=weak_ref)
561

~/Workspace/mars/mars/serialize/pbserializer.pyx in mars.serialize.pbserializer.ProtobufSerializeProvider._set_typed_value()
443             value_field = PRIMITIVE_TYPE_TO_VALUE_FIELD[tp]
--> 444             setattr(obj, value_field, value)
445         elif tp is ValueType.slice:

TypeError: Failed to set field `shape` for Chunk <op=TensorTranspose, key=6fd87469bf886695950bdfb3164a7ce7> with value (10.0, -1), reason: 10.0 has type float, but expected one of: int, long

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

    out_chunks = []
    for c in op.inputs[0].chunks:
        chunk_op = op.copy().reset_key()
        chunk_shape = tuple(
            s if np.isnan(s) else int(s) for s in _reorder(c.shape, op.axes)
        )
        chunk_idx = _reorder(c.index, op.axes)
        out_chunk = chunk_op.new_chunk(
            [c], shape=chunk_shape, index=chunk_idx, order=tensor.order
        )
        out_chunks.append(out_chunk)

    new_op = op.copy()
    nsplits = _reorder(op.inputs[0].nsplits, op.axes)
    return new_op.new_tensors(
        op.inputs,
        op.outputs[0].shape,
        order=tensor.order,
        chunks=out_chunks,
        nsplits=nsplits,
    )