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
Base.:*(l::AbstractDimensions, r) =error("Please use an `AbstractQuantity` for multiplication. You used multiplication on types: $(typeof(l)) and $(typeof(r)).")
8
+
Base.:*(l, r::AbstractDimensions) =error("Please use an `AbstractQuantity` for multiplication. You used multiplication on types: $(typeof(l)) and $(typeof(r)).")
@@ -27,10 +27,10 @@ which is by default a rational number.
27
27
28
28
# Constructors
29
29
30
-
- `Dimensions(args...)`: Pass all the dimensions as arguments. `R` is set to `DEFAULT_DIM_TYPE`.
31
-
- `Dimensions(; kws...)`: Pass a subset of dimensions as keyword arguments. `R` is set to `DEFAULT_DIM_TYPE`.
30
+
- `Dimensions(args...)`: Pass all the dimensions as arguments. `R` is set to `DEFAULT_DIM_BASE_TYPE`.
31
+
- `Dimensions(; kws...)`: Pass a subset of dimensions as keyword arguments. `R` is set to `DEFAULT_DIM_BASE_TYPE`.
32
32
- `Dimensions(::Type{R}; kws...)` or `Dimensions{R}(; kws...)`: Pass a subset of dimensions as keyword arguments, with the output type set to `Dimensions{R}`.
33
-
- `Dimensions{R}(args...)`: Pass all the dimensions as arguments, with the output type set to `Dimensions{R}`.
33
+
- `Dimensions{R}()`: Create a dimensionless object typed as `Dimensions{R}`.
34
34
- `Dimensions{R}(d::Dimensions)`: Copy the dimensions from another `Dimensions` object, with the output type set to `Dimensions{R}`.
(::Type{D})(::Type{R}; kws...) where {R,D<:AbstractDimensions} =D{R}((tryrationalize(R, get(kws, k, zero(R))) for k instatic_fieldnames(D))...)
47
-
(::Type{D})(; kws...) where {D<:AbstractDimensions} =D(DEFAULT_DIM_TYPE; kws...)
48
-
49
-
(::Type{D})(args...) where {R,D<:AbstractDimensions{R}} =dimension_constructor(D)(Base.Fix1(convert, R).(args)...)
50
-
(::Type{D})(; kws...) where {R,D<:AbstractDimensions{R}} =dimension_constructor(D)(R; kws...)
46
+
(::Type{D})(::Type{R}; kws...) where {R,D<:AbstractDimensions} =constructor_of(D){R}((tryrationalize(R, get(kws, k, zero(R))) for k instatic_fieldnames(D))...)
47
+
(::Type{D})(; kws...) where {R,D<:AbstractDimensions{R}} =constructor_of(D)(R; kws...)
48
+
(::Type{D})(; kws...) where {D<:AbstractDimensions} =D(DEFAULT_DIM_BASE_TYPE; kws...)
51
49
(::Type{D})(d::AbstractDimensions) where {R,D<:AbstractDimensions{R}} =D((getproperty(d, k) for k instatic_fieldnames(D))...)
Physical quantity with value `value` of type `T` and dimensions `dimensions` of type `Dimensions{R}`.
56
+
Physical quantity with value `value` of type `T` and dimensions `dimensions` of type `D`.
58
57
For example, the velocity of an object with mass 1 kg and velocity
59
58
2 m/s is `Quantity(2, mass=1, length=1, time=-1)`.
60
59
You should access these fields with `ustrip(q)`, and `dimensions(q)`.
@@ -68,77 +67,37 @@ dimensions according to the operation.
68
67
# Fields
69
68
70
69
- `value::T`: value of the quantity of some type `T`. Access with `ustrip(::Quantity)`
71
-
- `dimensions::Dimensions{R}`: dimensions of the quantity with dimension type `R`. Access with `dimension(::Quantity)`
70
+
- `dimensions::D`: dimensions of the quantity. Access with `dimension(::Quantity)`
72
71
73
72
# Constructors
74
73
75
-
- `Quantity(x; kws...)`: Construct a quantity with value `x` and dimensions given by the keyword arguments. The value type is inferred from `x`. `R` is set to `DEFAULT_DIM_TYPE`.
76
-
- `Quantity(x, ::Type{R}; kws...)`: Construct a quantity with value `x`. The dimensions parametric type is set to `R`.
77
-
- `Quantity(x, d::Dimensions{R})`: Construct a quantity with value `x` and dimensions `d`.
78
-
- `Quantity{T}(q::Quantity)`: Construct a quantity with value `q.value` and dimensions `q.dimensions`, but with value type converted to `T`.
79
-
- `Quantity{T,R}(q::Quantity)`: Construct a quantity with value `q.value` and dimensions `q.dimensions`, but with value type converted to `T` and dimensions parametric type set to `R`.
74
+
- `Quantity(x; kws...)`: Construct a quantity with value `x` and dimensions given by the keyword arguments. The value
75
+
type is inferred from `x`. `R` is set to `DEFAULT_DIM_TYPE`.
76
+
- `Quantity(x, ::Type{D}; kws...)`: Construct a quantity with value `x` with dimensions given by the keyword arguments,
77
+
and the dimensions type set to `D`.
78
+
- `Quantity(x, d::D)`: Construct a quantity with value `x` and dimensions `d` of type `D`.
79
+
- `Quantity{T}(...)`: As above, but converting the value to type `T`. You may also pass a `Quantity` as input.
80
+
- `Quantity{T,D}(...)`: As above, but converting the value to type `T` and dimensions to `D`. You may also pass a
for T in [DEFAULT_VALUE_TYPE, Float16, Float32, Float64], R in [DEFAULT_DIM_TYPE, Rational{Int16}, Rational{Int32}, SimpleRatio{Int}, SimpleRatio{SafeInt16}]
15
-
x = DynamicQuantities.Quantity(T(0.2), R, length=1, amount=2, current=-1//2, luminosity=2//5)
14
+
for T in [DEFAULT_VALUE_TYPE, Float16, Float32, Float64], R in [DEFAULT_DIM_BASE_TYPE, Rational{Int16}, Rational{Int32}, SimpleRatio{Int}, SimpleRatio{SafeInt16}]
15
+
D = DynamicQuantities.Dimensions{R}
16
+
x = DynamicQuantities.Quantity(T(0.2), D, length=1, amount=2, current=-1//2, luminosity=2//5)
0 commit comments