-
-
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
Support conv_direct!
on custom datatypes
#592
Conversation
Looks like failures on nightly are unrelated. |
@mcabbott could a patch release be tagged for this? |
Tagged |
Thanks! |
@@ -81,6 +81,11 @@ function conv_direct!( | |||
# Use `calc_padding_regions` to determine where we do or don't need to worry about padding | |||
padded_regions, central_region = calc_padding_regions(cdims) | |||
|
|||
# Set outputs to zero to support custom datatypes (https://github.com/FluxML/NNlib.jl/issues/490) | |||
if iszero(beta) | |||
y = fill!(y, zero(yT)) |
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.
As I mentioned in the original issue, naive fill!
/fill
doesn't necessarily work with e.g. BigInt
:
julia> a = Vector{BigInt}(undef, 2)
2-element Vector{BigInt}:
#undef
#undef
julia> fill!(a, zero(BigInt))
2-element Vector{BigInt}:
0
0
julia> a[1] ===a[2]
true
I don't know how important these kinds of usecases are for NNlib.jl though.
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.
Is that problematic here?
julia> a = Vector{BigInt}(undef, 2)
2-element Vector{BigInt}:
#undef
#undef
julia> fill!(a, zero(BigInt))
2-element Vector{BigInt}:
0
0
julia> for (i, ai) in enumerate(a)
a[i] = i + 0 * a[i]
end
julia> a
2-element Vector{BigInt}:
1
2
Closes #490, #405.
As described in #490, undefined array elements can't be indexed on all datatypes:
Such indexing is used in the right-hand side of
conv_direct!
on mainNNlib.jl/src/impl/conv_direct.jl
Line 111 in 627374c
which means that
conv_direct!
doesn't support all input datatypes.However, assignments work, which is way the problem can be solved by first setting
y
to zero, as suggested here by @ToucheSir.