How to use the awkward.JaggedArray.fromiter function in awkward

To help you get started, we’ve selected a few awkward examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-hep / uproot-methods / tests / test_issues.py View on Github external
def test_issue10(self):
        p4 = TLorentzVectorArray.from_ptetaphim(awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]))
        assert p4.mass.tolist() == [[1.0]]
        assert p4[0].mass.tolist() == [1.0]
        assert p4[0][0].mass == 1.0
        assert p4[0][0]._to_cartesian().mass == 0.9999999999999999
        assert type(p4.mass) is awkward.JaggedArray
        assert type(p4.x) is awkward.JaggedArray

        p3 = TVector3Array.from_cylindrical(awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]))
        assert p3.rho.tolist() == [[1.0]]
        assert p3[0].rho.tolist() == [1.0]
        assert p3[0][0].rho == 1.0
        assert type(p3.rho) is awkward.JaggedArray
        assert type(p3.x) is awkward.JaggedArray

        p2 = TVector2Array.from_polar(awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]))
        assert p2.rho.tolist() == [[1.0]]
        assert p2[0].rho.tolist() == [1.0]
        assert p2[0][0].rho == 1.0
        assert type(p2.rho) is awkward.JaggedArray
        assert type(p2.x) is awkward.JaggedArray
github CoffeaTeam / coffea / tests / samples / build_rochester.py View on Github external
suberr = []
            for im in range(len(pt[ie])):
                if isData:
                    subres += [roccor.kScaleDT(int(charge[ie][im]), float(pt[ie][im]), float(eta[ie][im]), float(phi[ie][im]))]
                    suberr += [roccor.kScaleDTerror(int(charge[ie][im]), float(pt[ie][im]), float(eta[ie][im]), float(phi[ie][im]))]
                else:
                    if gid[ie][im]>=0:
                        subres += [roccor.kSpreadMC(int(charge[ie][im]), float(pt[ie][im]), float(eta[ie][im]), float(phi[ie][im]), float(gpt[ie][gid[ie][im]]))]
                        suberr += [roccor.kSpreadMCerror(int(charge[ie][im]), float(pt[ie][im]), float(eta[ie][im]), float(phi[ie][im]), float(gpt[ie][gid[ie][im]]))]
                    else:
                        subres += [roccor.kSmearMC(int(charge[ie][im]), float(pt[ie][im]), float(eta[ie][im]), float(phi[ie][im]), int(nl[ie][im]), float(u[ie][im]))]
                        suberr += [roccor.kSmearMCerror(int(charge[ie][im]), float(pt[ie][im]), float(eta[ie][im]), float(phi[ie][im]), int(nl[ie][im]), float(u[ie][im]))]
            res += [subres]
            err += [suberr]
    res = JaggedArray.fromiter(res)
    err = JaggedArray.fromiter(err)
    outres = res.flatten()
    outerr = err.flatten()
    np.save(fname.replace('.root','_rochester.npy'), outres)
    np.save(fname.replace('.root','_rochester_err.npy'), outerr)
    if not isData:
        outrand = np.concatenate([ui.flatten() for ui in fullu])
        np.save(fname.replace('.root','_rochester_rand.npy'), outrand)
github FAST-HEP / fast-carpenter / tests / test_expressions.py View on Github external
assert len(doubled[0, :, :]) == 0
    assert doubled[1, 0, :] == [2]
    assert doubled[2, 0, :] == [4]
    assert all(doubled[2, 1, :] == [4, 6])

    doubled = expressions.evaluate(wrapped_tree, "Fake3D + Fake3D")
    assert (doubled == fake_3d * 2).all().all().all()
    assert len(doubled[0, :, :]) == 0
    assert doubled[1, 0, :] == [2]
    assert doubled[2, 0, :] == [4]
    assert all(doubled[2, 1, :] == [4, 6])

    fake_3d_2 = [[np.arange(i + 3) + j
                  for i in range(j % 2)]
                 for j in range(len(wrapped_tree))]
    fake_3d_2 = JaggedArray.fromiter(fake_3d_2)
    wrapped_tree.new_variable("SecondFake3D", fake_3d_2)

    with pytest.raises(RuntimeError) as e:
        expressions.evaluate(wrapped_tree, "SecondFake3D + Fake3D")
    assert "different jaggedness" in str(e)
github scikit-hep / uproot-methods / tests / test_issues.py View on Github external
p4 = TLorentzVectorArray.from_ptetaphim(awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]))
        assert p4.mass.tolist() == [[1.0]]
        assert p4[0].mass.tolist() == [1.0]
        assert p4[0][0].mass == 1.0
        assert p4[0][0]._to_cartesian().mass == 0.9999999999999999
        assert type(p4.mass) is awkward.JaggedArray
        assert type(p4.x) is awkward.JaggedArray

        p3 = TVector3Array.from_cylindrical(awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]))
        assert p3.rho.tolist() == [[1.0]]
        assert p3[0].rho.tolist() == [1.0]
        assert p3[0][0].rho == 1.0
        assert type(p3.rho) is awkward.JaggedArray
        assert type(p3.x) is awkward.JaggedArray

        p2 = TVector2Array.from_polar(awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]))
        assert p2.rho.tolist() == [[1.0]]
        assert p2[0].rho.tolist() == [1.0]
        assert p2[0][0].rho == 1.0
        assert type(p2.rho) is awkward.JaggedArray
        assert type(p2.x) is awkward.JaggedArray
github FAST-HEP / fast-carpenter / tests / test_expressions.py View on Github external
def test_3D_jagged(wrapped_tree):
    fake_3d = [[np.arange(i + 1) + j
                for i in range(j % 3)]
               for j in range(len(wrapped_tree))]
    fake_3d = JaggedArray.fromiter(fake_3d)
    wrapped_tree.new_variable("Fake3D", fake_3d)
    assert isinstance(fake_3d.count(), JaggedArray)
    assert all((fake_3d.copy().count() == fake_3d.count()).all())

    aliased = expressions.evaluate(wrapped_tree, "Fake3D")
    assert (aliased == fake_3d).all().all().all()

    doubled = expressions.evaluate(wrapped_tree, "Fake3D * 2")
    assert (doubled == fake_3d * 2).all().all().all()
    assert len(doubled[0, :, :]) == 0
    assert doubled[1, 0, :] == [2]
    assert doubled[2, 0, :] == [4]
    assert all(doubled[2, 1, :] == [4, 6])

    doubled = expressions.evaluate(wrapped_tree, "Fake3D + Fake3D")
    assert (doubled == fake_3d * 2).all().all().all()
github scikit-hep / uproot-methods / tests / test_issues.py View on Github external
def test_issue10(self):
        p4 = TLorentzVectorArray.from_ptetaphim(awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]))
        assert p4.mass.tolist() == [[1.0]]
        assert p4[0].mass.tolist() == [1.0]
        assert p4[0][0].mass == 1.0
        assert p4[0][0]._to_cartesian().mass == 0.9999999999999999
        assert type(p4.mass) is awkward.JaggedArray
        assert type(p4.x) is awkward.JaggedArray

        p3 = TVector3Array.from_cylindrical(awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]))
        assert p3.rho.tolist() == [[1.0]]
        assert p3[0].rho.tolist() == [1.0]
        assert p3[0][0].rho == 1.0
        assert type(p3.rho) is awkward.JaggedArray
        assert type(p3.x) is awkward.JaggedArray

        p2 = TVector2Array.from_polar(awkward.JaggedArray.fromiter([[1.0]]), awkward.JaggedArray.fromiter([[1.0]]))
        assert p2.rho.tolist() == [[1.0]]
github scikit-hep / awkward-array / tests / test_hdf5.py View on Github external
def test_read_write_hdf(tmpdir, input_arr):
    tmp_file = tmpdir / "example.h5"

    # Write
    with h5py.File(str(tmp_file), "w") as hf:
        a = awkward.JaggedArray.fromiter(input_arr)
        ah5 = awkward.hdf5(hf)
        ah5["example"] = a

    # Read
    with h5py.File(str(tmp_file)) as hf:
        ah5 = awkward.hdf5(hf)
        b = ah5["example"]

    assert a.tolist() == b.tolist()