Repository navigation
Validate block sizes in depth-space transforms - #155
Open
sylvesterkaczmarek wants to merge 1 commit into
Open
sylvesterkaczmarek wants to merge 1 commit into
sylvesterkaczmarek wants to merge 1 commit into
Conversation
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.
Fixes #154.
Problem
depth_to_spaceandspace_to_depthdocument a block size of at least 2, but accept values that violate this contract. A zero value reaches integer division and raisesZeroDivisionError; negative values fail during JAX reshaping; and a size of 1 is silently interpreted as an identity operation. Floating-point and boolean block sizes similarly bypass consistent validation. These errors also arise for batched inputs, where the functions map themselves over images.Change
Introduce one shared block-size validator and call it before shape arithmetic or batching. Accept Python and NumPy integer values of at least 2. Reject booleans, fractions, zero and negative values with a clear
ValueErroridentifyingblock_size.For four-dimensional inputs, capture the already validated Python integer in the
jax.vmapclosure. This avoids converting it into a traced scalar when the per-image function is called recursively, and preserves shape inference for JIT-compiled batches.Verification
master, 16 invalid-input regression cases fail: seven invalid sizes for each function and two batched cases.git diff --checkpass.Scope and limitations
The tensor rearrangement formula, output shape for valid sizes and ordering of pixels are unchanged. The new validation concerns the documented Python integer argument, which must be static for JIT shape construction. TensorFlow-dependent test modules were not executed locally.