Skip to content

Commit

Permalink
Concretize IndexLens using to_indices (#43)
Browse files Browse the repository at this point in the history
Should implement #35.  The "problem" with this is that the resulting values are not exactly what you'd write by hand:

```julia
julia> AbstractPPL.concretize(@varname(x.a[1:end, end][:]), x)
x.a[1:2,2][Base.Slice(Base.OneTo(2))]
```

That wouldn't be so much of a problem besides printing, but unfortunately, lenses currenctly compare equality using strict types:

```julia
julia> AbstractPPL.concretize(@varname(x[1:3, :]), rand(10, 10)).lens.indices == @varname(x[1:3, 1:10]).lens.indices
true

julia> AbstractPPL.concretize(@varname(x[1:3, :]), rand(10, 10)).lens == @varname(x[1:3, 1:10]).lens
false

julia> AbstractPPL.concretize(@varname(x[1:3, :]), rand(10, 10)) == @varname(x[1:3, 1:10])
false
```

Cf. jw3126/Setfield.jl#165; the equality comparison can hopefully be fixed there.

The remaining thing is that subsumption must still be able to work with `Colon`, since a user might index a trace/VarInfo using a non-concretized varname containing a colon.  But at least we can then be sure that one side is always concrete.

Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
  • Loading branch information
3 people committed Nov 6, 2022
1 parent 1fbd526 commit 392bbc0
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
keywords = ["probablistic programming"]
license = "MIT"
desc = "Common interfaces for probabilistic programming"
version = "0.5.3"
version = "0.6"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand All @@ -15,5 +15,5 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
[compat]
AbstractMCMC = "2, 3, 4"
DensityInterface = "0.4"
Setfield = "0.7.1, 0.8"
Setfield = "0.8.1"
julia = "~1.6.6, 1.7.3"
2 changes: 1 addition & 1 deletion bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ required_approvals = 1
use_squash_merge = true
# Uncomment this to use a two hour timeout.
# The default is one hour.
timeout_sec = 7200
timeout_sec = 7200
11 changes: 10 additions & 1 deletion src/AbstractPPL.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
module AbstractPPL

# VarName
export VarName, getsym, getlens, inspace, subsumes, varname, vsym, @varname, @vsym
export VarName,
getsym,
getlens,
inspace,
subsumes,
subsumedby,
varname,
vsym,
@varname,
@vsym


# Abstract model functions
Expand Down
Loading

0 comments on commit 392bbc0

Please sign in to comment.