Skip to content

Join chunk element types in ChainedVector map like Base's map - #139

Open
quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/chainedvector-map-eltype
Open

quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/chainedvector-map-eltype

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Why

A ChainedVector should give the same answers as the same data in a Vector. map mapped each chunk and then joined the chunks with numeric promotion. When the chunks produced different element types, values were converted, which can lose precision. The result eltype also differed from Base's map, which joins types without converting:

julia> map(x -> x == 1 ? 0.5 : x, ChainedVector([[1], [2^60 + 1]]))
2-element ChainedVector{Float64, Vector{Float64}}:
 0.5
 1.152921504606847e18     # Vector gives 1152921504606846977 in a Vector{Real}

map on a ChainedVector with no chunks also threw MethodError when Julia could not infer the mapped chunk type.

What changed

  • map joins the chunk eltypes with Base.promote_typejoin, the rule Base's map uses for element types, and converts only to that joined type.
  • With no chunks, map maps an empty Vector{T} to get Base's result eltype.

Scope

  • Chunks whose results already share one eltype keep the same result as before.

Blast radius

Code that relied on map promoting mixed Int and Float chunks to Float64 now gets the same eltype as map over a Vector.

Verification

🤖 Generated with Claude Code

quinnj and others added 2 commits November 18, 2026 23:30
Fails on main; passes with the next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
map promoted chunks with different result eltypes with promote_type,
which converts Int to Float64 and can lose precision, while Base's map
joins element types. Join chunk eltypes with Base.promote_typejoin and
convert only to that type. With no chunks, map an empty Vector{T} so
the result eltype matches Base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quinnj-bot
quinnj-bot Bot force-pushed the claude/chainedvector-map-eltype branch from da386b2 to a140a75 Compare November 19, 2026 06:32
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.

1 participant