Skip to content

Commit 0d31764

Browse files
authored
Merge pull request #17 from TuringLang/dw/varname
2 parents b7a2e48 + b315b92 commit 0d31764

File tree

6 files changed

+33
-27
lines changed

6 files changed

+33
-27
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
33
keywords = ["probablistic programming"]
44
license = "MIT"
55
desc = "Common interfaces for probabilistic programming"
6-
version = "0.1.2"
6+
version = "0.1.3"
77

88
[deps]
99
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"

src/AbstractPPL.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
module AbstractPPL
22

3-
4-
include("varname.jl")
5-
include("abstractprobprog.jl")
6-
include("abstractmodeltrace.jl")
7-
8-
93
# VarName
104
export VarName,
115
getsym,
@@ -27,5 +21,9 @@ export AbstractProbabilisticProgram
2721
# Abstract traces
2822
export AbstractModelTrace
2923

24+
include("varname.jl")
25+
include("abstractprobprog.jl")
26+
include("abstractmodeltrace.jl")
27+
include("deprecations.jl")
3028

3129
end # module

src/deprecations.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@deprecate VarName(sym::Symbol) VarName{sym}()
2+
@deprecate VarName(sym::Symbol, indexing::Tuple) VarName{sym}(indexing)

src/varname.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
VarName(sym[, indexing=()])
2+
VarName{sym}(indexing::Tuple=())
33
44
A variable identifier for a symbol `sym` and indices `indexing` in the format
55
returned by [`@vinds`](@ref).
@@ -10,30 +10,30 @@ stores the indices requires to access the random variable from the Julia variabl
1010
as a tuple of tuples. Each element of the tuple thereby contains the indices of one indexing
1111
operation.
1212
13-
`VarName`s can be manually constructed using the `VarName(sym, indexing)` constructor, or from an
13+
`VarName`s can be manually constructed using the `VarName{sym}(indexing)` constructor, or from an
1414
indexing expression through the [`@varname`](@ref) convenience macro.
1515
1616
# Examples
1717
1818
```jldoctest
19-
julia> vn = VarName(:x, ((Colon(), 1), (2,)))
19+
julia> vn = VarName{:x}(((Colon(), 1), (2,)))
2020
x[Colon(),1][2]
2121
2222
julia> vn.indexing
2323
((Colon(), 1), (2,))
2424
25-
julia> VarName(AbstractPPL.@vsym(x[:, 1][1+1]), AbstractPPL.@vinds(x[:, 1][1+1]))
25+
julia> @varname x[:, 1][1+1]
2626
x[Colon(),1][2]
2727
```
2828
"""
2929
struct VarName{sym, T<:Tuple}
3030
indexing::T
31-
end
3231

33-
VarName(sym::Symbol, indexing::Tuple = ()) = VarName{sym, typeof(indexing)}(indexing)
32+
VarName{sym}(indexing::Tuple=()) where {sym} = new{sym,typeof(indexing)}(indexing)
33+
end
3434

3535
"""
36-
VarName(vn::VarName[, indexing=()])
36+
VarName(vn::VarName, indexing=())
3737
3838
Return a copy of `vn` with a new index `indexing`.
3939
@@ -46,7 +46,7 @@ x
4646
```
4747
"""
4848
function VarName(vn::VarName, indexing::Tuple = ())
49-
return VarName{getsym(vn), typeof(indexing)}(indexing)
49+
return VarName{getsym(vn)}(indexing)
5050
end
5151

5252

@@ -249,11 +249,11 @@ macro varname(expr::Union{Expr, Symbol})
249249
return esc(varname(expr))
250250
end
251251

252-
varname(expr::Symbol) = VarName(expr)
252+
varname(sym::Symbol) = :($(AbstractPPL.VarName){$(QuoteNode(sym))}())
253253
function varname(expr::Expr)
254254
if Meta.isexpr(expr, :ref)
255255
sym, inds = vsym(expr), vinds(expr)
256-
return :($(AbstractPPL.VarName)($(QuoteNode(sym)), $inds))
256+
return :($(AbstractPPL.VarName){$(QuoteNode(sym))}($inds))
257257
else
258258
throw("Malformed variable name $(expr)!")
259259
end
@@ -269,13 +269,13 @@ For example, `@vsym x[1]` returns `:x`.
269269
## Examples
270270
271271
```jldoctest
272-
julia> AbstractPPL.@vsym x
272+
julia> @vsym x
273273
:x
274274
275-
julia> AbstractPPL.@vsym x[1,1][2,3]
275+
julia> @vsym x[1,1][2,3]
276276
:x
277277
278-
julia> AbstractPPL.@vsym x[end]
278+
julia> @vsym x[end]
279279
:x
280280
```
281281
"""
@@ -307,19 +307,19 @@ Returns a tuple of tuples of the indices in `expr`.
307307
## Examples
308308
309309
```jldoctest
310-
julia> AbstractPPL.@vinds x
310+
julia> @vinds x
311311
()
312312
313-
julia> AbstractPPL.@vinds x[1,1][2,3]
313+
julia> @vinds x[1,1][2,3]
314314
((1, 1), (2, 3))
315315
316-
julia> AbstractPPL.@vinds x[:,1][2,:]
316+
julia> @vinds x[:,1][2,:]
317317
((Colon(), 1), (2, Colon()))
318318
319-
julia> AbstractPPL.@vinds x[2:3,1][2,1:2]
319+
julia> @vinds x[2:3,1][2,1:2]
320320
((2:3, 1), (2, 1:2))
321321
322-
julia> AbstractPPL.@vinds x[2:3,2:3][[1,2],[1,2]]
322+
julia> @vinds x[2:3,2:3][[1,2],[1,2]]
323323
((2:3, 2:3), ([1, 2], [1, 2]))
324324
```
325325
@@ -341,10 +341,10 @@ suitable for input of the [`VarName`](@ref) constructor.
341341
## Examples
342342
343343
```jldoctest
344-
julia> AbstractPPL.vinds(:(x[end]))
344+
julia> vinds(:(x[end]))
345345
:((((lastindex)(x),),))
346346
347-
julia> AbstractPPL.vinds(:(x[1, end]))
347+
julia> vinds(:(x[1, end]))
348348
:(((1, (lastindex)(x, 2)),))
349349
```
350350
"""

test/deprecations.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@testset "deprecations.jl" begin
2+
@test (@test_deprecated VarName(:x)) == VarName{:x}()
3+
@test (@test_deprecated VarName(:x, ((1,), (:, 2)))) == VarName{:x}(((1,), (:, 2)))
4+
end

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ using Documenter
1111
using Test
1212

1313
@testset "AbstractPPL.jl" begin
14+
include("deprecations.jl")
15+
1416
@testset "doctests" begin
1517
DocMeta.setdocmeta!(
1618
AbstractPPL,

0 commit comments

Comments
 (0)