Skip to content

In-place assignment on strictly typed vectors does not report error #76

Closed

Description

@mcovalt

If using an in-place assignment operator .= from a tracked vector into a typed vector, no error is reported and an incorrect answer is given. Consider the following:

using ReverseDiff

function test1(x)
    out = Vector{Float64}(length(x))
    out .= 3.0.*x
    out .^= 2
    return sqrt(dot(out,out))
end
function test2(x)
    out = Vector{Any}(length(x))
    out .= 3.0.*x
    out .^= 2
    return sqrt(dot(out,out))
end

input = rand(3)
test1(input) == test2(input)
g1 = ReverseDiff.gradient(test1, input)
g2 = ReverseDiff.gradient(test2, input)

Output in Julia 0.5:

julia> test1(input) == test2(input)
    true
julia> g1 = ReverseDiff.gradient(test1, input)
    3-element Array{Float64,1}:
    0.0
    0.0
    0.0
julia> g2 = ReverseDiff.gradient(test2, input)
    3-element Array{Float64,1}:
    0.0936007
    6.53833
    13.5873

Activity

  1. jrevels commented on Jun 19, 2017

    @jrevels
    Member

    This is due to

    Base.convert{R<:Real,T<:TrackedReal}(::Type{R}, t::T) = R(value(t))
    , which I knew about when adding it. I think I needed that method to support some other behavior, but I can't for the life of me remember what...

  2. antoine-levitt commented on Aug 16, 2017

    @antoine-levitt

    Just got hit by this, could this yield an error while the behavior is being worked out?

  3. added 2 commits that reference this issue on Feb 28, 2021
    2336232
    e13da22
  4. added a commit that references this issue on Feb 28, 2021
    8f7a050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions