|
98 | 98 |
|
99 | 99 | Expand the symbolic units in a quantity to their base SI form.
|
100 | 100 | In other words, this converts a `Quantity` with `SymbolicDimensions`
|
101 |
| -to one with `Dimensions`. |
| 101 | +to one with `Dimensions`. The opposite of this function is `uconvert`, |
| 102 | +for converting to specific symbolic units, or `convert(Quantity{<:Any,<:SymbolicDimensions}, q)`, |
| 103 | +for assuming SI units as the output symbols. |
102 | 104 | """
|
103 | 105 | function expand_units(q::Q) where {T,R,D<:SymbolicDimensions{R},Q<:AbstractQuantity{T,D}}
|
104 | 106 | return convert(constructor_of(Q){T,Dimensions{R}}, q)
|
105 | 107 | end
|
106 | 108 | expand_units(q::QuantityArray) = expand_units.(q)
|
107 | 109 |
|
108 | 110 | """
|
109 |
| - as_u(q::AbstractQuantity{<:Any, <:Dimensions}, qout::AbstractQuantity{<:Any, <:SymbolicDimensions}) |
110 |
| - as_u(q::AbstractQuantity{<:Any, <:Dimensions}, ustr::String) |
| 111 | + uconvert(qout::AbstractQuantity{<:Any, <:SymbolicDimensions}, q::AbstractQuantity{<:Any, <:Dimensions}) |
| 112 | + uconvert(ustr::String, q::AbstractQuantity{<:Any, <:Dimensions}) |
111 | 113 |
|
112 | 114 | Convert a quantity `q` with base SI units to the symbolic units of `qout`, for `q` and `qout` with compatible units.
|
113 | 115 | Mathematically, the result has value `q / expand_units(qout)` and units `dimension(qout)`.
|
114 | 116 | For string input, `qout` is created by parsing `ustr` as a symbolic unit, i.e. `qout = sym_uparse(ustr)`.
|
115 | 117 | """
|
116 |
| -function as_u(q::AbstractQuantity{<:Any, <:Dimensions}, qout::AbstractQuantity{<:Any, <:SymbolicDimensions}) |
| 118 | +function uconvert(qout::AbstractQuantity{<:Any, <:SymbolicDimensions}, q::AbstractQuantity{<:Any, <:Dimensions}) |
117 | 119 | qout_expanded = expand_units(qout)
|
118 | 120 | dimension(q) == dimension(qout_expanded) || throw(DimensionError(q, qout_expanded))
|
119 | 121 | return new_quantity(typeof(qout), ustrip(q) / ustrip(qout_expanded), dimension(qout))
|
120 | 122 | end
|
121 |
| -as_u(q::AbstractQuantity{<:Any, <:Dimensions}, ustr::String) = as_u(q, sym_uparse(ustr)) |
| 123 | +uconvert(ustr::String, q::AbstractQuantity{<:Any, <:Dimensions}) = uconvert(sym_uparse(ustr), q) |
122 | 124 |
|
123 | 125 | """
|
124 |
| - as_u(qout::AbstractQuantity{<:Any, <:SymbolicDimensions}) |
125 |
| - as_u(ustr::String) |
| 126 | + uconvert(qout::AbstractQuantity{<:Any, <:SymbolicDimensions}) |
| 127 | + uconvert(ustr::String) |
126 | 128 |
|
127 | 129 | Create a function that converts an input quantity `q` with base SI units to the symbolic units of `qout`, i.e
|
128 |
| -a function equivalent to `q -> as_u(q, qout)`. |
| 130 | +a function equivalent to `q -> uconvert(qout, q)`. |
129 | 131 | For string input, `qout` is created by parsing `ustr` as a symbolic unit, i.e. `qout = sym_uparse(ustr)`.
|
130 | 132 | """
|
131 |
| -as_u(qout::AbstractQuantity{<:Any, <:SymbolicDimensions}) = Base.Fix2(as_u, qout) |
132 |
| -as_u(ustr::String) = Base.Fix2(as_u, ustr) |
| 133 | +uconvert(qout::AbstractQuantity{<:Any, <:SymbolicDimensions}) = Base.Fix1(uconvert, qout) |
| 134 | +uconvert(ustr::String) = uconvert(sym_uparse(ustr)) |
133 | 135 |
|
134 | 136 | Base.copy(d::SymbolicDimensions) = SymbolicDimensions(copy(getfield(d, :nzdims)), copy(getfield(d, :nzvals)))
|
135 | 137 | function Base.:(==)(l::SymbolicDimensions, r::SymbolicDimensions)
|
|
0 commit comments