Skip to content

Commit

Permalink
improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
xukai92 committed Sep 16, 2019
1 parent 0297f47 commit ef2db2f
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/adaptation/precond.jl
Expand Up @@ -141,7 +141,6 @@ UnitPreconditioner(::Type{T}=Float64) where {T} = UnitPreconditioner{T}()
string(::UnitPreconditioner) = "I"
reset!(::UnitPreconditioner) = nothing
getM⁻¹(dpc::UnitPreconditioner{T}) where {T<:AbstractFloat} = UniformScaling{T}(one(T))

adapt!(
::UnitPreconditioner,
::AbstractVector{<:Real},
Expand All @@ -150,7 +149,11 @@ adapt!(
) = nothing


mutable struct DiagPreconditioner{T<:Real, AT<:AbstractVector{T}, TEst <: VarEstimator{T}} <: AbstractPreconditioner
mutable struct DiagPreconditioner{
T<:Real,
AT<:AbstractVector{T},
TEst<:VarEstimator{T}
} <: AbstractPreconditioner
n_min :: Int
ve :: TEst
var :: AT
Expand All @@ -159,7 +162,12 @@ Base.show(io::IO, ::DiagPreconditioner) = print(io, "DiagPreconditioner")

# Diagonal
DiagPreconditioner(d::Int, n_min::Int=10) = DiagPreconditioner(Float64, d, n_min)
function DiagPreconditioner(::Type{T}, d::Int; n_min::Int=10, var=Vector(ones(T, d))) where {T}
function DiagPreconditioner(
::Type{T},
d::Int;
n_min::Int=10,
var=Vector(ones(T, d))
) where {T}
ve = WelfordVar(T, d)
return DiagPreconditioner(n_min, ve, var)
end
Expand All @@ -183,15 +191,23 @@ function adapt!(
end

# Dense
mutable struct DensePreconditioner{T<:AbstractFloat, TEst <: CovEstimator{T}} <: AbstractPreconditioner
mutable struct DensePreconditioner{
T<:AbstractFloat,
TEst<:CovEstimator{T}
} <: AbstractPreconditioner
n_min :: Int
ce :: TEst
covar :: Matrix{T}
end
Base.show(io::IO, ::DensePreconditioner) = print(io, "DensePreconditioner")

DensePreconditioner(d::Int, n_min::Int=10) = DensePreconditioner(Float64, d, n_min)
function DensePreconditioner(::Type{T}, d::Int; n_min::Int=10, covar=LinearAlgebra.diagm(0 => ones(T, d))) where {T}
function DensePreconditioner(
::Type{T},
d::Int;
n_min::Int=10,
covar=LinearAlgebra.diagm(0 => ones(T, d))
) where {T}
ce = WelfordCov(T, d)
# TODO: take use of the line below when we have an interface to set which covariance estimator to use
# ce = NaiveCov(T)
Expand Down Expand Up @@ -363,4 +379,4 @@ Preconditioner(m::DiagEuclideanMetric{T}) where {T} = DiagPreconditioner(T, m.di
Preconditioner(m::DenseEuclideanMetric{T}) where {T} = DensePreconditioner(T, m.dim; covar=m.M⁻¹)

Preconditioner(m::Type{TM}, dim::Int=2) where {TM<:AbstractMetric} = Preconditioner(Float64, m, dim)
Preconditioner(::Type{T}, ::Type{TM}, dim::Int=2) where {T<:AbstractFloat,TM<:AbstractMetric} = Preconditioner(TM(T, dim))
Preconditioner(::Type{T}, ::Type{TM}, dim::Int=2) where {T<:AbstractFloat, TM<:AbstractMetric} = Preconditioner(TM(T, dim))

0 comments on commit ef2db2f

Please sign in to comment.