def as_type(obj, typ):
    """Return obj if it is of dtype typ, otherwise return a copy type-cast to
    typ."""
    # Assume it's a NumPy data type
    try:
        return obj if obj.dtype == typ else obj.astype(typ)
    except __HOLE__:
        if isinstance(obj, int):
            return np.int64(obj).astype(typ)
        elif isinstance(obj, float):
            return np.float64(obj).astype(typ)
        else:
            raise TypeError("Invalid type %s" % type(obj))
dataset/ETHPy150Open OP2/PyOP2/pyop2/utils.py/as_type