def testCast(self): N = 100 arrays = { ak.int64: ak.randint(-(2**48), 2**48, N), ak.float64: ak.randint(0, 1, N, dtype=ak.float64), ak.bool: ak.randint(0, 2, N, dtype=ak.bool) } roundtripable = set( ((ak.bool, ak.bool), (ak.int64, ak.int64), (ak.int64, ak.float64), (ak.int64, npstr), (ak.float64, ak.float64), (ak.float64, npstr), (ak.uint8, ak.int64), (ak.uint8, ak.float64), (ak.uint8, npstr))) for t1, orig in arrays.items(): for t2 in ak.DTypes: t2 = ak.dtype(t2) other = ak.cast(orig, t2) self.assertEqual(orig.size, other.size) if (t1, t2) in roundtripable: roundtrip = ak.cast(other, t1) self.assertTrue((orig == roundtrip).all(), f"{t1}: {orig[:5]}, {t2}: {roundtrip[:5]}") self.assertTrue((ak.array([1, 2, 3, 4, 5]) == ak.cast(ak.linspace(1, 5, 5), dt=ak.int64)).all()) self.assertEqual( ak.cast(ak.arange(0, 5), dt=ak.float64).dtype, ak.float64) self.assertTrue((ak.array([False, True, True, True, True]) == ak.cast(ak.linspace(0, 4, 5), dt=ak.bool)).all())
def testCast(self): N = 100 arrays = { ak.int64: ak.randint(-(2**48), 2**48, N), ak.float64: ak.randint(0, 1, N, dtype=ak.float64), ak.bool: ak.randint(0, 2, N, dtype=ak.bool) } roundtripable = set( ((ak.bool, ak.bool), (ak.int64, ak.int64), (ak.int64, ak.float64), (ak.int64, akstr), (ak.float64, ak.float64), (ak.float64, akstr), (ak.uint8, ak.int64), (ak.uint8, ak.float64), (ak.uint8, akstr))) for t1, orig in arrays.items(): for t2 in ak.DTypes: t2 = ak.dtype(t2) other = ak.cast(orig, t2) self.assertEqual(orig.size, other.size) if (t1, t2) in roundtripable: roundtrip = ak.cast(other, t1) self.assertTrue((orig == roundtrip).all(), f"{t1}: {orig[:5]}, {t2}: {roundtrip[:5]}")