Skip to content

How to use DirectLinearSolver #189

@bmxam

Description

@bmxam

Hi,

I'm trying to use the DirectLinearSolver instead of the default IterativeLinearSolver but I must be missing something because the below MWE, adapted from the doc, fails. How can I fix this examples?

using ForwardDiff
using ImplicitDifferentiation
using LinearAlgebra
using Optim

function forward_optim(x)
    f(y) = sum(abs2, y .^ 2 .- x)
    y0 = ones(eltype(x), size(x))
    result = optimize(f, y0)
    y = Optim.minimizer(result)
    z = nothing
    return y, z
end

function conditions_optim(x, y, _z)
    ∇₂f = 4 .* (y .^ 2 .- x) .* y
    return ∇₂f
end

x = [4.0, 9.0]

implicit_iterative = ImplicitFunction(
    forward_optim,
    conditions_optim;
    linear_solver = IterativeLinearSolver(),
)
@show ForwardDiff.jacobian(first  implicit_iterative, x) # OK

implicit_direct =
    ImplicitFunction(forward_optim, conditions_optim; linear_solver = DirectLinearSolver())
@show ForwardDiff.jacobian(first  implicit_direct, x) # KO
# ERROR: LoadError: MethodError: no method matching (::ImplicitDifferentiation.DirectLinearSolver)(::ImplicitDifferentiation.JVP{…}, ::Nothing, ::Vector{…}, ::Vector{…})

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