Skip to content

Error when hashing Measurement{Float64} #103

@jwscook

Description

@jwscook

Hello,

I've encountered this error:

julia> hash(1.0 ± 0.1)
ERROR: MethodError: no method matching decompose(::Measurement{Float64})
Closest candidates are:
  decompose(::Integer) at float.jl:555
  decompose(::Float16) at float.jl:557
  decompose(::Float32) at float.jl:568
  ...
Stacktrace:
 [1] hash(x::Measurement{Float64}, h::UInt64)
   @ Base ./float.jl:491
 [2] hash(x::Measurement{Float64})
   @ Base ./hashing.jl:18
 [3] top-level scope
   @ REPL[6]:1

What would the fix be? Declare hash by hand or implement decompose?

Something like:

Base.hash(m::Measurement) = foldr(hash, (m.val, m.err, m.der, m.tag))

or maybe if tag can be hijacked:

Base.hash(m::Measurement) = foldr(hash, (m.val, m.err, m.der); init=m.tag)

Versions:

 [eff96d63] Measurements v2.6.0
 Version 1.6.1-pre.39 (2021-04-17)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions