Skip to content

fix: keep the last accumulated value in scan (#356) - #368

Merged
devcrocod merged 2 commits into
developfrom
fix/scan-drops-last-value
Nov 13, 2026
Merged

devcrocod merged 2 commits into
developfrom
fix/scan-drops-last-value

Conversation

@devcrocod

Copy link
Copy Markdown
Collaborator

scan, scanIndexed and scanMultiIndexed return all size + 1 values instead of cutting the result to the source shape, and scanIndexed passes indices from 0. The result is always 1D, so scan and scanMultiIndexed now return D1Array<R> instead of NDArray<R, D> (source-incompatible for D > 1).

Fixes #356

Testing

  • :multik-core:jvmTest; IterableNDArrayTest and doc samples on macosArm64; new tests on JS (node)
  • apiCheck korroCheck

Checklist

  • Existing tests pass
  • New/updated tests for changed behavior
  • New/updated documentation if necessary

scan, scanIndexed and scanMultiIndexed return all size + 1 values, and
scanIndexed passes indices from 0. scan and scanMultiIndexed now return
D1Array<R> instead of NDArray<R, D>.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 16:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The source-incompatible return-type changes to scan and scanMultiIndexed for multidimensional callers require maintainer confirmation that the API break and its release and migration handling are acceptable.

No open issues 🎉

What changed in this PR

Fixes #356 in Multik’s scan operations by preserving the final accumulated value and using zero-based indices in scanIndexed.

Changes:

  • All scan variants return all size + 1 values as a 1D array. The return-type changes to scan and scanMultiIndexed are source-incompatible for multidimensional callers.
  • Adds regression tests for accumulation, indexing, transposed views, and empty arrays.
  • Updates KDoc, API documentation, and matching code samples.
File Description
multik-core/​src/​commonTest/​kotlin/​samples/​docs/​apiDocs/​arrayOperations.kt Adds indexed and multidimensional scan examples.
multik-core/​src/​commonTest/​kotlin/​org/​jetbrains/​kotlinx/​multik/​iterable/​IterableNDArrayTest.kt Adds assertions covering corrected scan behavior and edge cases.
multik-core/​src/​commonMain/​kotlin/​org/​jetbrains/​kotlinx/​multik/​ndarray/​operations/​IteratingNDArray.kt Fixes result shapes and indexing; documents the updated contracts.
docs/​topics/​apiDocs/​scan.md Updates signatures, result semantics, and synchronized examples.

Review effort: Balanced

@devcrocod
devcrocod merged commit b747cfd into develop Nov 13, 2026
2 checks passed
@devcrocod
devcrocod deleted the fix/scan-drops-last-value branch November 13, 2026 16:25
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.

scan drops the last accumulated value

2 participants