Skip to content

Fix affine() IndexError with boolean mask indexing#1547

Open
alinpahontu2912 wants to merge 1 commit intodotnet:mainfrom
alinpahontu2912:fix/affine-boolean-mask-indexing
Open

Fix affine() IndexError with boolean mask indexing#1547
alinpahontu2912 wants to merge 1 commit intodotnet:mainfrom
alinpahontu2912:fix/affine-boolean-mask-indexing

Conversation

@alinpahontu2912
Copy link
Member

@alinpahontu2912 alinpahontu2912 commented Feb 27, 2026

Fixes #1502

Replace img[mask] = fill_img[mask] with torch::where(mask, fill_img, img) in THSVision_ApplyGridTransform's Nearest-mode fill logic. The operator[] boolean mask indexing is not supported in recent LibTorch versions.

This fixes torchvision.transforms.functional.affine() and rotate() when called with a fill value and Nearest interpolation mode.

Replace img[mask] = fill_img[mask] with torch::where(mask, fill_img, img)
in THSVision_ApplyGridTransform's Nearest-mode fill logic. The operator[]
boolean mask indexing is not supported in recent LibTorch versions.

This fixes torchvision.transforms.functional.affine() and rotate() when
called with a fill value and Nearest interpolation mode.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@alinpahontu2912 alinpahontu2912 changed the title Fix affine() IndexError with boolean mask indexing (#1502) Fix affine() IndexError with boolean mask indexing Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

torchvision.transforms.functional.affine throws IndexError

1 participant