How to use the awkward1.forms function in awkward1

To help you get started, we’ve selected a few awkward1 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 CoffeaTeam / coffea / coffea / nanoevents / factory.py View on Github external
def _nestedindex(self, indexers, name):
        def nestedindex():
            # idx = awkward1.concatenate([idx[:, None] for idx in indexers], axis=1)
            n = len(indexers)
            out = numpy.empty(n * len(indexers[0]), dtype="int64")
            for i, idx in enumerate(indexers):
                out[i::n] = idx
            offsets = numpy.arange(0, len(out) + 1, n, dtype=numpy.int64)
            return awkward1.layout.ListOffsetArray64(
                awkward1.layout.Index64(offsets), awkward1.layout.NumpyArray(out),
            )

        form = awkward1.forms.Form.fromjson(
            '{"class": "ListOffsetArray64", "offsets": "i64", "content": "int64"}'
        )
        generator = awkward1.layout.ArrayGenerator(
            nestedindex, (), {}, form=form, length=indexers[0].generator.length,
        )
        return awkward1.layout.VirtualArray(
            generator,
            self._cache,
            cache_key="/".join([self._keyprefix, "nestedindex", name]),
        )
github CoffeaTeam / coffea / coffea / nanoaod / nanoawkward1.py View on Github external
def _array(self, branch_name: bytes):
        interpretation = uproot.interpret(self._tree[branch_name])
        if isinstance(interpretation, uproot.asjagged):
            dtype = interpretation.content.type
            length = None
        else:
            dtype = interpretation.type
            length = len(self)
        form = awkward1.forms.Form.fromjson('"%s"' % dtype)
        generator = awkward1.layout.ArrayGenerator(
            self.reader, (branch_name,), {}, form=form, length=length,
        )
        return awkward1.layout.VirtualArray(
            generator,
            self._cache,
            cache_key="/".join([self._keyprefix, "file", branch_name.decode("ascii")]),
            parameters={"__doc__": self._tree[branch_name].title.decode("ascii"),},
        )
github CoffeaTeam / coffea / coffea / nanoaod / nanoawkward1.py View on Github external
mixin = self._mixin_map.get(name, "NanoCollecton")
            if "n" + name in arrays:
                # list collection
                cname = "n" + name
                counts = arrays[cname]
                content = {
                    k[len(cname) :]: arrays[k]
                    for k in arrays
                    if k.startswith(name + "_")
                }
                recordparams = {
                    "__doc__": counts.parameters["__doc__"],
                    "__record__": mixin,
                    "events_key": self._keyprefix,
                }
                form = awkward1.forms.ListOffsetForm(
                    "i32",
                    awkward1.forms.RecordForm(
                        {k: v.form for k, v in content.items()}, parameters=recordparams
                    ),
                )
                generator = awkward1.layout.ArrayGenerator(
                    self._listarray,
                    (counts, content, recordparams),
                    {},
                    form=form,
                    length=len(self),
                )
                return awkward1.layout.VirtualArray(
                    generator,
                    self._cache,
                    cache_key="/".join([self._keyprefix, "file", name]),
github CoffeaTeam / coffea / coffea / nanoevents / factory.py View on Github external
self._cache,
                    cache_key="/".join([self._keyprefix, source, name]),
                    parameters=recordparams,
                )
            elif "o" + name in arrays:
                # list singleton
                offsets = arrays["o" + name]
                content = arrays[name]
                params = {
                    # This makes more sense as offsets doc but it seems that is empty
                    "__doc__": content.parameters["__doc__"],
                    "__array__": mixin,
                    "events_key": self._keyprefix,
                    "collection_name": name,
                }
                form = awkward1.forms.ListOffsetForm(
                    "i32", content.form, parameters=params
                )
                generator = awkward1.layout.ArrayGenerator(
                    self._listarray,
                    (offsets, content, params),
                    {},
                    form=form,
                    length=len(self),
                )
                source = "runtime"
                return awkward1.layout.VirtualArray(
                    generator,
                    self._cache,
                    cache_key="/".join([self._keyprefix, source, name]),
                    parameters=params,
                )
github CoffeaTeam / coffea / coffea / nanoevents / factory.py View on Github external
def _array(self, branch_name):
        interpretation = uproot.interpret(self._tree[branch_name])
        if isinstance(interpretation, uproot.asjagged):
            dtype = interpretation.content.type
            length = None
        else:
            dtype = interpretation.type
            length = len(self)
        parameters = {
            "__doc__": self._tree[branch_name].title.decode("ascii"),
            "__record__": "NanoColumn",
        }
        # use hint to resolve platform-dependent format
        formhint = awkward1.forms.Form.fromjson('"%s"' % dtype)
        form = awkward1.forms.NumpyForm(
            [], formhint.itemsize, formhint.format, parameters=parameters
        )
        generator = awkward1.layout.ArrayGenerator(
            self.reader, (branch_name, parameters), {}, form=form, length=length,
        )
        source = "file"
        return awkward1.layout.VirtualArray(
            generator,
            self._cache,
            "/".join([self._keyprefix, source, branch_name]),
            parameters=parameters,
        )