How to use the awkward.util.windows_safe 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 / awkward-array / awkward / array / jagged.py View on Github external
out = self.JaggedArray.fromoffsets(offsets, self.Table.named("tuple", i1, i2, i3, i4))
        elif n == 3:
            k3 = indices - offsets[parents]
            i3 = np.repeat(local, awkward.util.windows_safe(local*(local - 1)//2))
            k2 = k3 - i3*(i3 - 1)*(i3 - 2)//6
            i2 = root2(k2)
            k1 = k2 - i2*(i2 - 1)//2
            i1 = k1
            if absolute:
                starts_parents = self.starts[parents]
                for idx in [i1, i2, i3]:
                    idx += starts_parents
            out = self.JaggedArray.fromoffsets(offsets, self.Table.named("tuple", i1, i2, i3))
        elif n == 2:
            k2 = indices - offsets[parents]
            i2 = np.repeat(local, awkward.util.windows_safe(local))
            k1 = k2 - i2*(i2 - 1)//2
            i1 = k1
            if absolute:
                starts_parents = self.starts[parents]
                for idx in [i1, i2]:
                    idx += starts_parents
            out = self.JaggedArray.fromoffsets(offsets, self.Table.named("tuple", i1, i2))

        return out
github scikit-hep / awkward-array / awkward / array / jagged.py View on Github external
def startsstops2parents(cls, starts, stops):
        assert starts.shape == stops.shape
        starts = starts.reshape(-1)  # flatten in case multi-d jagged
        stops = stops.reshape(-1)
        dtype = cls.JaggedArray.fget(None).INDEXTYPE
        out = cls.numpy.full(stops.max(), -1, dtype=dtype)
        indices = cls.numpy.arange(len(starts), dtype=dtype)
        counts = stops - starts
        parents = cls.numpy.repeat(indices, awkward.util.windows_safe(counts))
        contiguous_offsets = cls.JaggedArray.fget(None).counts2offsets(counts)
        content_indices = cls.numpy.arange(contiguous_offsets[-1])
        content_indices -= cls.numpy.repeat(contiguous_offsets[:-1], awkward.util.windows_safe(counts))
        content_indices += starts[parents]
        cls.numpy.put(out, awkward.util.windows_safe(content_indices), parents)
        return out
github scikit-hep / awkward-array / awkward / array / jagged.py View on Github external
def offsets2parents(cls, offsets):
        dtype = cls.JaggedArray.fget(None).INDEXTYPE
        counts = cls.numpy.diff(cls.numpy.r_[dtype.type(0), offsets])  # numpy >= 1.16: diff prepend
        indices = cls.numpy.arange(-1, len(offsets) - 1, dtype=dtype)
        return cls.numpy.repeat(indices, awkward.util.windows_safe(counts))
github scikit-hep / awkward-array / awkward / array / jagged.py View on Github external
def startsstops2parents(cls, starts, stops):
        assert starts.shape == stops.shape
        starts = starts.reshape(-1)  # flatten in case multi-d jagged
        stops = stops.reshape(-1)
        dtype = cls.JaggedArray.fget(None).INDEXTYPE
        out = cls.numpy.full(stops.max(), -1, dtype=dtype)
        indices = cls.numpy.arange(len(starts), dtype=dtype)
        counts = stops - starts
        parents = cls.numpy.repeat(indices, awkward.util.windows_safe(counts))
        contiguous_offsets = cls.JaggedArray.fget(None).counts2offsets(counts)
        content_indices = cls.numpy.arange(contiguous_offsets[-1])
        content_indices -= cls.numpy.repeat(contiguous_offsets[:-1], awkward.util.windows_safe(counts))
        content_indices += starts[parents]
        cls.numpy.put(out, awkward.util.windows_safe(content_indices), parents)
        return out
github scikit-hep / awkward-array / awkward / array / jagged.py View on Github external
k4 = k5 - i5*(i5 - 1)*(i5 - 2)*(i5 - 3)*(i5 - 4)//120
            i4 = root4(k4)
            k3 = k4 - i4*(i4 - 1)*(i4 - 2)*(i4 - 3)//24
            i3 = root3(k3)
            k2 = k3 - i3*(i3 - 1)*(i3 - 2)//6
            i2 = root2(k2)
            k1 = k2 - i2*(i2 - 1)//2
            i1 = k1
            if absolute:
                starts_parents = self.starts[parents]
                for idx in [i1, i2, i3, i4, i5]:
                    idx += starts_parents
            out = self.JaggedArray.fromoffsets(offsets, self.Table.named("tuple", i1, i2, i3, i4, i5))
        elif n == 4:
            k4 = indices - offsets[parents]
            i4 = np.repeat(local, awkward.util.windows_safe(local*(local - 1)*(local - 2)//6))
            k3 = k4 - i4*(i4 - 1)*(i4 - 2)*(i4 - 3)//24
            i3 = root3(k3)
            k2 = k3 - i3*(i3 - 1)*(i3 - 2)//6
            i2 = root2(k2)
            k1 = k2 - i2*(i2 - 1)//2
            i1 = k1
            if absolute:
                starts_parents = self.starts[parents]
                for idx in [i1, i2, i3, i4]:
                    idx += starts_parents
            out = self.JaggedArray.fromoffsets(offsets, self.Table.named("tuple", i1, i2, i3, i4))
        elif n == 3:
            k3 = indices - offsets[parents]
            i3 = np.repeat(local, awkward.util.windows_safe(local*(local - 1)//2))
            k2 = k3 - i3*(i3 - 1)*(i3 - 2)//6
            i2 = root2(k2)
github scikit-hep / awkward-array / awkward / array / jagged.py View on Github external
k4 = indices - offsets[parents]
            i4 = np.repeat(local, awkward.util.windows_safe(local*(local - 1)*(local - 2)//6))
            k3 = k4 - i4*(i4 - 1)*(i4 - 2)*(i4 - 3)//24
            i3 = root3(k3)
            k2 = k3 - i3*(i3 - 1)*(i3 - 2)//6
            i2 = root2(k2)
            k1 = k2 - i2*(i2 - 1)//2
            i1 = k1
            if absolute:
                starts_parents = self.starts[parents]
                for idx in [i1, i2, i3, i4]:
                    idx += starts_parents
            out = self.JaggedArray.fromoffsets(offsets, self.Table.named("tuple", i1, i2, i3, i4))
        elif n == 3:
            k3 = indices - offsets[parents]
            i3 = np.repeat(local, awkward.util.windows_safe(local*(local - 1)//2))
            k2 = k3 - i3*(i3 - 1)*(i3 - 2)//6
            i2 = root2(k2)
            k1 = k2 - i2*(i2 - 1)//2
            i1 = k1
            if absolute:
                starts_parents = self.starts[parents]
                for idx in [i1, i2, i3]:
                    idx += starts_parents
            out = self.JaggedArray.fromoffsets(offsets, self.Table.named("tuple", i1, i2, i3))
        elif n == 2:
            k2 = indices - offsets[parents]
            i2 = np.repeat(local, awkward.util.windows_safe(local))
            k1 = k2 - i2*(i2 - 1)//2
            i1 = k1
            if absolute:
                starts_parents = self.starts[parents]
github scikit-hep / awkward-array / awkward / array / jagged.py View on Github external
def regular(self):
        self._valid()

        if len(self) > 0 and not (self.counts.reshape(-1)[0] == self.counts).all():
            raise ValueError("jagged array is not regular: different elements have different counts")
        count = self.counts.reshape(-1)[0]
        content = self._util_regular(self._content)

        if self._canuseoffset():
            out = content[self._starts[0]:self._stops[-1]]
            return out.reshape(self._starts.shape + (count,) + content.shape[1:])

        else:
            indexes = self.numpy.repeat(self._starts, awkward.util.windows_safe(count)).reshape(self._starts.shape + (count,))
            indexes += self.numpy.arange(count)
            return content[indexes]