@@ -96,31 +96,29 @@ expand_units(q::QuantityArray) = expand_units.(q)
96
96
97
97
"""
98
98
as_u(q::AbstractQuantity{<:Any, <:Dimensions}, qout::AbstractQuantity{<:Any, <:SymbolicDimensions})
99
+ as_u(q::AbstractQuantity{<:Any, <:Dimensions}, ustr::String)
99
100
100
101
Convert a quantity `q` with base SI units to the symbolic units of `qout`, for `q` and `qout` with compatible units.
101
102
Mathematically, the result has value `q / expand_units(qout)` and units `dimension(qout)`.
103
+ For string input, `qout` is created by parsing `ustr` as a symbolic unit, i.e. `qout = sym_uparse(ustr)`.
102
104
"""
103
105
function as_u (q:: AbstractQuantity{<:Any, <:Dimensions} , qout:: AbstractQuantity{<:Any, <:SymbolicDimensions} )
104
106
qout_expanded = expand_units (qout)
105
107
dimension (q) == dimension (qout_expanded) || throw (DimensionError (q, qout_expanded))
106
108
return new_quantity (typeof (qout), ustrip (q) / ustrip (qout_expanded), dimension (qout))
107
109
end
110
+ as_u (q:: AbstractQuantity{<:Any, <:Dimensions} , ustr:: String ) = as_u (q, sym_uparse (ustr))
108
111
109
112
"""
110
113
as_u(qout::AbstractQuantity{<:Any, <:SymbolicDimensions})
114
+ as_u(ustr::String)
111
115
112
116
Create a function that converts an input quantity `q` with base SI units to the symbolic units of `qout`, i.e
113
117
a function equivalent to `q -> as_u(q, qout)`.
118
+ For string input, `qout` is created by parsing `ustr` as a symbolic unit, i.e. `qout = sym_uparse(ustr)`.
114
119
"""
115
120
as_u (qout:: AbstractQuantity{<:Any, <:SymbolicDimensions} ) = Base. Fix2 (as_u, qout)
116
-
117
- """
118
- as_u(q::AbstractQuantity{<:Any, <:Dimensions}, qout::String)
119
-
120
- Convert a quantity `q` with base SI units to a set of compatible units specified of `qout`.
121
- Internally, this works by parsing `qout` as a symbolic unit, so this is equivalent to `as_u(q, sym_uparse(qout))`.
122
- """
123
- as_u (q:: AbstractQuantity{<:Any, <:Dimensions} , qout:: String ) = as_u (q, sym_uparse (qout))
121
+ as_u (ustr:: String ) = Base. Fix2 (as_u, ustr)
124
122
125
123
Base. copy (d:: SymbolicDimensions ) = SymbolicDimensions (copy (data (d)))
126
124
Base.:(== )(l:: SymbolicDimensions , r:: SymbolicDimensions ) = data (l) == data (r)
0 commit comments