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
copy(::TrackedArray) doesn't work #416
Comments
We just need to add a method to catch this. Since tracked arrays are immutable anyway it can just be a no-op. |
What should |
Similar should always return the equivalent un-tracked object; there's no reason to include tracking for that since there are no gradients anyway. |
I am not sure, since the Interfaces documentation says that
but in x = TrackedArray(ones(5))
y = similar(x)
eltype(x) == eltype(y) # => false which is causing the above code to fail. |
@johnnychen94: I am not sure this is the right solution. For a bit of context, consider a function where I want to preallocate an array for results, eg function unitvec(xs::AbstractVector{T}) where {T <: Real}
S = typeof(√one(T)) # takes care of T ≡ Int64, etc
n = length(xs)
y = Vector{S}(undef, n + 1)
r = one(S)
for (i, x) in enumerate(xs)
z = tanh(x)
y[i] = z * √r
r *= 1 - abs2(z)
end
y[end] = √r
y
end which works fine for all kinds of arrays, except julia> xs = Flux.param(ones(3))
Tracked 3-element Array{Float64,1}:
1.0
1.0
1.0
julia> unitvec(xs)
S = Float64
ERROR: MethodError: no method matching Float64(::Flux.Tracker.TrackedReal{Float64})
Closest candidates are:
Float64(::Real, ::RoundingMode) where T<:AbstractFloat at rounding.jl:194
Float64(::T<:Number) where T<:Number at boot.jl:741
Float64(::Int8) at float.jl:60
...
Stacktrace:
[1] convert(::Type{Float64}, ::Flux.Tracker.TrackedReal{Float64}) at ./number.jl:7
[2] setindex!(::Array{Float64,1}, ::Flux.Tracker.TrackedReal{Float64}, ::Int64) at ./array.jl:766
[3] unitvec(::TrackedArray{…,Array{Float64,1}}) at ./REPL[88]:9
[4] top-level scope at none:0 I would find it more consistent if the parameter |
I've tweaked the definition of |
MWE:
gives the error
on
The text was updated successfully, but these errors were encountered: