Skip to content

Update object detector input array creation to use span#93

Merged
tjia1818 merged 1 commit into
apple:mainfrom
kevchengcodes:mutableview_fix
Jul 9, 2026
Merged

Update object detector input array creation to use span#93
tjia1818 merged 1 commit into
apple:mainfrom
kevchengcodes:mutableview_fix

Conversation

@kevchengcodes

Copy link
Copy Markdown
Contributor

Summary

Update buildInputNDArray to acquire the mutable view outside the preprocessing loop

This reworks ObjectDetector.buildInputNDArray to obtain the input NDArray's mutable storage once via mutableView(...).contiguousElements before the per-image loop, then index the resulting bounds-checked MutableSpan to write each image into its [3, H, W] batch slot.

This is safer because it drops the raw UnsafeMutablePointer arithmetic and baseAddress! force-unwrap, and treats a non-contiguous buffer (where contiguousElements is nil) as an explicit error instead of silently mis-indexing. Behavior is unchanged — each image still lands in its correct batch slot with no B3H*W intermediate buffer.

@tjia1818 tjia1818 merged commit f9e9357 into apple:main Jul 9, 2026
3 checks passed
@kevchengcodes kevchengcodes deleted the mutableview_fix branch July 10, 2026 16:54
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.

3 participants