File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 45
45
function finite_difference (f,
46
46
x:: T ,
47
47
dtype:: Symbol = :central ) where T <: Number
48
+ # handle irrationals
49
+ if T <: Irrational
50
+ x = float (x)
51
+ end
48
52
if dtype == :forward
49
53
@forwardrule x epsilon
50
54
xplusdx = x + epsilon
@@ -101,6 +105,10 @@ function finite_difference!(f,
101
105
x:: AbstractVector{S} ,
102
106
g:: AbstractVector{T} ,
103
107
dtype:: Symbol ) where {S <: Number , T <: Number }
108
+ # handle irrationals
109
+ if S <: Irrational
110
+ x = float .(x)
111
+ end
104
112
# What is the dimension of x?
105
113
n = length (x)
106
114
@@ -161,6 +169,10 @@ function finite_difference_jacobian!(f,
161
169
dtype:: Symbol = :central ) where {R <: Number ,
162
170
S <: Number ,
163
171
T <: Number }
172
+ # handle irrationals
173
+ if R <: Irrational
174
+ x = float .(x)
175
+ end
164
176
# What is the dimension of x?
165
177
m, n = size (J)
166
178
214
226
215
227
function finite_difference_hessian (f,
216
228
x:: T ) where T <: Number
229
+ # handle irrationals
230
+ if typeof (x) <: Irrational
231
+ x = float (x)
232
+ end
217
233
@hessianrule x epsilon
218
234
(f (x + epsilon) - 2 * f (x) + f (x - epsilon))/ epsilon^ 2
219
235
end
@@ -234,6 +250,10 @@ function finite_difference_hessian!(f,
234
250
x:: AbstractVector{S} ,
235
251
H:: Array{T} ) where {S <: Number ,
236
252
T <: Number }
253
+ # handle irrationals
254
+ if S <: Irrational
255
+ x = float .(x)
256
+ end
237
257
# What is the dimension of x?
238
258
n = length (x)
239
259
You can’t perform that action at this time.
0 commit comments