Skip to content

Commit 5f24f6b

Browse files
committed
Change all Array and Vector to AbstractArray and AbstractVector
1 parent cb42f36 commit 5f24f6b

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/check_derivative.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function check_derivative(f::Function, g::Function, x::Number)
33
return maximum(abs(g(x) - auto_g(x)))
44
end
55

6-
function check_gradient{T <: Number}(f::Function, g::Function, x::Vector{T})
6+
function check_gradient{T <: Number}(f::Function, g::Function, x::AbstractVector{T})
77
auto_g = gradient(f)
88
return maximum(abs(g(x) - auto_g(x)))
99
end
@@ -13,7 +13,7 @@ function check_second_derivative(f::Function, h::Function, x::Number)
1313
return maximum(abs(h(x) - auto_h(x)))
1414
end
1515

16-
function check_hessian{T <: Number}(f::Function, h::Function, x::Vector{T})
16+
function check_hessian{T <: Number}(f::Function, h::Function, x::AbstractVector{T})
1717
auto_h = hessian(f)
1818
return maximum(abs(h(x) - auto_h(x)))
1919
end

src/derivative.jl

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ function derivative(f::Function, ftype::Symbol, dtype::Symbol)
88
end
99
return g
1010
end
11-
Compat.@compat derivative{T <: Number}(f::Function, x::Union{T, Vector{T}}, dtype::Symbol = :central) = finite_difference(f, float(x), dtype)
11+
Compat.@compat derivative{T <: Number}(f::Function, x::Union{T, AbstractVector{T}}, dtype::Symbol = :central) = finite_difference(f, float(x), dtype)
1212
derivative(f::Function, dtype::Symbol = :central) = derivative(f, :scalar, dtype)
1313

14-
Compat.@compat gradient{T <: Number}(f::Function, x::Union{T, Vector{T}}, dtype::Symbol = :central) = finite_difference(f, float(x), dtype)
14+
Compat.@compat gradient{T <: Number}(f::Function, x::Union{T, AbstractVector{T}}, dtype::Symbol = :central) = finite_difference(f, float(x), dtype)
1515
gradient(f::Function, dtype::Symbol = :central) = derivative(f, :vector, dtype)
1616

17-
Compat.@compat function Base.gradient{T <: Number}(f::Function, x::Union{T, Vector{T}}, dtype::Symbol = :central)
17+
Compat.@compat function Base.gradient{T <: Number}(f::Function, x::Union{T, AbstractVector{T}}, dtype::Symbol = :central)
1818
Base.warn_once("The finite difference methods from Calculus.jl no longer extend Base.gradient and should be called as Calculus.gradient instead. This usage is deprecated.")
1919
Calculus.gradient(f,x,dtype)
2020
end
@@ -26,11 +26,11 @@ end
2626

2727
ctranspose(f::Function) = derivative(f)
2828

29-
function jacobian{T <: Number}(f::Function, x::Vector{T}, dtype::Symbol)
29+
function jacobian{T <: Number}(f::Function, x::AbstractVector{T}, dtype::Symbol)
3030
finite_difference_jacobian(f, x, dtype)
3131
end
3232
function jacobian(f::Function, dtype::Symbol)
33-
g(x::Vector) = finite_difference_jacobian(f, x, dtype)
33+
g(x::AbstractVector) = finite_difference_jacobian(f, x, dtype)
3434
return g
3535
end
3636
jacobian(f::Function) = jacobian(f, :central)
@@ -45,16 +45,16 @@ function second_derivative(f::Function, g::Function, ftype::Symbol, dtype::Symbo
4545
end
4646
return h
4747
end
48-
Compat.@compat function second_derivative{T <: Number}(f::Function, g::Function, x::Union{T, Vector{T}}, dtype::Symbol)
48+
Compat.@compat function second_derivative{T <: Number}(f::Function, g::Function, x::Union{T, AbstractVector{T}}, dtype::Symbol)
4949
finite_difference_hessian(f, g, x, dtype)
5050
end
51-
Compat.@compat function hessian{T <: Number}(f::Function, g::Function, x::Union{T, Vector{T}}, dtype::Symbol)
51+
Compat.@compat function hessian{T <: Number}(f::Function, g::Function, x::Union{T, AbstractVector{T}}, dtype::Symbol)
5252
finite_difference_hessian(f, g, x, dtype)
5353
end
54-
Compat.@compat function second_derivative{T <: Number}(f::Function, g::Function, x::Union{T, Vector{T}})
54+
Compat.@compat function second_derivative{T <: Number}(f::Function, g::Function, x::Union{T, AbstractVector{T}})
5555
finite_difference_hessian(f, g, x, :central)
5656
end
57-
Compat.@compat function hessian{T <: Number}(f::Function, g::Function, x::Union{T, Vector{T}})
57+
Compat.@compat function hessian{T <: Number}(f::Function, g::Function, x::Union{T, AbstractVector{T}})
5858
finite_difference_hessian(f, g, x, :central)
5959
end
6060
function second_derivative(f::Function, x::Number, dtype::Symbol)
@@ -63,10 +63,10 @@ end
6363
function hessian(f::Function, x::Number, dtype::Symbol)
6464
finite_difference_hessian(f, derivative(f), x, dtype)
6565
end
66-
function second_derivative{T <: Number}(f::Function, x::Vector{T}, dtype::Symbol)
66+
function second_derivative{T <: Number}(f::Function, x::AbstractVector{T}, dtype::Symbol)
6767
finite_difference_hessian(f, gradient(f), x, dtype)
6868
end
69-
function hessian{T <: Number}(f::Function, x::Vector{T}, dtype::Symbol)
69+
function hessian{T <: Number}(f::Function, x::AbstractVector{T}, dtype::Symbol)
7070
finite_difference_hessian(f, gradient(f), x, dtype)
7171
end
7272
function second_derivative(f::Function, x::Number)
@@ -75,10 +75,10 @@ end
7575
function hessian(f::Function, x::Number)
7676
finite_difference_hessian(f, derivative(f), x, :central)
7777
end
78-
function second_derivative{T <: Number}(f::Function, x::Vector{T})
78+
function second_derivative{T <: Number}(f::Function, x::AbstractVector{T})
7979
finite_difference_hessian(f, gradient(f), x, :central)
8080
end
81-
function hessian{T <: Number}(f::Function, x::Vector{T})
81+
function hessian{T <: Number}(f::Function, x::AbstractVector{T})
8282
finite_difference_hessian(f, gradient(f), x, :central)
8383
end
8484
second_derivative(f::Function, g::Function, dtype::Symbol) = second_derivative(f, g, :scalar, dtype)

src/finite_difference.jl

+11-11
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ end
9898
##############################################################################
9999

100100
function finite_difference!{S <: Number, T <: Number}(f::Function,
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)
@@ -136,7 +136,7 @@ function finite_difference!{S <: Number, T <: Number}(f::Function,
136136
return
137137
end
138138
function finite_difference{T <: Number}(f::Function,
139-
x::Vector{T},
139+
x::AbstractVector{T},
140140
dtype::Symbol = :central)
141141
# Allocate memory for gradient
142142
g = Array(Float64, length(x))
@@ -157,9 +157,9 @@ end
157157
function finite_difference_jacobian!{R <: Number,
158158
S <: Number,
159159
T <: Number}(f::Function,
160-
x::Vector{R},
161-
f_x::Vector{S},
162-
J::Array{T},
160+
x::AbstractVector{R},
161+
f_x::AbstractVector{S},
162+
J::AbstractArray{T},
163163
dtype::Symbol = :central)
164164
# What is the dimension of x?
165165
m, n = size(J)
@@ -192,7 +192,7 @@ function finite_difference_jacobian!{R <: Number,
192192
return
193193
end
194194
function finite_difference_jacobian{T <: Number}(f::Function,
195-
x::Vector{T},
195+
x::AbstractVector{T},
196196
dtype::Symbol = :central)
197197
# Establish a baseline for f_x
198198
f_x = f(x)
@@ -233,8 +233,8 @@ end
233233

234234
function finite_difference_hessian!{S <: Number,
235235
T <: Number}(f::Function,
236-
x::Vector{S},
237-
H::Array{T})
236+
x::AbstractVector{S},
237+
H::AbstractArray{T})
238238
# What is the dimension of x?
239239
n = length(x)
240240

@@ -265,7 +265,7 @@ function finite_difference_hessian!{S <: Number,
265265
Base.LinAlg.copytri!(H,'U')
266266
end
267267
function finite_difference_hessian{T <: Number}(f::Function,
268-
x::Vector{T})
268+
x::AbstractVector{T})
269269
# What is the dimension of x?
270270
n = length(x)
271271

@@ -280,7 +280,7 @@ function finite_difference_hessian{T <: Number}(f::Function,
280280
end
281281
function finite_difference_hessian{T <: Number}(f::Function,
282282
g::Function,
283-
x::Vector{T},
283+
x::AbstractVector{T},
284284
dtype::Symbol = :central)
285285
finite_difference_jacobian(g, x, dtype)
286286
end

0 commit comments

Comments
 (0)