Skip to content

Throw better error when normalize! is called for Histogram with non-floating point weights #936

Open
@david-macmahon

Description

@david-macmahon

When normalizing a Histogram, the normalize function produces floating point values for the weights. The in-place version (i.e. normalize!) can only be called for Histograms that have floating point weights. When calling normalize! on a Histogram with non-floating point weights the resulting "no method matching..." MethodError is technically correct, but it would be more helpful to display a more informative message. This could be done my defining:

function normalize!(h::Histogram{T,N}, aux_weights::Array{T,N}...; mode::Symbol=:pdf) where {T,N}
    error("Cannot normalize a Histogram with $T weights in-place")
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions