Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

This PR fixes the type-stability issue in mapreduce for ArrayPartition on Julia 1.10 that was blocking PR #444.

Problem

The mapreduce function 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 infer Any instead of the concrete return type.

Solution

  • Use @generated functions (_mapreduce_impl and _mapreduce_impl_init) to unroll the tuple iteration at compile time
  • This avoids the type inference issues with kwargs that affected Julia 1.10
  • Preserves correct init parameter semantics (init applied once at the outer level, not per-partition)

Additional Fix

  • Added missing ArrayInterface import in test/named_array_partition_tests.jl

Test Results

  • Julia 1.10: All tests pass ✅
  • Julia 1.11: All tests pass ✅

Test plan

  • Run Pkg.test() on Julia 1.10
  • Run Pkg.test() on Julia 1.11
  • Verify @inferred sum(ArrayPartition(ArrayPartition(zeros(4,4)))) returns Float64

🤖 Generated with Claude Code

ChrisRackauckas and others added 8 commits May 9, 2025 07:55
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
- 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>
@ChrisRackauckas ChrisRackauckas merged commit 84d9be5 into SciML:master Dec 14, 2025
17 of 25 checks passed
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