-
-
Notifications
You must be signed in to change notification settings - Fork 609
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 hcat of onehot vectors and matrices #1595
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! I left some suggestions that make sure we hit reshaped arrays as well.
hitting reshaped arrays Co-authored-by: Kyle Daruwalla <daruwalla.k.public@icloud.com>
I believe the root issue is that we don't have |
Adding tests for typeof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go back to the previously suggested changes (I have commented them again with some updates). If the constructor is causing issues, then why not just change the constructor to:
OneHotArray(indices::I, L::Integer) where {T, N, I<: AbstractArray{T, N}} = OneHotArray{T, L, N, I}(indices)
Then much more than hcat
can see the performance benefit.
Good point! Though this means we would need to pair We might want to define |
Ideally we would fix it generally rather than for special cases. That's the flux way. |
Here is an implementation of function Base.similar(x::OneHotArray, ::Type{Bool}, dims::Dims)
indices = similar(_indices(x), Base.tail(dims))
return OneHotArray(indices, first(dims))
end This would need to be paired with |
making hcat more generic for onehotlike Co-authored-by: Kyle Daruwalla <daruwalla.k.public@icloud.com>
Ok, the performance is now good even for reshaped arrays. Should I now include the |
I think the best move is to remove the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some readability changes in addition to the request to remove the reduce(hcat, ...)
paths for now.
more readable code Co-authored-by: Kyle Daruwalla <daruwalla.k.public@icloud.com>
Done, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
bors r+ |
Build succeeded: |
PR Checklist
Fixes #1594 , adds tests for it and also optimized reduce(hcat, xs).
No new features are added, only performance optimization.