Skip to content

Commit

Permalink
Fix test_jacobian.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jul 3, 2018
1 parent 465ce77 commit 228f4d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/utils/array_utils.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module ArrayUtils

using StaticArrays: SMatrix
using StaticArrays: SMatrix, SVector

container_array_of(::SVector{S}) where {S} = SVector{S}
container_array_of(::SMatrix{S1, S2}) where {S1, S2} = SMatrix{S1, S2}
container_array_of(::Array{T, N}) where {T, N} = Array{<:Any, N}

_eigvals(A) = eigvals(A)
_eigvals(A::SMatrix) = eigvals(Array(A))
Expand Down
7 changes: 7 additions & 0 deletions test/preamble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Setfield: @lens

using Bifurcations
using Bifurcations: BifurcationProblem, special_points
using Bifurcations.ArrayUtils: container_array_of

macro test_nothrow(ex)
quote
Expand Down Expand Up @@ -44,3 +45,9 @@ function smoke_test_solver_plot(solver)
@test_nothrow nullshow(plot(solver.sol))
@test_nothrow nullshow(plot(solver))
end

_generalize_f(f, A) = function(u::U, p, t) where {T, U <: AbstractArray{T}}
U(f(A(u), p, t))
end

generalized_f(mod) = _generalize_f(mod.f, container_array_of(mod.u0))
2 changes: 1 addition & 1 deletion test/test_jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sjac(f, x) = [diff(f[i], x[j]) for i in 1:length(f), j in 1:length(x)]

nx = length(PredatorPrey.u0)
np = length(PredatorPrey.p)
f = PredatorPrey.f
f = generalized_f(PredatorPrey)
pe = [symbols("p_$i") for i in 1:np]
xe = [symbols("x_$i") for i in 1:nx]
ve = [symbols("v_$i") for i in 1:nx]
Expand Down
10 changes: 9 additions & 1 deletion test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ module TestUtils
using Base.Test
using Compat

using StaticArrays: SVector
using StaticArrays: SVector, SMatrix

using Bifurcations.ArrayUtils: container_array_of
using Bifurcations.Codim2: cast_container, as_reals, _ds_eigvec

@testset "container_array_of" begin
@test container_array_of([1, 2, 3]) == Vector
@test container_array_of([1 2; 3 4]) == Matrix
@test container_array_of(SVector(1.0, 2.0, 3.0)) === SVector{3}
@test container_array_of(SMatrix{2, 2}(1, 2, 3, 4)) === SMatrix{2, 2}
end

@testset "cast_container" begin
# No cast if it's already of the correct type:
for v in [ones(3),
Expand Down

0 comments on commit 228f4d7

Please sign in to comment.