Skip to content

ak.min/max/argmin/argmax do not work on axis=1 for the jax backend if the last element of an input ListOffsetArray is empty #3456

Open
@ikrommyd

Description

@ikrommyd

Example:

import awkward as ak
ak.jax.register_and_check()

ak.min(ak.Array([[1, 2], []], backend="cpu"), axis=1) #works
ak.min(ak.Array([[1, 2], []], backend="jax"), axis=1) #errors

All ak.min/max/argmin/argmax are going to give you

File ~/Dropbox/work/coffea_dev/awkward/src/awkward/contents/listoffsetarray.py:1618, in ListOffsetArray._reduce_next(self, reducer, negaxis, starts, shifts, parents, outlength, mask, keepdims, behavior)
   1615 trimmed = self._content[self.offsets[0] : self.offsets[-1]]
   1616 nextstarts = self.offsets[:-1]
-> 1618 outcontent = trimmed._reduce_next(
   1619     reducer,
   1620     negaxis,
   1621     nextstarts,
   1622     shifts,
   1623     nextparents,
   1624     globalstarts_length,
   1625     mask,
   1626     keepdims,
   1627     behavior,
   1628 )
   1630 outoffsets = Index64.empty(outlength + 1, nplike)
   1631 assert outoffsets.nplike is nplike and parents.nplike is nplike

File ~/Dropbox/work/coffea_dev/awkward/src/awkward/contents/numpyarray.py:1155, in NumpyArray._reduce_next(self, reducer, negaxis, starts, shifts, parents, outlength, mask, keepdims, behavior)
   1139     assert (
   1140         outmask.nplike is self._backend.nplike
   1141         and parents.nplike is self._backend.nplike
   1142     )
   1143     self._backend.maybe_kernel_error(
   1144         self._backend[
   1145             "awkward_NumpyArray_reduce_mask_ByteMaskedArray_64",
   (...)   1153         )
   1154     )
-> 1155     out = ak.contents.ByteMaskedArray(outmask, out, False, parameters=None)
   1157 if keepdims:
   1158     out = ak.contents.RegularArray(out, 1, self.length, parameters=None)

File ~/Dropbox/work/coffea_dev/awkward/src/awkward/contents/bytemaskedarray.py:140, in ByteMaskedArray.__init__(self, mask, content, valid_when, parameters)
    131     raise TypeError(
    132         f"{type(self).__name__} 'valid_when' must be boolean, not {valid_when!r}"
    133     )
    134 if (
    135     content.backend.nplike.known_data
    136     and mask.length is not unknown_length
    137     and content.length is not unknown_length
    138     and mask.length > content.length
    139 ):
--> 140     raise ValueError(
    141         f"{type(self).__name__} len(mask) ({mask.length}) must be <= len(content) ({content.length})"
    142     )
    144 assert mask.nplike is content.backend.nplike
    146 self._mask = mask

ValueError: ByteMaskedArray len(mask) (2) must be <= len(content) (1)

This error occurred while calling

    ak.min(
        <Array [[1, 2], []] type='2 * var * int64'>
        axis = 1
    )

caused through the reduce_next call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThe problem described is something that must be fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions