Skip to content

Commit 64ffd6b

Browse files
committed
Add scalar aliases.
Fixes #37.
1 parent c2aabad commit 64ffd6b

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
# 0.3.3
4+
5+
- Add ASCII aliases for common scalar transforms
6+
37
# 0.3.2
48

59
- Check length of inputs for CorrCholeskyFactor

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TransformVariables"
22
uuid = "84d833dd-6860-57f9-a1a7-6da5db126cff"
33
authors = ["Tamas K. Papp <[email protected]>"]
4-
version = "0.3.2"
4+
version = "0.3.3"
55

66
[deps]
77
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
@@ -12,6 +12,9 @@ MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1212
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
1313
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1414

15+
[compat]
16+
julia = "^1"
17+
1518
[extras]
1619
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
1720
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
@@ -22,6 +25,3 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2225

2326
[targets]
2427
test = ["Flux", "LogDensityProblems", "OffsetArrays", "Random", "ReverseDiff", "Test"]
25-
26-
[compat]
27-
julia = "^1"

src/scalar.jl

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export ∞, asℝ, asℝ₊, asℝ₋, as𝕀
1+
export ∞, asℝ, asℝ₊, asℝ₋, as𝕀, as_real, as_positive_real, as_negative_real,
2+
as_unit_interval
23

34
"""
45
$(TYPEDEF)
@@ -170,14 +171,38 @@ function as(::Type{Real}, left::Real, right::Real)
170171
ScaledShiftedLogistic(right - left, left)
171172
end
172173

173-
"Transform to a non-negative real number."
174+
"""
175+
Transform to a positive real number.
176+
177+
`asℝ₊` and `as_positive_real` are equivalent alternatives.
178+
"""
174179
const asℝ₊ = as(Real, 0.0, ∞)
175180

176-
"Transform to a non-positive real number."
181+
const as_positive_real = asℝ₊
182+
183+
"""
184+
Transform to a negative real number.
185+
186+
`asℝ₋` and `as_negative_real` are equivalent alternatives.
187+
"""
177188
const asℝ₋ = as(Real, -∞, 0.0)
178189

179-
"Transform to the unit interval `(0, 1)`."
190+
const as_negative_real = asℝ₋
191+
192+
"""
193+
Transform to the unit interval `(0, 1)`.
194+
195+
`as𝕀` and `as_unit_interval` are equivalent alternatives.
196+
"""
180197
const as𝕀 = as(Real, 0.0, 1.0)
181198

182-
"Transform to the real line (identity)."
199+
const as_unit_interval = as𝕀
200+
201+
"""
202+
Transform to the real line (identity).
203+
204+
`asℝ` and `as_real` are equivalent alternatives.
205+
"""
183206
const asℝ = as(Real, -∞, ∞)
207+
208+
const as_real = asℝ

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ end
6363
@test_throws DomainError inverse_and_logjac(t, 11.0)
6464
end
6565

66+
@testset "scalar alternatives" begin
67+
@test as_real asℝ
68+
@test as_positive_real asℝ₊
69+
@test as_negative_real asℝ₋
70+
@test as_unit_interval as𝕀
71+
end
72+
6673
@testset "to unit vector" begin
6774
@testset "dimension checks" begin
6875
U = UnitVector(3)

0 commit comments

Comments
 (0)