9090@inline jacobian! (result:: Union{AbstractArray,DiffResult} , f, x:: StaticArray , cfg:: JacobianConfig ) = jacobian! (result, f, x)
9191@inline jacobian! (result:: Union{AbstractArray,DiffResult} , f, x:: StaticArray , cfg:: JacobianConfig , :: Val ) = jacobian! (result, f, x)
9292
93+ jacobian (f, x:: Real ) = throw (DimensionMismatch (" jacobian(f, x) expects that x is an array. Perhaps you meant derivative(f, x)?" ))
94+
9395# ####################
9496# result extraction #
9597# ####################
@@ -143,6 +145,7 @@ reshape_jacobian(result::DiffResult, ydual, xdual) = reshape_jacobian(DiffResult
143145
144146function vector_mode_jacobian (f:: F , x, cfg:: JacobianConfig{T,V,N} ) where {F,T,V,N}
145147 ydual = vector_mode_dual_eval (f, x, cfg)
148+ ydual isa AbstractArray || throw (JACOBIAN_ERROR)
146149 result = similar (ydual, valtype (eltype (ydual)), length (ydual), N)
147150 extract_jacobian! (T, result, ydual, N)
148151 extract_value! (T, result, ydual)
194197 return result
195198end
196199
200+ const JACOBIAN_ERROR = DimensionMismatch (" jacobian(f, x) expexts that f(x) is an array. Perhaps you meant gradient(f, x)?" )
201+
197202# chunk mode #
198203# ------------#
199204
@@ -216,6 +221,7 @@ function jacobian_chunk_mode_expr(work_array_definition::Expr, compute_ydual::Ex
216221 # do first chunk manually to calculate output type
217222 seed! (xdual, x, 1 , seeds)
218223 $ (compute_ydual)
224+ ydual isa AbstractArray || throw (JACOBIAN_ERROR)
219225 $ (result_definition)
220226 out_reshaped = reshape_jacobian (result, ydual, xdual)
221227 extract_jacobian_chunk! (T, out_reshaped, ydual, 1 , N)
0 commit comments