Skip to content

optimize reduce(vcat, vector_of_matrices) #496

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

Merged
merged 1 commit into from
Oct 24, 2019

Conversation

rfourquet
Copy link
Contributor

This is the idiomatic way to call vcat on a vector of matrices,
at least when performance matters (as opposed to
vcat(vector_of_matrices...)).
Let's optimize this case, like it's done in Base for Vector
and Matrix.
Similarly for hcat.

This is an alternative solution to the special implementation vcat(A::Vector{<: MatrixElem}) which was removed in #409.

This is the idiomatic way to call vcat on a vector of matrices,
at least when performance matters (as opposed to
`vcat(vector_of_matrices...)`).
Let's optimize this case, like it's done in `Base` for `Vector`
and `Matrix`.
Similarly for `hcat`.
@fieker
Copy link
Contributor

fieker commented Oct 14, 2019 via email

@rfourquet
Copy link
Contributor Author

How is one supposed to figure out that reduce is the "best" and "most natural" way of doing things?

I consider the situation to be subotimal in Base, and I hope the status quo will evolve for the better.

When you have a binary operation, like vcat, and you want to apply it to a collection one element at a time, reduce is the goto solution. But I would not have thought about it for vcat because it seems obvious it will be badly inefficient, by allocating a new result matrix at each iteration. However, they decided it will still be the current "blessed" way to do that, and they optimized this particular case to not allocate like crazy. So I find it unsatisfying because the non-naïve user won't think about this solution unless she knows it's optimized. Moreover, it works only for AbstractVector's of matrices, not for general iterators...
But, for the time being, this is the solution they chose, and it's easy to support the same in our case.

@wbhart
Copy link
Contributor

wbhart commented Oct 23, 2019

Does anyone have an objection to merging this? @thofma @fieker

@thofma
Copy link
Member

thofma commented Oct 23, 2019

Have no clue what this is doing, so no objection from me :)

@fieker
Copy link
Contributor

fieker commented Oct 24, 2019 via email

@rfourquet
Copy link
Contributor Author

Have no clue what this is doing,

This is making reduce(vcat, [M1, M2, M3]) "fast", where M1, M2, M3 are matrices. I.e. it doesn't allocate a new matrix for each intermediate step of reduce.

Does this break anyhting that is currently working?

I don't see what it could break. It seems to be an "optimization only" change.

@fieker
Copy link
Contributor

fieker commented Oct 24, 2019 via email

@wbhart wbhart merged commit 938f368 into Nemocas:master Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants