Skip to content

Commit

Permalink
part merging
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Mar 19, 2020
1 parent 78771cb commit f81379f
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/part.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,21 @@ end

function _merge!(a::Part, b::Part)
merge!(a.stat, b.stat)
merge!(a.domain, b.domain, a.stat, b.stat)
merge!(a.domain, b.domain)
end



#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------# Domains
#-----------------------------------------------------------------------------#
abstract type Domain end

Base.merge!(a::Domain, b::Domain, astat, bstat) = merge!(a, b)

# Required methods:
# - Base.merge!
# - Base.in
# - Base.isless

#-----------------------------------------------------------------------------# Centroid
mutable struct Centroid{T} <: Domain
mutable struct Centroid{T}
center::T
end

Expand All @@ -43,27 +39,29 @@ Base.in(x, c::Centroid) = false
Base.isless(a::Centroid, b::Centroid) = isless(a.center, b.center)
Base.show(io::IO, c::Centroid) = print(io, "Centroid: $(c.center)")

function Base.merge!(a::Centroid{<:Number}, b::Centroid{<:Number}, astat, bstat)
w = nobs(bstat) / nobs(astat)
a.center = smooth(a.center, b.center, w)
function Base.merge!(a::Part{Centroid{T}, O}, b::Part{Centroid{T}, O}) where {T <: Number, O}
merge!(a.stat, b.stat)
a.domain.center = smooth(a.domain.center, b.domain.center, nobs(b) / nobs(a))
a
end
function Base.merge!(a::Centroid, b::Centroid, astat, bstat)
w = nobs(bstat) / nobs(astat)
smooth!(a.center, b.center, w)
function Base.merge!(a::Part{Centroid{T}, O}, b::Part{Centroid{T}, O}) where {T, O}
merge!(a.stat, b.stat)
smooth!(a.domain.center, b.domain.center, nobs(b) / nobs(a))
a
end

#-----------------------------------------------------------------------------# ClosedInterval
mutable struct ClosedInterval{T} <: Domain
mutable struct ClosedInterval{T}
first::T
last::T
ClosedInterval(a::T, b::T) where {T} = a b ? new{T}(a,b) : error("Arguments must be ordered: [$a, $b]")
end
Base.show(io::IO, b::ClosedInterval) = print(io, "ClosedInterval: [$(b.first), $(b.last)]")
Base.in(x, bucket::ClosedInterval) = bucket.first x bucket.last
Base.isless(a::ClosedInterval, b::ClosedInterval) = isless(a.first, b.first)
function Base.merge!(a::ClosedInterval, b::ClosedInterval, astat, bstat)


function Base.merge!(a::ClosedInterval, b::ClosedInterval)
a.first = min(a.first, b.first)
a.last = max(a.last, b.last)
a
Expand Down

0 comments on commit f81379f

Please sign in to comment.