@@ -241,10 +241,17 @@ function JacVec(f, u::AbstractArray, p = nothing, t = nothing; autodiff = true)
241241 vecprod = autodiff ? auto_jacvec : num_jacvec
242242 vecprod! = autodiff ? auto_jacvec! : num_jacvec!
243243
244+ outofplace = static_hasmethod (f, typeof ((u,)))
245+ isinplace = static_hasmethod (f, typeof ((u, u,)))
246+
247+ if ! (isinplace) & ! (outofplace)
248+ error (" $f must have signature f(u), or f(du, u)." )
249+ end
250+
244251 L = FwdModeAutoDiffVecProd (f, u, cache, vecprod, vecprod!)
245252
246253 FunctionOperator (L, u, u;
247- isinplace = true , outofplace = true ,
254+ isinplace = isinplace , outofplace = outofplace ,
248255 p = p, t = t, islinear = true ,
249256 )
250257end
@@ -266,10 +273,17 @@ function HesVec(f, u::AbstractArray, p = nothing, t = nothing; autodiff = true)
266273 vecprod = autodiff ? numauto_hesvec : num_hesvec
267274 vecprod! = autodiff ? numauto_hesvec! : num_hesvec!
268275
276+ outofplace = static_hasmethod (f, typeof ((u,)))
277+ isinplace = static_hasmethod (f, typeof ((u,)))
278+
279+ if ! (isinplace) & ! (outofplace)
280+ error (" $f must have signature f(u)." )
281+ end
282+
269283 L = FwdModeAutoDiffVecProd (f, u, cache, vecprod, vecprod!)
270284
271285 FunctionOperator (L, u, u;
272- isinplace = true , outofplace = true ,
286+ isinplace = isinplace , outofplace = outofplace ,
273287 p = p, t = t, islinear = true ,
274288 )
275289end
@@ -292,10 +306,17 @@ function HesVecGrad(f, u::AbstractArray, p = nothing, t = nothing; autodiff = tr
292306 vecprod = autodiff ? auto_hesvecgrad : num_hesvecgrad
293307 vecprod! = autodiff ? auto_hesvecgrad! : num_hesvecgrad!
294308
309+ outofplace = static_hasmethod (f, typeof ((u,)))
310+ isinplace = static_hasmethod (f, typeof ((u, u,)))
311+
312+ if ! (isinplace) & ! (outofplace)
313+ error (" $f must have signature f(u), or f(du, u)." )
314+ end
315+
295316 L = FwdModeAutoDiffVecProd (f, u, cache, vecprod, vecprod!)
296317
297318 FunctionOperator (L, u, u;
298- isinplace = true , outofplace = true ,
319+ isinplace = isinplace , outofplace = outofplace ,
299320 p = p, t = t, islinear = true ,
300321 )
301322end
0 commit comments