forked from JuliaStats/Distributions.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunits.jl
28 lines (22 loc) · 1.07 KB
/
units.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Variates and distribution parameters with physical dimensions.
using Unitful: Unitful, Quantity, Units, NoDims, NoUnits, unit, ustrip
"""
Type of the variate of a distribution that supports both pure `Real`s and real Unitful
Quantities. If a parameter of the distribution is dimensioned, it is also a `RealQuantity`.
```julia
const RealQuantity = Union{Real, Unitful.Quantity{<:Real}}
```
_i.e._ a `RealQuantity` is either a pure `Real`, or a Unitful `Quantity` with a `Real` as
numeric backing type.
"""
const RealQuantity = Union{Real, Unitful.Quantity{<:Real}}
"""
unit(d::Distribution)
Retrieve the physical units of the distribution's variate, as a
[`Unitful.Units`](https://painterqubits.github.io/Unitful.jl/stable/types/).
- If the distribution does not have units attached (*i.e.* it is over real values), this
returns `NoUnits`, which is a 0-size singleton that gets pruned away in mathematical
expressions at compile-time.
- If the distribution does have units attached, this is `unit(eltype(d))`.
"""
Unitful.unit(::D) where {D <: Distribution} = unit(eltype(D))