Description
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.
Line 2 in b0ca0b0
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
.