-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add scatter operations #255
Conversation
Could these easily be combined to something like |
@mcabbott Sure! I have API like |
I think he is suggesting to directly pass the operator (not a symbol), the same way you would use it in julia> reduce(+, ones(10))
10.0 We could have julia> function scatter!(op, ys::Array{T}, us::Array{T}, xs::Array{<:IntOrTuple}) where {T<:Real}
@simd for k = 1:length(xs)
k = CartesianIndices(xs)[k]
ys_v = view(ys, xs[k]...)
us_v = view(us, k)
@inbounds ys_v .= (op).(ys_v, us_v)
end
ys
end and a few specialized methods: function scatter!(op::typeof(mean), ys::Array{T}, us::Array{T}, xs::Array{<:IntOrTuple}) where {T<:Real}
... |
ab03446
to
be4fa94
Compare
Maybe we should specified how our |
I discussed with @chengchingwen yesterday. We hope to introduce some new features to generalize scatter/gather operations. New features are listed in the following:
|
dims = Nsrc - Nidx | ||
dstsize = (size(src)[1:dims]..., maximum_dims(idx)...) | ||
dst = similar(src, T, dstsize) | ||
fill!(dst, typemax(T)) |
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.
I wonder if typemax
is the right thing to do here. The problem is if there are positions in dst
which receive no contributions for src
they will end up holding typemax
, which doesn't seem meaningful. Maybe we should error out in such cases, but doing this check may have a performance impact
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.
Yeah, I thought this issue before. Checking the position of dst
is properly covered by idx
is the way to avoid holding typemax
. But still, it is necessary to check values in src
is smaller than the value we assigned, either typemax
or similar
. similar
gives the value existing in bare memory, so we have no idea knowing if the values are smaller enough.
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.
What if we give the maximum
of src
? Thus, the value is at least smaller or equals to the maximum
of src
.
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.
I think maximum(src)
would be more surprising, in un-visited entries. typemax
seems OK to me.
If it is ready to go, just let it go. |
ok, I'll merge this so that work can proceed, I'll open a pr to revisit the docstrings |
1516: add Embedding layer r=CarloLucibello a=CarloLucibello Basic implementation. Maybe could be improved when FluxML/NNlib.jl#255 lands ### PR Checklist - [x] Tests are added - [x] Entry in NEWS.md - [x] Documentation, if applicable - [ ] Final review from `@dhairyagandhi96` (for API changes). Co-authored-by: Carlo Lucibello <[email protected]>
1516: add Embedding layer r=CarloLucibello a=CarloLucibello Basic implementation. Maybe could be improved when FluxML/NNlib.jl#255 lands ### PR Checklist - [x] Tests are added - [x] Entry in NEWS.md - [x] Documentation, if applicable - [ ] Final review from `@dhairyagandhi96` (for API changes). Co-authored-by: Carlo Lucibello <[email protected]>
1516: add Embedding layer r=DhairyaLGandhi a=CarloLucibello Basic implementation. Maybe could be improved when FluxML/NNlib.jl#255 lands ### PR Checklist - [x] Tests are added - [x] Entry in NEWS.md - [x] Documentation, if applicable - [ ] Final review from `@dhairyagandhi96` (for API changes). Co-authored-by: Carlo Lucibello <[email protected]> Co-authored-by: Carlo Lucibello <[email protected]>
I have generalized scatter operations to every dimensions, instead of excluding the first dimension.
Related to yuehhua/ScatterNNlib.jl#32