-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change behavior of one
to match Unitful
#42
Conversation
one
for compatibility with QuadGK.jlone
to match Unitful
Hm, I do also appreciate the property julia> q = 1u"kg/s"
1.0 kg s⁻¹
julia> arr_empty = typeof(q)[]
Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}[]
julia> arr = [q]
1-element Vector{Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}:
1.0 kg s⁻¹
julia> prod(arr_empty) |> typeof
Float64
julia> prod(arr) |> typeof
Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}
julia> @code_warntype prod(arr)
MethodInstance for prod(::Vector{Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}})
from prod(a::AbstractArray; dims, kw...) @ Base reducedim.jl:996
Arguments
#self#::Core.Const(prod)
a::Vector{Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}
Body::Union{Float64, Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}
1 ─ nothing
│ %2 = Base.:(:)::Core.Const(Colon())
│ %3 = Core.NamedTuple()::Core.Const(NamedTuple())
│ %4 = Base.pairs(%3)::Core.Const(Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}())
│ %5 = Base.:(var"#prod#831")(%2, %4, #self#, a)::Union{Float64, Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}
└── return %5 |
Great point. Do you want to repost this on #40? |
Will cherry pick the |
Closing as we have BaseType.base_numeric_type now |
cc @mikeingold @stevengj
This is a draft PR to modify
one(q)
to returnone(ustrip(q))
rather than a dimensionless quantity, to match the behavior of Unitful.jl. This also makesAbstractQuantity <: Number
.Fixes #40
Also @gaurav-arya what do you think? Apparently we need this for compatibility with packages that use Unitful.
TODO:
one
)