Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

ENH: pad: implement more padding modes

オープン
#811 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
python
領域
data

調査の方向性

エントリポイント xpx.pad から始め、現在の定数モードのパスを NumPy のスライス代入実装 _arraypad_impl.py と比較します。期待されるエッジの挙動を確認するため、引用されている SciPy と scikit-image の呼び出し箇所を確認します。これらの使用例と一致する挙動で、汎用的かつ配列に依存しない mode="edge" のサポートを追加すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

enhancement help wanted

Currently, xpx.pad only implements mode="constant". However, mode="edge" is used, for example, in SciPy FFT and ndimage,

$ git grep -n mode=\'edge\'
scipy/fft/tests/test_real_transforms.py:40:    y2 = xp.asarray(np.pad(np.asarray(y), pad, mode='edge'))
scipy/fft/tests/test_real_transforms.py:111:    y2 = xp.asarray(np.pad(np.asarray(y), pad, mode='edge'))
scipy/ndimage/_interpolation.py:219:            padded = np.pad(input, npad, mode='edge')
scipy/signal/_short_time_fft.py:1096:            'edge': dict(mode='edge'),

also scikit-image:

$ git grep -n mode=\'edge\'
doc/examples/registration/plot_opticalflow.py:42:image1_warp = warp(image1, np.array([row_coords + v, col_coords + u]), mode='edge')
src/skimage/exposure/_adapthist.py:172:    map_array = np.pad(hist, [[1, 1] for _ in range(ndim)] + [[0, 0]], mode='edge')
src/skimage/filters/_fft_based.py:92:        ``mode='edge'`` extension.
src/skimage/filters/_fft_based.py:155:        image = np.pad(image, npad, mode='edge')
src/skimage/registration/_optical_flow.py:104:            moving_image, _get_warp_points(grid, flow_current), mode='edge'
src/skimage/registration/_optical_flow.py:324:            moving_image, _get_warp_points(grid, flow), mode='edge'
src/skimage/segmentation/_chan_vese.py:26:    P = np.pad(phi, 1, mode='edge')
src/skimage/segmentation/_chan_vese.py:95:    P = np.pad(phi, 1, mode='edge')
src/skimage/segmentation/boundaries.py:37:    windows = view_as_windows(np.pad(label_img_expanded, 1, mode='edge'), (3,) * ndim)
tests/skimage/registration/test_ilk.py:34:    image1 = warp(image0, grid - gt_flow, mode='edge')
tests/skimage/registration/test_tvl1.py:34:    image1 = warp(image0, grid - gt_flow, mode='edge')
tests/skimage/transform/test_warps.py:568:        x, out_size, order=1, mode='edge', anti_aliasing=True, anti_aliasing_sigma=sigma

A generic, array-agnostic edge mode seems doable, since the numpy's version is pretty much all slice assignments,
https://github.com/numpy/numpy/blob/main/numpy/lib/_arraypad_impl.py#L870-L874

Many array libraries implement it natively: jax.numpy.pad, cupy.pad, even dask. An odd one out is pytorch, which only has an equivalent functionality in torchvision IIUC, so a pytorch version could probably share the padding code with a "generic" version.

主要言語
Python
スター
33
フォーク
32
平均マージ
5時間 58分
マージ済み PR(30日)
47

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

data-apis/array-api-extra のほかの issue

data-apis/array-api-extra の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。