Пример #1
0
def test():
    np_array = np.array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9])
    one = ak.Array(np_array)

    np_array[1] = 999
    assert ak.to_list(one) == [0.0, 999, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]

    two = copy.copy(one)
    np_array[3] = 123
    assert ak.to_list(two) == [0.0, 999, 2.2, 123, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]

    three = copy.deepcopy(two)
    four = np.copy(two)
    np_array[5] = 321
    assert ak.to_list(three) == [0.0, 999, 2.2, 123, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]
    assert ak.to_list(four) == [0.0, 999, 2.2, 123, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]

    assert ak.to_list(copy.deepcopy(ak.Array([[1, 2, 3], [], [4, 5]]))) == [
        [1, 2, 3],
        [],
        [4, 5],
    ]

    assert ak.to_list(copy.deepcopy(ak.Record({"one": 1, "two": 2.2}))) == ak.to_list(
        copy.deepcopy(ak.Record({"one": 1, "two": 2.2}))
    )
Пример #2
0
def test_record():
    assert pickle.loads(pickle.dumps(ak.Record({
        "x": 2.2,
        "y": [1, 2]
    }), -1)).tolist() == {
        "x": 2.2,
        "y": [1, 2]
    }
    assert pickle.loads(
        pickle.dumps(
            ak.Array([
                {
                    "x": 1.1,
                    "y": [1]
                },
                {
                    "x": 2.2,
                    "y": [1, 2]
                },
                {
                    "x": 3.3,
                    "y": [1, 2, 3]
                },
            ])[1],
            -1,
        )).tolist() == {
            "x": 2.2,
            "y": [1, 2]
        }
def test_Record():
    record = ak.Record({"x": 1, "y": [1, 2, 3]})

    @numba.njit
    def f1():
        return record.y[1]

    assert f1() == 2
def test():
    point = ak.Record(
        {
            "x": 1,
            "y": 2,
            "z": 3
        },
        with_name="Vector3D",
        behavior=vector._backends.awkward_.behavior,
    )
    assert np.matmul(point, vector.obj(x=1, y=0, z=2)) == 7
def test():
    @numba.njit
    def f1(array):
        return array.ndim

    assert f1(ak.Array([[1, 2, 3], [], [4, 5]])) == 2
    assert f1(ak.Array([[[1], [2, 3]], [], [[4, 5], []]])) == 3

    with pytest.raises(numba.core.errors.TypingError):
        f1(ak.Record({"x": [1, 2, 3], "y": [4]}))

    partitioned = ak.partitioned(
        [ak.Array([[1, 2, 3], [], [4, 5]]) for i in range(5)])

    assert f1(partitioned) == 2
Пример #6
0
    def test_cherenkov_from_best_track_which_returns_awkward_Record(self):
        pd = km3pipe.extras.pandas()

        best_track = ak.Record(self.track)

        arr = cherenkov(pd.DataFrame(self.calib_hits), best_track)

        self.assertAlmostEqual(arr["d_photon_closest"][0], 24.049593557846112)
        self.assertAlmostEqual(arr["d_photon"][0], 35.80244420413484)
        self.assertAlmostEqual(arr["d_track"][0], 45.88106599210481)
        self.assertAlmostEqual(arr["t_photon"][0], 70311759.26448613)
        self.assertAlmostEqual(arr["cos_photon_PMT"][0], -0.98123942583677)
        self.assertAlmostEqual(arr["dir_x_photon"][0], 0.45964884122649263)
        self.assertAlmostEqual(arr["dir_y_photon"][0], -0.8001372907490844)
        self.assertAlmostEqual(arr["dir_z_photon"][0], -0.3853612055096594)
Пример #7
0
    def _apply_global_index(self, index):
        """Internal method to take from a collection using a flat index

        This is often necessary to be able to still resolve cross-references on
        reduced arrays or single records.
        """
        if isinstance(index, int):
            out = self._content()[index]
            return awkward.Record(out, behavior=self.behavior)

        def flat_take(layout):
            idx = awkward.Array(layout)
            return self._content()[idx.mask[idx >= 0]]

        def descend(layout, depth):
            if layout.purelist_depth == 1:
                return lambda: flat_take(layout)

        (index, ) = awkward.broadcast_arrays(index)
        out = awkward._util.recursively_apply(index.layout, descend)
        return awkward.Array(out, behavior=self.behavior)
Пример #8
0
def test():
    behavior = {"point": Point}
    rec = ak.Record({"x": 1, "y": 1.1}, with_name="point", behavior=behavior)
    assert isinstance(rec, Point)
    assert hasattr(rec, "distance")
def test_record():
    assert ak.to_list(ak.Record({"x": 1, "y": 2.2})) == {"x": 1, "y": 2.2}