Skip to content

Inconsistent return types of map when applied to Memory #56962

@frankwswang

Description

@frankwswang

MWE (on Julia 1.11.2):

julia> a = Memory{Int}([1, 2])
2-element Memory{Int64}:
 1
 2

julia> b = Memory{Int}([3, 4])
2-element Memory{Int64}:
 3
 4

julia> map(x->(x,), a)
2-element Memory{Tuple{Int64}}:
 (1,)
 (2,)

julia> map((x, y)->(x, y), a, b)
2-element Vector{Tuple{Int64, Int64}}:
 (1, 3)
 (2, 4)

julia> map((x, y, z)->(x, y+1, z), a, a, b)
2-element Vector{Tuple{Int64, Int64, Int64}}:
 (1, 2, 3)
 (2, 3, 4)

For iterations over one Memory object, the returned value of map remains a Memory. However, when iterating over multiple Memory objects, the returned type falls back to Vector. Personally, I think the return type should remain Memory for all situations when calling map since we already have a type conversion for direct broadcast on Memory:

julia> a .+ b
2-element Vector{Int64}:
 4
 6

julia> a .+ 1
2-element Vector{Int64}:
 2
 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions