Skip to content

Optimized reduce(vcat, xs) and reduce(hcat, xs) for xs being any iterator #31636

@oxinabox

Description

@oxinabox

We should extend #21672
for all iterators, in so far as is possible.

That way people would not run into surprises
when they do reduce(hcat, filter(x->x[1]>5, xs))
or reduce(vcat, (vec(sum(abs2, xs; dim=2)) for x in xs) etc

Because right now the performance of those kind of things is worse than splatting.
and it is really annoying having to be so careful about your types when writing code.

Likely any PR to solve this would also solve #31169
just because that one makes writing tests for correctness of behavior annoying

Fixing this for generators
would allow solving the mapreduce(vcat/hcat problem in #31137
(and its generalization to nonarrays,)
since
we could have mapreduce(f, vcat, xs) = reduce(vcat, f(x) for x in xs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    foldsum, maximum, reduce, foldl, etc.performanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions