def cast(tensor, dtype):
    """Cast

    Args:
        tensor (Tensor): tensor to cast.
        dtype (str): type to cast. Usually floatx or intx
    """

    if isinstance(tensor, float) or isinstance(tensor, int):
        if dtype in ['float', 'float32']:
            return float(tensor)
        elif dtype == ['int', 'int32']:
            return int(tensor)
        else:
            raise ValueError("can't cast scalar", type(tensor), "to dype",
                             dtype)
    return tensor.astype(dtype)