8000
Skip to content

feat(python): support N-D nk.scale - #376

Open
ternaus wants to merge 1 commit into
ashvardanian:mainfrom
ternaus:agent/nd-scale
Open

feat(python): support N-D nk.scale#376
ternaus wants to merge 1 commit into
ashvardanian:mainfrom
ternaus:agent/nd-scale

Conversation

@ternaus
@ternaus ternaus commented Aug 8, 2026
Copy link
Copy Markdown
Contributor

Summary

  • Allow nk.scale to accept shape-preserving N-D buffers through the existing stride walker.
  • Cover direct HWC and NHWC calls, out=, in-place out=input, and strided HWC inputs.
  • Keep out= C-contiguous and same-dtype, consistent with the existing vector contract.

Why

Callers can now scale images and batches directly, without flattening an input buffer and reshaping the result in Python. This is an API and readability improvement; it intentionally preserves the existing native kernel and has no performance claim.

Benchmark

Apple arm64, NumKong 7.8.0, NumPy 2.4.4, median of 151 interleaved samples:

Layout Shape Mode Direct N-D Flattened vector Ratio
HWC (1080, 1920, 3) Allocate 3.0835 ms 3.0875 ms 0.999x
HWC (1080, 1920, 3) out= 1.5992 ms 1.6027 ms 0.998x
NHWC (4, 512, 512, 3) Allocate 1.4510 ms 1.4935 ms 0.972x
NHWC (4, 512, 512, 3) out= 0.8553 ms 0.8610 ms 0.993x

Validation

  • PYTHONPATH=python python -m pytest test/test_each.py -q — 46,696 passed.

Closes #327.

@ternaus
ternaus marked this pull request as ready for review August 8, 2026 06:26
Accept shape-preserving HWC and NHWC buffers without flattening them in Python.
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.

Feature: Shape-preserving N-D nk.scale with documented integer rounding

1 participant

0