The type of AbstractWeights is restricted to Real which precludes complex numbers, numbers with units from Unitful, etc. Using Number for the most general type would be more inclusive.
|
abstract type AbstractWeights{S<:Real, T<:Real, V<:AbstractVector{T}} <: AbstractVector{T} end |
Of course many subtypes like ProbabilityWeights must be Real, but general weights do not, especially for how weights are used in the fit method for a Histogram. The follow MWE ideally would work, but fails due to the weights() method restrictions:
using StatsBase
#T = Float32 # this version works fine
T = ComplexF64 # this version errors at weights(w)
w = rand(T, 100) # weights
data = randn(100)
fit(Histogram, data, weights(w))
An alternative to generalizing the AbstractWeights type would be to generalize the fit method so that the weights can simply be any Number type.
I would be eventually willing to help with a PR if there is openness to such a generalization, but it would helpful to know if there is a preference between generalizing Weights vs generalizing fit.
The type of
AbstractWeightsis restricted toRealwhich precludes complex numbers, numbers with units from Unitful, etc. UsingNumberfor the most general type would be more inclusive.StatsBase.jl/src/weights.jl
Line 2 in b0ca0b0
Of course many subtypes like
ProbabilityWeightsmust be Real, but general weights do not, especially for how weights are used in thefitmethod for aHistogram. The follow MWE ideally would work, but fails due to theweights()method restrictions:An alternative to generalizing the
AbstractWeightstype would be to generalize thefitmethod so that the weights can simply be any Number type.I would be eventually willing to help with a PR if there is openness to such a generalization, but it would helpful to know if there is a preference between generalizing
Weightsvs generalizingfit.