1- import Base: eltype, length, size, getindex, iterate, convert, promote_rule, keys
1+ import Base: eltype, keytype, valtype, length, size, getindex, iterate, convert, promote_rule,
2+ keys, values, push!, pop!, empty!, haskey, get, get!, delete!
23
34# Type structure: leaving things open for adding anisotropic Gaussians and GMMs
45
@@ -41,7 +42,10 @@ iterate(gmm::AbstractSingleGMM) = iterate(gmm.gaussians)
4142iterate (gmm:: AbstractSingleGMM , i) = iterate (gmm. gaussians, i)
4243size (gmm:: AbstractSingleGMM{N,T} ) where {N,T} = (length (gmm. gaussians), N)
4344size (gmm:: AbstractSingleGMM{N,T} , idx:: Int ) where {N,T} = (length (gmm. gaussians), N)[idx]
44- eltype (gmm:: AbstractSingleGMM ) = eltype (gmm. gaussians);
45+ eltype (gmm:: AbstractSingleGMM ) = eltype (gmm. gaussians)
46+ push! (gmm:: AbstractSingleGMM , g:: AbstractGaussian ) = push! (gmm. gaussians, g)
47+ pop! (gmm:: AbstractSingleGMM ) = pop! (gmm. gaussians)
48+ empty! (gmm:: AbstractSingleGMM ) = empty! (gmm. gaussians)
4549
4650coords (gmm:: AbstractSingleGMM ) = hcat ([g. μ for g in gmm. gaussians]. .. )
4751weights (gmm:: AbstractSingleGMM ) = [g. ϕ for g in gmm. gaussians]
@@ -54,7 +58,16 @@ iterate(mgmm::AbstractMultiGMM) = iterate(mgmm.gmms)
5458iterate (mgmm:: AbstractMultiGMM , i) = iterate (mgmm. gmms, i)
5559size (mgmm:: AbstractMultiGMM{N,T,K} ) where {N,T,K} = (length (mgmm. gmms), N)
5660size (mgmm:: AbstractMultiGMM{N,T,K} , idx:: Int ) where {N,T,K} = (length (mgmm. gmms), N)[idx]
57- eltype (mgmm:: AbstractMultiGMM ) = eltype (mgmm. gmms);
61+ eltype (mgmm:: AbstractMultiGMM ) = eltype (mgmm. gmms)
62+ eltype (:: Type{MGMM} ) where MGMM<: AbstractMultiGMM = Pair{keytype (MGMM),valtype (MGMM)}
63+ keytype (mgmm:: AbstractMultiGMM ) = keytype (typeof (mgmm))
64+ keytype (:: Type{<:AbstractMultiGMM{N,T,K}} ) where {N,T,K} = K
65+ valtype (mgmm:: AbstractMultiGMM ) = valtype (mgmm. gmms)
66+ haskey (mgmm:: AbstractMultiGMM , k) = haskey (mgmm. gmms, k)
67+ get (mgmm:: AbstractMultiGMM , k, default) = get (mgmm. gmms, k, default)
68+ get! (:: Type{V} , mgmm:: AbstractMultiGMM , k) where V = get! (V, mgmm. gmms, k)
69+ delete! (mgmm:: AbstractMultiGMM , k) = delete! (mgmm. gmms, k)
70+ empty! (mgmm:: AbstractMultiGMM ) = empty! (mgmm. gmms)
5871
5972coords (mgmm:: AbstractMultiGMM ) = hcat ([coords (gmm) for (k,gmm) in mgmm. gmms]. .. )
6073weights (mgmm:: AbstractMultiGMM ) = vcat ([weights (gmm) for (k,gmm) in mgmm. gmms]. .. )
7992
8093IsotropicGaussian (g:: AbstractIsotropicGaussian ) = IsotropicGaussian (g. μ, g. σ, g. ϕ)
8194
82- convert (:: Type{IsotropicGaussian{N,T}} , g:: AbstractIsotropicGaussian ) where {N,T} = IsotropicGaussian ( SVector {N,T} (g. μ), T ( g. σ), T ( g. ϕ) )
95+ convert (:: Type{IsotropicGaussian{N,T}} , g:: AbstractIsotropicGaussian ) where {N,T} = IsotropicGaussian {N,T} (g. μ, g. σ, g. ϕ)
8396promote_rule (:: Type{IsotropicGaussian{N,T}} , :: Type{IsotropicGaussian{N,S}} ) where {N,T<: Real ,S<: Real } = IsotropicGaussian{N,promote_type (T,S)}
8497
8598(g:: IsotropicGaussian )(pos:: AbstractVector ) = exp (- sum (abs2, pos- g. μ)/ (2 * g. σ^ 2 ))* g. ϕ
@@ -92,11 +105,13 @@ struct IsotropicGMM{N,T} <: AbstractIsotropicGMM{N,T}
92105end
93106
94107IsotropicGMM (gmm:: AbstractIsotropicGMM ) = IsotropicGMM (gmm. gaussians)
108+ IsotropicGMM {N,T} () where {N,T} = IsotropicGMM {N,T} (IsotropicGaussian{N,T}[])
95109
96- convert (t :: Type{IsotropicGMM } , gmm:: AbstractIsotropicGMM ) = t (gmm. gaussians)
110+ convert (:: Type{GMM } , gmm:: AbstractIsotropicGMM ) where GMM <: IsotropicGMM = GMM (gmm. gaussians)
97111promote_rule (:: Type{IsotropicGMM{N,T}} , :: Type{IsotropicGMM{N,S}} ) where {T,S,N} = IsotropicGMM{N,promote_type (T,S)}
112+ eltype (:: Type{IsotropicGMM{N,T}} ) where {N,T} = IsotropicGaussian{N,T}
98113
99- (gmm:: IsotropicGMM )(pos:: AbstractVector ) = sum (g (pos) for g in gmm. gaussians )
114+ (gmm:: IsotropicGMM )(pos:: AbstractVector ) = sum (g (pos) for g in gmm)
100115
101116"""
102117A collection of labeled `IsotropicGMM`s, to each be considered separately during an alignment procedure. That is,
@@ -110,6 +125,7 @@ IsotropicMultiGMM(gmm::AbstractIsotropicMultiGMM) = IsotropicMultiGMM(gmm.gmms)
110125
111126convert (t:: Type{IsotropicMultiGMM} , mgmm:: AbstractIsotropicMultiGMM ) = t (mgmm. gmms)
112127promote_rule (:: Type{IsotropicMultiGMM{N,T,K}} , :: Type{IsotropicMultiGMM{N,S,K}} ) where {N,T,S,K} = IsotropicMultiGMM{N,promote_type (T,S),K}
128+ valtype (:: Type{IsotropicMultiGMM{N,T,K}} ) where {N,T,K} = IsotropicGMM{N,T}
113129
114130# descriptive display
115131# TODO update to display type parameters, make use of supertypes, etc
0 commit comments