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

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

Open
oxinabox opened this issue Apr 6, 2019 · 2 comments
Open
Labels
fold sum, maximum, reduce, foldl, etc. performance Must go faster

Comments

@oxinabox
Copy link
Contributor

oxinabox commented Apr 6, 2019

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)

@oxinabox oxinabox changed the title Optimized reduce(vcat, xs) and reduce(hcat, xs) for nonarrays Optimized reduce(vcat, xs) and reduce(hcat, xs) for xs being any iterator Apr 7, 2019
@nalimilan
Copy link
Member

The difficulty is to avoid ambiguities. I guess you should try and see whether it can work.

@oxinabox
Copy link
Contributor Author

oxinabox commented Apr 7, 2019

There are 4 cases:

  • vcat of Vectors
  • vcat of Matrixs
  • hcat of Vectors
  • hcat of Matrixs

Potentially, each wanting there own special treatment.
Since for example if you know the length for hcat of Vectors you know the width of the matrix you must allocate.
and any time you work with matrixes reshape tricks need to be played

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fold sum, maximum, reduce, foldl, etc. performance Must go faster
Projects
None yet
Development

No branches or pull requests

3 participants