fix(ops): fix convolve padRight for even kernels in same mode - #467
Merged
davidkoski merged 2 commits intoSep 14, 2026
Merged
davidkoski merged 2 commits into
davidkoski merged 2 commits into
Conversation
Author
|
Hi @davidkoski — Friendly ping on this PR when you get a chance. It fixes convolution right-padding calculation for even kernel sizes under 'same' mode. Tests pass cleanly. Thanks! |
davidkoski
approved these changes
Sep 11, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Nice! I realized I just found the same issue in #478
Just waiting on CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
Resolves #466.
Fixes right-side padding calculation in
convolve(_:_:mode:stream:)(Source/MLX/Ops.swift) for.samemode when the kernel length is even.Root Cause
Previously, when the weight size was even,
padRightwas computed asmax(0, padLeft / 2 - 1)instead ofmax(0, padLeft - 1). For example, withpadLeft = 2(kernel size 4),padRightincorrectly evaluated to0instead of1, causing the input to be under-padded and the output length for.samemode to be truncated by 1 element.This change aligns the calculation with the MLX C++ / Python implementation (
int pad_r = std::max(0, pad_l - 1)).Tests
Added
testConvolve()inTests/MLXTests/OpsTests.swifttesting.full,.valid, and.samemode outputs with both even and odd kernel sizes.Checklist