88function GradientCache (
99 df,
1010 x,
11- fdtype = Val{ :central } ,
11+ fdtype = Val ( :central ) ,
1212 returntype = eltype (df),
1313 inplace = Val{true })
1414
15+ fdtype isa Type && (fdtype = fdtype ())
1516 if typeof (x)<: AbstractArray # the vector->scalar case
16- if fdtype!= Val{ :complex } # complex-mode FD only needs one cache, for x+eps*im
17+ if fdtype!= Val ( :complex ) # complex-mode FD only needs one cache, for x+eps*im
1718 if typeof (x)<: StridedVector
1819 if eltype (df)<: Complex && ! (eltype (x)<: Complex )
1920 _c1 = zero (Complex{eltype (x)}) .* x
@@ -37,7 +38,7 @@ function GradientCache(
3738 _c3 = similar (x)
3839 else # the scalar->vector case
3940 # need cache arrays for fx1 and fx2, except in complex mode, which needs one complex array
40- if fdtype != Val{ :complex }
41+ if fdtype != Val ( :complex )
4142 _c1 = similar (df)
4243 _c2 = similar (df)
4344 else
5556function finite_difference_gradient (
5657 f,
5758 x,
58- fdtype = Val{ :central } ,
59+ fdtype = Val ( :central ) ,
5960 returntype = eltype (x),
6061 inplace = Val{true },
6162 fx = nothing ,
@@ -89,7 +90,7 @@ function finite_difference_gradient!(
8990 df,
9091 f,
9192 x,
92- fdtype= Val{ :central } ,
93+ fdtype= Val ( :central ) ,
9394 returntype= eltype (df),
9495 inplace= Val{true },
9596 fx= nothing ,
@@ -133,12 +134,12 @@ function finite_difference_gradient!(
133134 # NOTE: in this case epsilon is a vector, we need two arrays for epsilon and x1
134135 # c1 denotes x1, c2 is epsilon
135136 fx, c1, c2, c3 = cache. fx, cache. c1, cache. c2, cache. c3
136- if fdtype != Val{ :complex } && ArrayInterface. fast_scalar_indexing (c2)
137+ if fdtype != Val ( :complex ) && ArrayInterface. fast_scalar_indexing (c2)
137138 @. c2 = compute_epsilon (fdtype, x, relstep, absstep, dir)
138139 copyto! (c1,x)
139140 end
140141 copyto! (c3,x)
141- if fdtype == Val{ :forward }
142+ if fdtype == Val ( :forward )
142143 @inbounds for i ∈ eachindex (x)
143144 if ArrayInterface. fast_scalar_indexing (c2)
144145 epsilon = ArrayInterface. allowed_getindex (c2,i)* dir
@@ -168,7 +169,7 @@ function finite_difference_gradient!(
168169 ArrayInterface. allowed_setindex! (c1,c1_old,i)
169170 end
170171 end
171- elseif fdtype == Val{ :central }
172+ elseif fdtype == Val ( :central )
172173 @inbounds for i ∈ eachindex (x)
173174 if ArrayInterface. fast_scalar_indexing (c2)
174175 epsilon = ArrayInterface. allowed_getindex (c2,i)* dir
@@ -191,7 +192,7 @@ function finite_difference_gradient!(
191192 ArrayInterface. allowed_setindex! (c1,c1_old, i)
192193 ArrayInterface. allowed_setindex! (c3,x_old,i)
193194 end
194- elseif fdtype == Val{ :complex } && returntype <: Real
195+ elseif fdtype == Val ( :complex ) && returntype <: Real
195196 copyto! (c1,x)
196197 epsilon_complex = eps (real (eltype (x)))
197198 # we use c1 here to avoid typing issues with x
@@ -219,13 +220,13 @@ function finite_difference_gradient!(
219220 # c1 is x1 if we need a complex copy of x, otherwise Nothing
220221 # c2 is Nothing
221222 fx, c1, c2, c3 = cache. fx, cache. c1, cache. c2, cache. c3
222- if fdtype != Val{ :complex }
223+ if fdtype != Val ( :complex )
223224 if eltype (df)<: Complex && ! (eltype (x)<: Complex )
224225 copyto! (c1,x)
225226 end
226227 end
227228 copyto! (c3,x)
228- if fdtype == Val{ :forward }
229+ if fdtype == Val ( :forward )
229230 for i ∈ eachindex (x)
230231 epsilon = compute_epsilon (fdtype, x[i], relstep, absstep, dir)
231232 x_old = x[i]
@@ -262,7 +263,7 @@ function finite_difference_gradient!(
262263 df[i] -= im * imag (dfi)
263264 end
264265 end
265- elseif fdtype == Val{ :central }
266+ elseif fdtype == Val ( :central )
266267 @inbounds for i ∈ eachindex (x)
267268 epsilon = compute_epsilon (fdtype, x[i], relstep, absstep, dir)
268269 x_old = x[i]
@@ -289,7 +290,7 @@ function finite_difference_gradient!(
289290 df[i] -= im* imag (dfi / (2 * im* epsilon))
290291 end
291292 end
292- elseif fdtype== Val{ :complex } && returntype<: Real && eltype (df)<: Real && eltype (x)<: Real
293+ elseif fdtype== Val ( :complex ) && returntype<: Real && eltype (df)<: Real && eltype (x)<: Real
293294 copyto! (c1,x)
294295 epsilon_complex = eps (real (eltype (x)))
295296 # we use c1 here to avoid typing issues with x
@@ -324,8 +325,8 @@ function finite_difference_gradient!(
324325 _c1, _c2 = c1, c2
325326 end
326327
327- if fdtype == Val{ :forward }
328- epsilon = compute_epsilon (Val{ :forward } , x, relstep, absstep, dir)
328+ if fdtype == Val ( :forward )
329+ epsilon = compute_epsilon (Val ( :forward ) , x, relstep, absstep, dir)
329330 if inplace == Val{true }
330331 f (c1, x+ epsilon)
331332 else
@@ -341,8 +342,8 @@ function finite_difference_gradient!(
341342 end
342343 @. df = (_c1 - _c2) / epsilon
343344 end
344- elseif fdtype == Val{ :central }
345- epsilon = compute_epsilon (Val{ :central } , x, relstep, absstep, dir)
345+ elseif fdtype == Val ( :central )
346+ epsilon = compute_epsilon (Val ( :central ) , x, relstep, absstep, dir)
346347 if inplace == Val{true }
347348 f (c1, x+ epsilon)
348349 f (c2, x- epsilon)
@@ -351,7 +352,7 @@ function finite_difference_gradient!(
351352 _c2 = f (x- epsilon)
352353 end
353354 @. df = (_c1 - _c2) / (2 * epsilon)
354- elseif fdtype == Val{ :complex } && returntype <: Real
355+ elseif fdtype == Val ( :complex ) && returntype <: Real
355356 epsilon_complex = eps (real (eltype (x)))
356357 if inplace == Val{true }
357358 f (c1, x+ im* epsilon_complex)
0 commit comments