Skip to content

Commit 82e0594

Browse files
committed
Fix calculation of 1x1 Jacobian of a Vector
1 parent 2d81794 commit 82e0594

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/FiniteDiff.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ _vec(x) = vec(x)
99
_vec(x::Number) = x
1010

1111
_mat(x::AbstractMatrix) = x
12-
_mat(x::StaticVector) = reshape(x, (axes(x, 1), SOneTo(1)))
13-
_mat(x::AbstractVector) = reshape(x, (axes(x, 1), OneTo(1)))
12+
_mat(x::StaticVector) = reshape(x, (axes(x, 1), SOneTo(1)))
13+
_mat(x::AbstractVector) = reshape(x, (axes(x, 1), Base.OneTo(1)))
1414

1515
include("iteration_utils.jl")
1616
include("epsilons.jl")

test/out_of_place_tests.jl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,15 @@ J = FiniteDiff.finite_difference_jacobian(f, x, Val{:forward}, eltype(x),
3434
@test J second_derivative_stencil(30)
3535
@test typeof(J) == typeof(spJ)
3636

37-
#1x1 SVector test
38-
x = SVector{1}([1.])
39-
f(x) = x
40-
J = FiniteDiff.finite_difference_jacobian(f, x, Val{:forward}, eltype(x))
41-
@test J[1, 1] 1.0
42-
@test J isa SMatrix{1,1}
43-
J = FiniteDiff.finite_difference_jacobian(f, x, Val{:central}, eltype(x))
44-
@test J[1, 1] 1.0
45-
@test J isa SMatrix{1,1}
46-
J = FiniteDiff.finite_difference_jacobian(f, x, Val{:complex}, eltype(x))
47-
@test J[1, 1] 1.0
48-
@test J isa SMatrix{1,1}
37+
f = x -> x
38+
@testset "1x1 test of $x" for
39+
(x, y) in ((SVector{1}([1.]), SMatrix{1,1}), ([1.0], Matrix)),
40+
difftype in (:forward, :central, :complex)
41+
42+
J = FiniteDiff.finite_difference_jacobian(f, x, Val{difftype}, eltype(x))
43+
@test J[1, 1] 1.0
44+
@test J isa y
45+
end
4946

5047
x = SVector{1}([1.])
5148
f(x) = vcat(x, x)

0 commit comments

Comments
 (0)