BUG: searchsorted: needs to broadcast batch shapes

未關閉
#1,014 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@nightcityblade 已經在處理了。

開始於 2026年10月13日。

  • #1024 來自 @nightcityblade —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
56/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
python
領域
backend

研究方向

Start by locating the searchsorted implementation and its tests; the issue provides a reproducer for the failing case where x has shape (2, 5) and y has shape (5,). Read how the function handles batch dimensions, then run the relevant tests with this case. Done means the batch shapes broadcast and the call succeeds with the expected indices.

由索引模型根據 Issue 內容生成。

描述

bug

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.

主要語言
Python
星號
34
分支
35
平均合併
5 小時 49 分鐘
30 天內合併 PR
58

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

data-apis/array-api-extra 的其他 Issue

查看 data-apis/array-api-extra 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。