`BSplineFieldTransform.to_field()` reuses the weights of its first reference
評価
- 難易度
- 3/5
- 見積もり時間
- 半日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
The bug is in BSplineFieldTransform.to_field() in nitransforms/nonlinear.py, which caches B-spline weights on the first call and reuses them. Start by reading that method and its cache, then run the reproduction script from the issue to confirm the stale deltas and the broadcast ValueError on the smaller reference. Done when to_field() recomputes weights for each reference and both the shifted and smaller-grid cases produce correct fields.
索引モデルが issue の本文から書いたものです。
説明
to_field() computes the B-spline weights for its reference on the first call and caches them. Later calls reuse those weights whatever reference they are given.
Reproduction
import nibabel as nb
import numpy as np
from nitransforms.base import ImageGrid
from nitransforms.nonlinear import BSplineFieldTransform
def centered_grid(linear, shape):
"""Affine for a grid of given shape, centered at the origin, with given linear part"""
affine = nb.affines.from_matvec(linear, -linear @ (np.array(shape) - 1) / 2)
return nb.Nifti1Image(np.zeros(shape), affine)
# A 10 mm lattice of 10 x 10 x 10 knots, centered at the origin
knots = ImageGrid(centered_grid(np.eye(3) * 10, (10, 10, 10)))
# Set coefficient to RAS position, which is linear and so exactly representable
coeffs = knots.ndcoords.reshape(10, 10, 10, 3).astype("float32")
xfm = BSplineFieldTransform(nb.Nifti1Image(coeffs, knots.affine))
first = centered_grid(np.eye(3) * 3, (11, 11, 11))
shifted = nb.Nifti1Image(first.dataobj, nb.affines.from_matvec(np.eye(3) * 3, [-10, -12, -14]))
xfm.to_field(reference=first)
field = xfm.to_field(reference=shifted)
assert np.allclose(field._deltas.reshape(-1, 3), ImageGrid(shifted).ndcoords, atol=1e-3)
A smaller reference fails outright:
xfm.to_field(reference=centered_grid(np.eye(3) * 3, (5, 5, 5)))
ValueError: could not broadcast input array from shape (1331,) into shape (125,)
- 主要言語
- Python
- スター
- 36
- フォーク
- 18
- 平均マージ
- 1時間 24分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nipy/nitransforms のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nipy/nitransforms#307 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nipy/nitransforms#306 ·
-
難易度 3/5 半日 初心者へのやさしさ 25/100
nipy/nitransforms#305 ·
-
`BSplineFieldTransform` ignores `order`対応中かも @effigies が 1 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
nipy/nitransforms#302 ·
-
`BSplineFieldTransform.to_field()` ignores the orientation of the reference grid対応中かも @effigies が 1 日前に担当しました。 オープン
難易度 3/5 半日 初心者へのやさしさ 45/100
nipy/nitransforms#300 ·
nipy/nitransforms の issue をすべて見る
似ている issue
-
eegprep-lean: set channel types from the Zarr group's channel_type対応中かも @claude が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
blacklanternsecurity/bbot#3679 ·
メンテナーはふだん 2 日以内に返信
-
Link Checker ReportオープンBot Type: Bug Type: Documentation
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
speakeasy-api/speakeasy#2159 ·
メンテナーはふだん 1 日以内に返信