Skip to content

Cancellation with sparse arrays #658

Open
@gdalle

Description

@gdalle

Consider a function $f(t)$ such that $f(0)$ is the fully zero sparse vector. Apparently, ForwardDiff cannot compute $f'(0)$.

julia> using ForwardDiff: derivative

julia> using SparseArrays: sparse

julia> x = sparse([1.0]);

julia> dx = [1.0];

julia> derivative(t -> x + t * dx - x, 0)  # incorrect
1-element SparseVector{Float64, Int64} with 0 stored entries

julia> derivative(t -> Vector(x) + t * dx - Vector(x), 0)  # correct
1-element Vector{Float64}:
 1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions