Skip to content

BUG: searchsorted: needs to broadcast batch shapes #1014

Open

Description

@mdhaber

Ran into this in scipy/scipy#26324:

import numpy as np
from scipy._external import array_api_extra as xpx

rng = np.random.default_rng(2398198374572881)
shape_1d = (5,)
shape_2d = (2, 5)

x = np.sort(rng.random(shape_1d), axis=-1)
y = rng.random(shape_2d)
xpx.searchsorted(x, y)  # OK

x = np.sort(rng.random(shape_2d), axis=-1)
y = rng.random(shape_1d)
xpx.searchsorted(x, y)  # not OK
# ValueError: input operand has more dimensions than allowed by the axis remapping

My workaround there was to broadcast the batch shapes (e.g. batch_shape = xp.broadcast_shapes(x1.shape[:-1], x2.shape[:-1])) and reshape the arguments accordingly.

Activity

  1. lucascolley commented on Oct 7, 2026

    @lucascolley
    Member

    PR welcome

  2. nightcityblade commented on Oct 13, 2026

    @nightcityblade
    Contributor

    Hi, I'd like to work on this. I'll submit a PR shortly.

  3. changed the title [-]`searchsorted` needs to broadcast batch shapes[/-] [+]BUG: searchsorted: needs to broadcast batch shapes[/+] on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions