Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Concretize IndexLens using to_indices #43

Closed
wants to merge 27 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0a03b30
Use `Base.to_indices` to concretize index lenses.
phipsgabler Nov 20, 2021
9e696e1
Fix doctest
phipsgabler Nov 20, 2021
3897231
Normalize all recovered range types (better printing and equivalence)
phipsgabler Nov 28, 2021
36ce5a3
Trade-off between to_indices and strange range types; add explicit
phipsgabler Dec 13, 2021
e854b17
Remove Slice wrappers
phipsgabler Dec 13, 2021
87f85d2
Merge branch 'main' into phg/concretization
phipsgabler Feb 5, 2022
65346a9
Add doc(test) for surprising range normalization
phipsgabler Feb 5, 2022
82c914c
Add proper VarName tests; some refactoring
phipsgabler Feb 5, 2022
7c6719d
Require newer Setfield version (fixed equality)
phipsgabler Feb 5, 2022
63a8191
Actually add test file...
phipsgabler Feb 5, 2022
34c3868
Shorter reconcretization
phipsgabler Feb 5, 2022
ab5c803
Fix remaining bugs?
phipsgabler Feb 5, 2022
477254d
Refactor subsumption; concretize into ConcretizedSlice; implement sug…
phipsgabler Feb 7, 2022
5ef7e1a
Rename confusing leftover (subsumes_index -> subsumes_indices)
phipsgabler Feb 7, 2022
48d00c2
Apply review suggestions
phipsgabler Feb 9, 2022
44effc1
Merge branch 'main' into phg/concretization
yebai Feb 9, 2022
98eed65
Change pretty printing indices to repr (fixes #50)
phipsgabler Feb 12, 2022
7024bf9
Merge remote-tracking branch 'origin/phg/concretization' into phg/con…
phipsgabler Feb 12, 2022
2888395
Update CI.yml
yebai Feb 13, 2022
358583b
Update bors.toml
yebai Feb 13, 2022
d83148d
Update Project.toml
yebai Feb 13, 2022
412e1bf
Update Project.toml
yebai Feb 13, 2022
33b9ada
Merge branch 'main' into phg/concretization
phipsgabler May 5, 2022
44a2615
Fix some docstrings
phipsgabler Oct 5, 2022
686f5ad
Merge branch 'main' into phg/concretization
phipsgabler Oct 5, 2022
e8683ce
Fix merge mess
phipsgabler Oct 5, 2022
af291d3
Bump version
phipsgabler Oct 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/varname.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,28 +418,34 @@ _issubrange(i::ConcreteIndex, j::Colon) = true
# we preserve the status quo, but I'm confused.
_issubrange(i::Colon, j::ConcreteIndex) = true

"""Turn any `AbstractRange` into an equivalent `UnitRange` or `StepRange`."""
_normalizerange(r::AbstractRange) = (:)(r...)
phipsgabler marked this conversation as resolved.
Show resolved Hide resolved
_normalizerange(x) = x

"""
concretize(l::Lens, x)

Return `l` instantiated on `x`, i.e. any runtime information evaluated using `x`.
"""
concretize(I::Lens, x) = I
concretize(I::DynamicIndexLens, x) = IndexLens(I.f(x))
concretize(I::IndexLens, x) = IndexLens(_normalizerange.(Base.to_indices(x, I.indices)))
concretize(I::DynamicIndexLens, x) = IndexLens(_normalizerange.(I.f(x)))
phipsgabler marked this conversation as resolved.
Show resolved Hide resolved
function concretize(I::ComposedLens, x)
x_inner = get(x, I.outer)
return ComposedLens(concretize(I.outer, x), concretize(I.inner, x_inner))
end

"""
concretize(vn::VarName, x)

Return `vn` instantiated on `x`, i.e. any runtime information evaluated using `x`.

# Examples
```jldoctest; setup=:(using Setfield)
julia> x = (a = [1.0 2.0;], );
julia> x = (a = [1.0 2.0; 3.0 4.0], );

julia> AbstractPPL.concretize(@varname(x.a[1, end][:]), x)
x.a[1,2][:]
julia> AbstractPPL.concretize(@varname(x.a[1:end, end][:]), x)
x.a[1:2,2][1:2]
```
"""
concretize(vn::VarName, x) = VarName(vn, concretize(getlens(vn), x))
Expand Down