Skip to content

Commit 0d98b27

Browse files
committed
update code to be rid of dep warnings on v0.6
1 parent 92d260e commit 0d98b27

3 files changed

Lines changed: 143 additions & 166 deletions

File tree

src/VarianceComponentModels.jl

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ model.
2323
- `lb`: lower bounds for `vec(B)`
2424
- `ub`: upper bounds for `vec(B)`
2525
"""
26-
type VarianceComponentModel{T <: AbstractFloat, M,
26+
mutable struct VarianceComponentModel{T <: AbstractFloat, M,
2727
BT <: AbstractVecOrMat, ΣT <: AbstractMatrix}
2828
# model parameters
2929
B::BT
@@ -34,12 +34,6 @@ type VarianceComponentModel{T <: AbstractFloat, M,
3434
b::Union{T, Vector{T}}
3535
lb::Union{T, Vector{T}}
3636
ub::Union{T, Vector{T}}
37-
# inner constructor
38-
function VarianceComponentModel(B::AbstractVecOrMat{T},
39-
Σ::NTuple{M, AbstractMatrix{T}}, A::Matrix{T}, sense::Union{Char, Vector{Char}},
40-
b::Union{T, Vector{T}}, lb::Union{T, Vector{T}}, ub::Union{T, Vector{T}})
41-
new(B, Σ, A, sense, b, lb, ub)
42-
end
4337
end
4438

4539
"""
@@ -48,15 +42,15 @@ end
4842
4943
Default constructor of [`VarianceComponentModel`](@ref) type.
5044
"""
51-
function VarianceComponentModel{M}(
45+
function VarianceComponentModel(
5246
B::AbstractVecOrMat,
5347
Σ::NTuple{M, AbstractMatrix},
5448
A::Matrix = zeros(eltype(B), 0, length(B)),
5549
sense::Union{Char, Vector{Char}} = Array{Char}(0),
5650
b::Union{Number, Vector} = zeros(eltype(B), 0),
5751
lb::Union{Number, Vector} = convert(eltype(B), -Inf),
5852
ub::Union{Number, Vector} = convert(eltype(B), Inf),
59-
)
53+
) where {M}
6054

6155
VarianceComponentModel{eltype(B), M, typeof(B), eltype(Σ)}(B, Σ, A, sense, b,
6256
lb, ub)
@@ -67,7 +61,7 @@ end
6761
6862
Construct [`VarianceComponentModel`](@ref) from `Σ` alone. `B` is treated empty.
6963
"""
70-
function VarianceComponentModel{M}::NTuple{M, AbstractMatrix})
64+
function VarianceComponentModel::NTuple{M, AbstractMatrix}) where {M}
7165
B = zeros(eltype(Σ[1]), 0, size(Σ[1], 1))
7266
VarianceComponentModel(B, Σ)
7367
end
@@ -81,15 +75,11 @@ end
8175
- `eigvec`: eigenvectors of `eig(Σ[1], Σ[2])`
8276
- `logdetΣ2`: log-determinant of `Σ[2]`
8377
"""
84-
immutable TwoVarCompModelRotate{T <: AbstractFloat, BT <: AbstractVecOrMat}
78+
struct TwoVarCompModelRotate{T <: AbstractFloat, BT <: AbstractVecOrMat}
8579
Brot::BT
8680
eigval::Vector{T}
8781
eigvec::Matrix{T}
8882
logdetΣ2::T
89-
function TwoVarCompModelRotate(Brot::AbstractVecOrMat{T},
90-
eigval::Vector{T}, eigvec::Matrix{T}, logdetΣ2::T)
91-
new(Brot, eigval, eigvec, logdetΣ2)
92-
end
9383
end
9484

9585
"""
@@ -137,17 +127,12 @@ model.
137127
- `X`: `n x p` predictors
138128
- `V`: tuple of `n x n` covariance matrices
139129
"""
140-
type VarianceComponentVariate{T <: AbstractFloat, M,
130+
mutable struct VarianceComponentVariate{T <: AbstractFloat, M,
141131
YT <: AbstractVecOrMat, XT <: AbstractVecOrMat, VT <: AbstractMatrix}
142132
# data
143133
Y::YT
144134
X::XT
145135
V::NTuple{M, VT}
146-
# inner constructor
147-
function VarianceComponentVariate(Y::AbstractVecOrMat{T},
148-
X::AbstractVecOrMat{T}, V::NTuple{M, AbstractMatrix{T}})
149-
new(Y, X, V)
150-
end
151136
end
152137

153138
"""
@@ -189,20 +174,14 @@ end
189174
- `eigvec`: eigenvectors of `eig(V[1], V[2])`
190175
- `logdetV2`: log-determinant of `V[2]`
191176
"""
192-
immutable TwoVarCompVariateRotate{T <: AbstractFloat, YT <: AbstractVecOrMat,
177+
struct TwoVarCompVariateRotate{T <: AbstractFloat, YT <: AbstractVecOrMat,
193178
XT <: AbstractVecOrMat}
194179
# data
195180
Yrot::YT
196181
Xrot::XT
197182
eigval::Vector{T}
198183
eigvec::Matrix{T}
199184
logdetV2::T
200-
201-
# inner constructor
202-
function TwoVarCompVariateRotate(Yrot::AbstractVecOrMat{T},
203-
Xrot::AbstractVecOrMat{T}, eigval::Vector{T}, eigvec::Matrix{T}, logdetV2::T)
204-
new(Yrot, Xrot, eigval, eigvec, logdetV2)
205-
end
206185
end
207186

208187
"""
@@ -268,7 +247,7 @@ Construct a [`VarianceComponentModel`](@ref) instance from a [`VarianceComponent
268247
instance. `B` is initialized to zero; `Σ` is initialized to a tupe of identity
269248
matrices.
270249
"""
271-
function VarianceComponentModel{T, M}(vcobs::VarianceComponentVariate{T, M})
250+
function VarianceComponentModel(vcobs::VarianceComponentVariate{T, M}) where {T, M}
272251

273252
p, d, m = size(vcobs.X, 2), size(vcobs.Y, 2), length(vcobs.V)
274253
B = zeros(T, p, d)
@@ -295,7 +274,7 @@ end
295274
Auxillary data for variance component model. This can be used as pre-allocated
296275
intermediate variable in iterative algorithm.
297276
"""
298-
immutable VarianceComponentAuxData{
277+
struct VarianceComponentAuxData{
299278
T1 <: AbstractMatrix,
300279
T2 <: AbstractVector
301280
}
@@ -485,10 +464,10 @@ function residual(vcm::VarianceComponentModel, vcobs::VarianceComponentVariate)
485464
return isempty(vcobs.X)? vcobs.Y : vcobs.Y - vcobs.X * vcm.B
486465
end
487466

488-
function residual{T1 <: VarianceComponentModel, T2 <: VarianceComponentVariate}(
467+
function residual(
489468
vcm::T1,
490469
vcdata::Array{T2}
491-
)
470+
) where {T1 <: VarianceComponentModel, T2 <: VarianceComponentVariate}
492471

493472
map(x -> residual(vcm, x), vcdata)
494473
end
@@ -509,11 +488,11 @@ function residual!(
509488
resid
510489
end
511490

512-
function residual!{T1 <: VarianceComponentModel, T2 <: VarianceComponentVariate}(
491+
function residual!(
513492
resid::AbstractArray,
514493
vcm::T1,
515494
vcdata::Array{T2}
516-
)
495+
) where {T1 <: VarianceComponentModel, T2 <: VarianceComponentVariate}
517496

518497
map(x -> residual!(x[1], vcm, x[2]), zip(resid, vcdata))
519498
end
@@ -531,10 +510,10 @@ function residual(vcmrot::TwoVarCompModelRotate, vcobsrot::TwoVarCompVariateRota
531510
end
532511
end
533512

534-
function residual{T1 <: TwoVarCompModelRotate, T2 <: TwoVarCompVariateRotate}(
513+
function residual(
535514
vcmrot::T1,
536515
vcdatarot::Array{T2}
537-
)
516+
) where {T1 <: TwoVarCompModelRotate, T2 <: TwoVarCompVariateRotate}
538517

539518
map(x -> residual(vcmrot, x), vcdatarot)
540519
end
@@ -556,10 +535,10 @@ function residual!(
556535
resid
557536
end
558537

559-
function residual!{T1 <: TwoVarCompModelRotate, T2 <: TwoVarCompVariateRotate}(
538+
function residual!(
560539
resid::Array{AbstractMatrix},
561540
vcmrot::T1,
562-
vcdatarot::Array{T2})
541+
vcdatarot::Array{T2}) where {T1 <: TwoVarCompModelRotate, T2 <: TwoVarCompVariateRotate}
563542

564543
map!(x -> residual(vcmrot, x), resid, vcdatarot)
565544
end

src/multivariate_calculus.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ duplication(M::AbstractMatrix) = duplication(eltype(M), size(M, 1))
115115
Compute the gradient `d / d vec(X)` from a vector of derivatives `dM` where
116116
`M=X⊗Y`, `n, q = size(X)`, and `p, r = size(Y)`.
117117
"""
118-
function kron_gradient!{T <: Real}(g::VecOrMat{T}, dM::VecOrMat{T},
119-
Y::Matrix{T}, n::Integer, q::Integer)
118+
function kron_gradient!(g::VecOrMat{T}, dM::VecOrMat{T},
119+
Y::Matrix{T}, n::Integer, q::Integer) where {T <: Real}
120120
p, r = size(Y)
121121
A_mul_B!(g, kron(speye(n * q), vec(Y)'),
122122
(kron(speye(q), spcommutation(n, r), speye(p)) * dM))
123123
end
124-
function kron_gradient{T <: Real}(dM::VecOrMat{T}, Y::Matrix{T},
125-
n::Integer, q::Integer)
124+
function kron_gradient(dM::VecOrMat{T}, Y::Matrix{T},
125+
n::Integer, q::Integer) where {T <: Real}
126126
if ndims(dM) == 1
127127
g = zeros(T, n * q)
128128
else
@@ -138,13 +138,13 @@ Compute the gradient `d / d vech(L)` from a vector of derivatives `dM` where
138138
`M=L*L'`.
139139
# TODO make it more memory efficient
140140
"""
141-
function chol_gradient!{T <: Real}(g::AbstractVecOrMat{T},
142-
dM::AbstractVecOrMat{T}, L::AbstractMatrix{T})
141+
function chol_gradient!(g::AbstractVecOrMat{T},
142+
dM::AbstractVecOrMat{T}, L::AbstractMatrix{T}) where {T <: Real}
143143
n = size(L, 1)
144144
At_mul_B!(g, spduplication(n),
145145
kron(L', speye(n)) * (dM + spcommutation(n) * dM))
146146
end
147-
function chol_gradient{T <: Real}(dM::AbstractVecOrMat{T}, L::AbstractMatrix{T})
147+
function chol_gradient(dM::AbstractVecOrMat{T}, L::AbstractMatrix{T}) where {T <: Real}
148148
n = size(L, 1)
149149
if ndims(dM) == 1 # vector
150150
g = zeros(T, binomial(n + 1, 2))
@@ -159,8 +159,8 @@ end
159159
160160
Overwrites `Y` with `A ⊗ X + Y`. Same as `Y += kron(A, X)` but more efficient.
161161
"""
162-
function kronaxpy!{T <: Real}(A::AbstractVecOrMat{T},
163-
X::AbstractVecOrMat{T}, Y::AbstractVecOrMat{T})
162+
function kronaxpy!(A::AbstractVecOrMat{T},
163+
X::AbstractVecOrMat{T}, Y::AbstractVecOrMat{T}) where {T <: Real}
164164

165165
# retrieve matrix sizes
166166
m, n = size(A, 1), size(A, 2)
@@ -182,7 +182,7 @@ end
182182
"""
183183
Add `ϵ` to the diagonal entries of matrix `A`.
184184
"""
185-
function bump_diagonal!{T}(A::Matrix{T}, ϵ::T)
185+
function bump_diagonal!(A::Matrix{T}, ϵ::T) where {T}
186186
@inbounds @simd for i in 1:minimum(size(A))
187187
A[i, i] += ϵ
188188
end
@@ -192,7 +192,7 @@ end
192192
"""
193193
Clamp the diagonal entries of matrix `A` to `[lo, hi]`.
194194
"""
195-
function clamp_diagonal!{T}(A::Matrix{T}, lo::T, hi::T)
195+
function clamp_diagonal!(A::Matrix{T}, lo::T, hi::T) where {T}
196196
@inbounds @simd for i in 1:minimum(size(A))
197197
A[i, i] = clamp(A[i, i], lo, hi)
198198
end

0 commit comments

Comments
 (0)