Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent return types of map when applied to Memory #56962

Open
frankwswang opened this issue Jan 5, 2025 · 0 comments
Open

Inconsistent return types of map when applied to Memory #56962

frankwswang opened this issue Jan 5, 2025 · 0 comments
Labels
arrays [a, r, r, a, y, s]

Comments

@frankwswang
Copy link

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
@nsajko nsajko added the arrays [a, r, r, a, y, s] label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s]
Projects
None yet
Development

No branches or pull requests

2 participants