-
Notifications
You must be signed in to change notification settings - Fork 24
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
Transducers improperly promotes elements on reduction #524
Comments
collect
A perhaps more explicit example: ◖◗ x = ([1, 2], [1.0, 2.0]);
◖◗ collect(x)
2-element Vector{Vector}:
[1, 2]
[1.0, 2.0]
◖◗ x |> Map(identity) |> collect
2-element Vector{Vector{Float64}}:
[1.0, 2.0]
[1.0, 2.0] Apparently everything based on Transducers including ThreadsX is promoting its elements. Not sure how long it's been going on or how I didn't notice it before. It's a bit scary, if you don't want this behavior your options for threads are reduced to |
collect
I'm having the same problem implementing a new feature of TableTransforms.jl: JuliaML/TableTransforms.jl#96. |
FYI you can work around this by wrapping arguments in |
Yeah, the real issue is JuliaFolds/BangBang.jl#230 and the non- Meanwhile, it's not difficult to define your own julia> function conservative_append!!(xs, ys)
if eltype(ys) <: eltype(xs)
append!(xs, ys)
xs
else
zs = similar(
xs,
Base.promote_typejoin(eltype(xs), eltype(ys)),
length(xs) + length(ys),
)
copyto!(view(zs, 1:length(xs)), xs)
copyto!(view(zs, length(xs)+1:length(zs)), ys)
zs
end
end;
julia> using MicroCollections: EmptyVector, SingletonVector
julia> my_collect(xs) =
xs |>
Map(x -> SingletonVector((x,))) |>
foldxt(conservative_append!!; init = EmptyVector()); (This is not OffsetArray-correct but it's straightforward to support non-base-1 vectors) This produces a result similar to julia> function mwe()
v = ([1.0, 2.0], [3, 4])
1:2 |> Map(i -> v[i]) |> my_collect
end;
julia> mwe()
2-element Vector{Vector}:
[1.0, 2.0]
[3, 4]
julia> let v = ([1.0, 2.0], [3, 4])
collect(v[i] for i in 1:2)
end
2-element Vector{Vector}:
[1.0, 2.0]
[3, 4] Perhaps a smaller MWE is julia> tcollect(x for x in Any[1, 2.0]) # aggressive promotion (similar to `vcat` and broadcasting)
2-element Vector{Float64}:
1.0
2.0
julia> my_collect(x for x in Any[1, 2.0]) # conservative promotion (similar to `collect`)
2-element Vector{Real}:
1
2.0
julia> collect(x for x in Any[1, 2.0])
2-element Vector{Real}:
1
2.0 |
gives
For whatever reason it seems to want to promote the second element.
The text was updated successfully, but these errors were encountered: