Fix mapreduce type-stability on Julia 1.10 using @generated functions#499
Merged
ChrisRackauckas merged 8 commits intoSciML:masterfrom Dec 14, 2025
Merged
Conversation
A function similar to what is implemented commit 2094a78 but for NamedArrayPartitions rather than ArrayPartitions. Tested privately to work with Implicit solvers in OrdinaryDiffEq.jl
NamedArrayPartition zeromatrix
- Use @generated functions (_mapreduce_impl and _mapreduce_impl_init) to ensure type-stable mapreduce for ArrayPartition on Julia 1.10 - The generated approach unrolls the tuple iteration at compile time, avoiding type inference issues with kwargs that affected Julia 1.10 - Preserves correct `init` parameter semantics (init applied once at outer level) - Add missing ArrayInterface import in named_array_partition_tests.jl This fixes the type inference failure where Julia 1.10 would infer `Any` instead of the correct concrete return type for mapreduce operations on nested ArrayPartitions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
This PR fixes the type-stability issue in
mapreduceforArrayPartitionon Julia 1.10 that was blocking PR #444.Problem
The
mapreducefunction was not type-stable on Julia 1.10. The issue was caused by type inference problems with kwargs and closures in generator expressions. While Julia 1.11 handled this correctly, Julia 1.10 would inferAnyinstead of the concrete return type.Solution
@generatedfunctions (_mapreduce_impland_mapreduce_impl_init) to unroll the tuple iteration at compile timeinitparameter semantics (init applied once at the outer level, not per-partition)Additional Fix
ArrayInterfaceimport intest/named_array_partition_tests.jlTest Results
Test plan
Pkg.test()on Julia 1.10Pkg.test()on Julia 1.11@inferred sum(ArrayPartition(ArrayPartition(zeros(4,4))))returnsFloat64🤖 Generated with Claude Code