Skip to content

Commit

Permalink
Fix #121 by removing type annotations. (#122)
Browse files Browse the repository at this point in the history
* Fix #121 by removing type annotations.

* Add test.
  • Loading branch information
pkofod authored Oct 19, 2017
1 parent 535b736 commit 0b1cdf8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/differentiable_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function DifferentiableMultivariateFunction(f!, g!, fg!, initial_x::AbstractArra
end

function DifferentiableMultivariateFunction(f!, g!)
function fg!(x::AbstractVector, fx::AbstractVector, gx::AbstractMatrix)
function fg!(x, fx, gx)
f!(x, fx)
g!(x, gx)
end
Expand All @@ -38,7 +38,7 @@ function DifferentiableMultivariateFunction(f!; dtype::Symbol=:central)
end
finite_difference_jacobian!(f, x, fx, gx, dtype)
end
function g!(x::AbstractVector, gx::AbstractMatrix)
function g!(x, gx)
fx = similar(x)
fg!(x, fx, gx)
end
Expand All @@ -52,7 +52,7 @@ end

# Helper for the case where only f! and fg! are available
function only_f!_and_fg!(f!, fg!)
function g!(x::AbstractVector, gx::AbstractMatrix)
function g!(x, gx)
fx = similar(x)
fg!(x, fx, gx)
end
Expand All @@ -66,11 +66,11 @@ end

# Helper for the case where only fg! is available
function only_fg!(fg!)
function f!(x::AbstractVector, fx::AbstractVector)
function f!(x, fx)
gx = Array{eltype(x)}(length(x), length(x))
fg!(x, fx, gx)
end
function g!(x::AbstractVector, gx::AbstractMatrix)
function g!(x, gx)
fx = similar(x)
fg!(x, fx, gx)
end
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end

# Helpers for functions that do not modify arguments in place but return
function not_in_place(f)
function f!(x::AbstractVector, fx::AbstractVector)
function f!(x, fx)
copy!(fx, f(x))
end
end
Expand Down
23 changes: 23 additions & 0 deletions test/api.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# taken from https://github.com/JuliaNLSolvers/NLsolve.jl/issues/121

function f(x)
eq = Array{Float64}(length(x))

eq[1] = 5 .* x[1] - x[2].^2
eq[2] = 4 .* x[2] - x[1]

return eq
end

function J(x)
jmat = Array{Float64}(length(x),length(x))

jmat[1,1] = 5
jmat[1,2] = -2.*x[2]
jmat[2,1] = -1
jmat[2,2] = 4

return jmat
end

x0 = [3.0, 12.0]
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Base.reshape(A::WrappedArray, dims::Int...) = WrappedArray(reshape(A.x, dims...)
if length(ARGS) > 0
tests = map(add_jl, ARGS)
else
tests = ["2by2.jl",
tests = ["api.jl",
"2by2.jl",
"singular.jl",
"finite_difference.jl",
"minpack.jl",
Expand Down

0 comments on commit 0b1cdf8

Please sign in to comment.