ggebbie / UnitfulLinearAlgebra.jl

Low-cost linear algebra functions for matrices with units
MIT License
6 stars 3 forks source link

diag for a permil matrix multiplies in the permils and returns a unitless quantity #77

Closed b-r-hamilton closed 1 year ago

b-r-hamilton commented 1 year ago

MWE

julia> using Unitful, UnitfulLinearAlgebra, LinearAlgebra

julia> mat = UnitfulMatrix(ones(2,2).*u"permille")
2×2 UnitfulMatrix{Float64,2}
 1.0 ‰  1.0 ‰
 1.0 ‰  1.0 ‰

julia> diag(mat)
2-element Vector{Float64}:
 0.001
 0.001

julia> 
b-r-hamilton commented 1 year ago

works fine for quantities like Kelvin

julia> mat = UnitfulMatrix(ones(2,2).*u"K")
2×2 UnitfulMatrix{Float64,2}
 1.0 K  1.0 K
 1.0 K  1.0 K

julia> diag(mat)
2-element Vector{Quantity}:
 1.0 K
 1.0 K
ggebbie commented 1 year ago

made 2 fixes, full accounting in comment for PR #80

please check that it works for you

julia> using Unitful, UnitfulLinearAlgebra, LinearAlgebra

julia> permil = Unitful.FixedUnits(u"permille")
‰

julia> K = u"K"
K

julia> mat = UnitfulMatrix(ones(2,2)*permil*K)
2×2 UnitfulMatrix{Float64,2}
 1.0 K ‰  1.0 K ‰
 1.0 K ‰  1.0 K ‰

julia> diag(mat)
2-element Vector{Quantity}:
 1.0 K ‰
 1.0 K ‰