Keno / SIUnits.jl

Efficient unit-checked computation
Other
70 stars 26 forks source link

Promotion error on latest 0.5 master #84

Open ssfrr opened 8 years ago

ssfrr commented 8 years ago

Seems that something has changed with the way values are promoted during array/scalar multiplication:

julia> collect(1:5) * Hz
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type SIUnits.SIUnit{0,0,-1,0,0,0,0,0,0}
This may have arisen from a call to the constructor SIUnits.SIUnit{0,0,-1,0,0,0,0,0,0}(...),
since type constructors fall back to convert methods.
 in promote_op(::Base.#.*, ::Type{Int64}, ::Type{SIUnits.SIUnit{0,0,-1,0,0,0,0,0,0}}) at ./number.jl:73
 in .*(::Array{Int64,1}, ::SIUnits.SIUnit{0,0,-1,0,0,0,0,0,0}) at ./arraymath.jl:78
 in *(::Array{Int64,1}, ::SIUnits.SIUnit{0,0,-1,0,0,0,0,0,0}) at ./abstractarraymath.jl:55
 in eval(::Module, ::Any) at ./boot.jl:234
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46
julia> versioninfo()
Julia Version 0.5.0-dev+5440
Commit edb112a* (2016-07-14 21:40 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)
pabloferz commented 8 years ago

If you need this to work before there is a fix of the issue in base you can define the following before trying to call anything like collect(1:5) * Hz for the first time

Base.promote_op{T<:Number,m,kg,s,A,K,mol,cd,rad,sr}(op, ::Type{SIUnits.SIUnit{m,kg,s,A,K,mol,cd,rad,sr}}, ::Type{T}) =
    SIUnits.SIQuantity{T,m,kg,s,A,K,mol,cd,rad,sr}
Base.promote_op{T<:Number,m,kg,s,A,K,mol,cd,rad,sr}(op, ::Type{T}, ::Type{SIUnits.SIUnit{m,kg,s,A,K,mol,cd,rad,sr}}) =
    SIUnits.SIQuantity{T,m,kg,s,A,K,mol,cd,rad,sr}