9898# #############################################################################
9999
100100function finite_difference! {S <: Number, T <: Number} (f,
101- x:: Vector {S} ,
102- g:: Vector {T} ,
101+ x:: AbstractVector {S} ,
102+ g:: AbstractVector {T} ,
103103 dtype:: Symbol )
104104 # What is the dimension of x?
105105 n = length (x)
106106
107107 # Iterate over each dimension of the gradient separately.
108- # Use xplusdx to store x + dx instead of creating a new vector on each pass.
109- # Use xminusdx to store x - dx instead of creating a new vector on each pass.
108+ # Use xplusdx to store x + dx instead of creating a new AbstractVector on each pass.
109+ # Use xminusdx to store x - dx instead of creating a new AbstractVector on each pass.
110110 if dtype == :forward
111111 # Establish a baseline value of f(x).
112112 f_x = f (x)
@@ -136,10 +136,10 @@ function finite_difference!{S <: Number, T <: Number}(f,
136136 return
137137end
138138function finite_difference {T <: Number} (f,
139- x:: Vector {T} ,
139+ x:: AbstractVector {T} ,
140140 dtype:: Symbol = :central )
141141 # Allocate memory for gradient
142- g = Vector {Float64} (length (x))
142+ g = AbstractVector {Float64} (length (x))
143143
144144 # Mutate allocated gradient
145145 finite_difference! (f, float (x), g, dtype)
157157function finite_difference_jacobian!{R <: Number ,
158158 S <: Number ,
159159 T <: Number }(f,
160- x:: Vector {R} ,
161- f_x:: Vector {S} ,
160+ x:: AbstractVector {R} ,
161+ f_x:: AbstractVector {S} ,
162162 J:: Array{T} ,
163163 dtype:: Symbol = :central )
164164 # What is the dimension of x?
@@ -191,7 +191,7 @@ function finite_difference_jacobian!{R <: Number,
191191 return
192192end
193193function finite_difference_jacobian {T <: Number} (f,
194- x:: Vector {T} ,
194+ x:: AbstractVector {T} ,
195195 dtype:: Symbol = :central )
196196 # Establish a baseline for f_x
197197 f_x = f (x)
232232
233233function finite_difference_hessian!{S <: Number ,
234234 T <: Number }(f,
235- x:: Vector {S} ,
235+ x:: AbstractVector {S} ,
236236 H:: Array{T} )
237237 # What is the dimension of x?
238238 n = length (x)
@@ -264,7 +264,7 @@ function finite_difference_hessian!{S <: Number,
264264 Base. LinAlg. copytri! (H,' U' )
265265end
266266function finite_difference_hessian {T <: Number} (f,
267- x:: Vector {T} )
267+ x:: AbstractVector {T} )
268268 # What is the dimension of x?
269269 n = length (x)
270270
@@ -279,7 +279,7 @@ function finite_difference_hessian{T <: Number}(f,
279279end
280280function finite_difference_hessian {T <: Number} (f,
281281 g,
282- x:: Vector {T} ,
282+ x:: AbstractVector {T} ,
283283 dtype:: Symbol = :central )
284284 finite_difference_jacobian (g, x, dtype)
285285end
@@ -329,16 +329,15 @@ end
329329# #############################################################################
330330
331331# The function "dirderivative" calculates directional derivatives in the direction v.
332- # The function supplied must have the form Vector{Float64} -> Float64
333- # function dirderivative(f, v::Vector{Float64}, x0::Vector{Float64}, h::Float64, twoside::Bool)
332+ # function dirderivative(f, v::AbstractVector{Float64}, x0::AbstractVector{Float64}, h::Float64, twoside::Bool)
334333# derivative(t::Float64 -> f(x0 + v*t) / norm(v), 0.0, h, twoside)
335334# end
336- # function dirderivative(f, v::Vector {Float64}, x0::Vector {Float64}, h::Float64)
335+ # function dirderivative(f, v::AbstractVector {Float64}, x0::AbstractVector {Float64}, h::Float64)
337336# dirderivative(f, v, x0, h, true)
338337# end
339- # function dirderivative(f, v::Vector {Float64}, x0::Vector {Float64}, )
338+ # function dirderivative(f, v::AbstractVector {Float64}, x0::AbstractVector {Float64}, )
340339# derivative(f, v, x0, 0.0001)
341340# end
342- # function dirderivative(f, v::Vector {Float64})
341+ # function dirderivative(f, v::AbstractVector {Float64})
343342# x -> dirderivative(f, v, x)
344343# end
0 commit comments