You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
throw(ArgumentError("Conversion of a `DynamicQuantities.Quantity` to a `Unitful.Quantity` is not defined with dimensions of type `SymbolicDimensions`. Instead, you can first use the `uexpand` function to convert the dimensions to their base SI form of type `Dimensions`, then convert this quantity to a `Unitful.Quantity`."))
27
+
for (_, _, Q) in ABSTRACT_QUANTITY_TYPES
28
+
@evalbegin
29
+
function Base.convert(::Type{Unitful.Quantity}, x::$Q)
30
+
validate_upreferred()
31
+
cumulator = DynamicQuantities.ustrip(x)
32
+
dims = DynamicQuantities.dimension(x)
33
+
if dims isa DynamicQuantities.SymbolicDimensions
34
+
throw(ArgumentError("Conversion of a `DynamicQuantities."*string($Q) *"` to a `Unitful.Quantity` is not defined with dimensions of type `SymbolicDimensions`. Instead, you can first use the `uexpand` function to convert the dimensions to their base SI form of type `Dimensions`, then convert this quantity to a `Unitful.Quantity`."))
35
+
end
36
+
equiv =unitful_equivalences()
37
+
for dim inkeys(dims)
38
+
value = dims[dim]
39
+
iszero(value) &&continue
40
+
cumulator *= equiv[dim]^value
41
+
end
42
+
cumulator
33
43
end
34
-
equiv =unitful_equivalences()
35
-
for dim inkeys(dims)
36
-
value = dims[dim]
37
-
iszero(value) &&continue
38
-
cumulator *= equiv[dim]^value
44
+
function Base.convert(::Type{$Q}, x::Unitful.Quantity{T}) where {T}
for T in [DEFAULT_VALUE_TYPE, Float16, Float32, Float64], R in [DEFAULT_DIM_BASE_TYPE, Rational{Int16}, Rational{Int32}, SimpleRatio{Int}, SimpleRatio{SafeInt16}]
Copy file name to clipboardExpand all lines: test/unittests.jl
+36-35Lines changed: 36 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
using DynamicQuantities
2
2
using DynamicQuantities: FixedRational
3
-
using DynamicQuantities: DEFAULT_DIM_BASE_TYPE, DEFAULT_DIM_TYPE, DEFAULT_VALUE_TYPE
3
+
using DynamicQuantities:DEFAULT_QUANTITY_TYPE, DEFAULT_DIM_BASE_TYPE, DEFAULT_DIM_TYPE, DEFAULT_VALUE_TYPE
4
4
using DynamicQuantities: array_type, value_type, dim_type, quantity_type
5
-
using DynamicQuantities: GenericQuantity
5
+
using DynamicQuantities: GenericQuantity, with_type_parameters, constructorof
6
6
using Ratios: SimpleRatio
7
7
using SaferIntegers: SafeInt16
8
8
using StaticArrays: SArray, MArray
@@ -20,7 +20,7 @@ end
20
20
21
21
@testset"Basic utilities"begin
22
22
23
-
for Q in [Quantity, GenericQuantity], T in [DEFAULT_VALUE_TYPE, Float16, Float32, Float64], R in [DEFAULT_DIM_BASE_TYPE, Rational{Int16}, Rational{Int32}, SimpleRatio{Int}, SimpleRatio{SafeInt16}]
23
+
for Q in [Quantity, GenericQuantity, RealQuantity], T in [DEFAULT_VALUE_TYPE, Float16, Float32, Float64], R in [DEFAULT_DIM_BASE_TYPE, Rational{Int16}, Rational{Int32}, SimpleRatio{Int}, SimpleRatio{SafeInt16}]
0 commit comments