Open tfiers opened 1 year ago
Problem with the "switch between fake and real units": global constants / typeds
The monster:
@code_typed 3u"mV"/8u"s"
CodeInfo(
1 โ %1 = Base.getfield(x, :val)::Int64
โ %2 = Base.getfield(y, :val)::Int64
โ %3 = Base.sitofp(Float64, %1)::Float64
โ %4 = Base.sitofp(Float64, %2)::Float64
โ %5 = Base.div_float(%3, %4)::Float64
โ %6 = %new(Quantity{Float64, ๐ ^2 ๐ ๐ ^-1 ๐ ^-4, Unitful.FreeUnits{(s^-1, mV), ๐ ^2 ๐ ๐ ^-1 ๐ ^-4, nothing}}, %5)::Quantity{Float64, ๐^2 ๐ ๐^-1 ๐^-4, Unitful.FreeUnits{(s^-1, mV), ๐^2 ๐ ๐^-1 ๐^-4, nothing}}
โโโ return %6
) => Quantity{Float64, ๐ ^2 ๐ ๐ ^-1 ๐ ^-4, Unitful.FreeUnits{(s^-1, mV), ๐ ^2 ๐ ๐ ^-1 ๐ ^-4, nothing}}
Simplification of Unitful types, maybe:
Quantity{Float64, Unit{(mV, s^-1), L^2 M I^-1 T^-4}}
Quantity{Float64, Unit{(mV, sโปยน), Lยฒ M Iโปยน Tโปโด}}
Quantity{Float64, Unit{(mV/s), M Lยฒ / (Tโด I)}
Quantity{Float64, Unit{(mV /s), M Lยฒ /Tโด /I)}
Quantity{Float64, Unit{mV/s, Voltage/Time}}
Quantity{Float64, Unit{V, Tโปยน}}
Val{Float64, Unit{V, Tโปยน}}
(ofc, yes, "try not to display types; display values instead". ofc in practice that's no go, starting with just having a Vector of those. grrr. (#julia annoyance))
what's those thangs in type
julia> q = 3m / 8s
0.375 m s^-1
julia> u = unit(q)
m s^-1
julia> T = typeof(u)
Unitful.FreeUnits{(m, s^-1), ๐ ๐ ^-1, nothing}
julia> T.parameters[1][2]
s^-1
julia> typeof(T.parameters[1][2])
Unitful.Unit{:Second, ๐ }
wat. where'd the -1 go.
julia> typeof(Unitful.s)
Unitful.FreeUnits{(s,), ๐ , nothing}
ah:
julia> x=T.parameters[1][2];
s^-1
julia> dump(x)
Unitful.Unit{:Second, ๐ }
tens: Int64 0
power: Rational{Int64}
num: Int64 -1
den: Int64 1
julia> isbits(x)
true
The above means that a sโปยน
repr is for sure possible :)
Problem with the "switch between fake and real units": global constants / typeds
Well, we'll just export two modules :)
And then user just needs to switch the using
stmt.
(SpikeWorks.Units
and SpikeWorks.FakeUnits
, or sth)
very impressive
implementation: