Repository navigation
fix: reified groupNDArrayBy values and empty chunked/windowed (#221) - #362
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The acknowledged compatibility breaks for Java, non-reified generic callers, and prebuilt klibs require explicit maintainer acceptance.
No open issues 🎉
What changed in this PR
This follow-up to #357 addresses #221 by improving dtype inference and empty-array handling in Multik’s collection-style operations.
Changes:
- Uses reified grouping value types to preserve dtypes on JS, with runtime inference for abstract types when elements are available.
- Returns
(0, 0)arrays for emptychunkedandwindowedinput and improves empty-constructor errors. - Adds regression tests and synchronizes documentation and the API dump.
| File | Description |
|---|---|
multik-core/src/commonTest/kotlin/org/jetbrains/kotlinx/multik/ndarray/data/ErrorHandlingTest.kt |
Checks shape details in empty-constructor errors. |
multik-core/src/commonTest/kotlin/org/jetbrains/kotlinx/multik/iterable/IterableNDArrayTest.kt |
Adds dtype and empty-input regressions; standardizes affected test names. |
multik-core/src/commonMain/kotlin/org/jetbrains/kotlinx/multik/ndarray/operations/IteratingNDArray.kt |
Updates dtype inference and handles empty windows. |
multik-core/src/commonMain/kotlin/org/jetbrains/kotlinx/multik/api/constructors.kt |
Makes empty-collection errors more actionable. |
multik-core/api/multik-core.api |
Records removal of two grouping signatures from the API dump. |
docs/topics/apiDocs/groupNDArray.md |
Documents the reified grouping value type. |
docs/topics/apiDocs/flatMap.md |
Corrects result-type bounds and multidimensional signatures. |
Review effort: Balanced
- groupNDArrayBy/groupNDArrayByTo with valueTransform take a reified V, so the dtype comes from V instead of the first value's runtime class, which is Int for a whole-valued Double on JS. - flatMap* and groupNDArrayBy* fall back to the runtime class when the element type is abstract (Number, Any), as before #357. - chunked/windowed return an empty (0, 0) array on empty input instead of dividing by zero. - ndarrayCommon names the shape and the alternatives when it cannot infer the dtype of an empty collection. - Sync the flatMap and groupNDArrayBy signatures in the docs, rename the #357 tests to testXxx and update the API dump.
devcrocod
force-pushed
the
fix/221-followup
branch
from
October 29, 2026 15:47
e347b56 to
5cd9a7c
Compare
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.
Follow-up to #357. Fixes #221.
groupNDArrayBy/groupNDArrayByTowithvalueTransform. The dtype came from the first value's runtime class, and on JS a whole-valuedDouble(and anyByte,ShortorFloat) is anIntat runtime.Vis now reified and the dtype comes from it.flatMap*(since fix: preserve array dtype on empty filter and transform operations (#221) #357) and the reifiedgroupNDArrayBy*threwIllegalStateExceptionforNumberorAny, even on empty input. A sharedinferDataTypehelper takes the dtype from the static type when it names one, and otherwise from the first element, as before fix: preserve array dtype on empty filter and transform operations (#221) #357.chunked/windowedon empty input threwArithmeticException: / by zero. They now return an empty(0, 0)array; the window width is clamped to the element count, as it is for short arrays.ndarrayCommon: the error for an empty collection without a dtype is now arequirethat names the shape and suggeststoNDArray()ormk.zeros<T>(...).flatMap.mdandgroupNDArray.md. Tests from fix: preserve array dtype on empty filter and transform operations (#221) #357 renamed totestXxxper CONTRIBUTING.md, with an unused import and lambda parameter removed.API changes
multik-core.apiloses two lines, because reified inline functions compile to private methods:Vis a non-reified type parameter no longer compiles ("Cannot use 'V' as reified type parameter"), andgroupNDArrayByTonow requiresV : Any. These are the same rules as formap,flatMapandscan.Release notes
chunked,windowedand the operations fixed in fix: preserve array dtype on empty filter and transform operations (#221) #357 return empty arrays on empty input instead of throwing.mk.ndarray(elements: Collection<T>, …)on an empty collection throwsIllegalArgumentException(wasNoSuchElementException).groupNDArrayBy/groupNDArrayByTowithvalueTransformtake a reifiedV(see API changes).Testing
:multik-core:jvmTest, 689 tests, 0 failures.:multik-core:macosArm64Test, 674 tests, 0 failures.jsNodeTestwas run locally with the Node test task enabled:IterableNDArrayTest48/48,ErrorHandlingTest8/8. Before the fix, the existingtest_groupNDArrayByand the newtestGroupNDArrayByValueTransformDtypefailed on JS (IntDataTypeinstead ofDoubleDataType).apiCheckandkorroCheckpass.Checklist