Skip to content

Commit

Permalink
allow NamedTuples in more places where Tuple is accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Mar 15, 2018
1 parent 9e30063 commit 1fcbc8e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/OnlineStatsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ default_weight(o::ExactStat) = EqualWeight()
abstract type StochasticStat{N} <: OnlineStat{N} end
default_weight(o::StochasticStat) = LearningRate()

function default_weight(t::Tuple)
function default_weight(t::Union{Tuple, NamedTuples.NamedTuple})
W = default_weight(first(t))
all(default_weight.(t) .== W) ||
error("Weight must be specified when defaults differ. Found: $(name.(default_weight.(t))).")
for item in t
default_weight(item) != W &&
error("Weight must be specified when defaults differ. Found:")
end
return W
end

Expand Down

0 comments on commit 1fcbc8e

Please sign in to comment.