Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
torfjelde and github-actions[bot] authored Nov 7, 2023
1 parent 8ce53f7 commit fc6a051
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,6 @@ istrans(vi::VarInfo, vn::VarName) = istrans(getmetadata(vi, vn), vn)
istrans(md::Metadata, vn::VarName) = is_flagged(md, vn, "trans")
istrans(vnv::VarNameVector, vn::VarName) = !(gettransform(vnv, vn) isa FromVec)

Check warning on line 909 in src/varinfo.jl

View check run for this annotation

Codecov / codecov/patch

src/varinfo.jl#L909

Added line #L909 was not covered by tests


getlogp(vi::VarInfo) = vi.logp[]

function setlogp!!(vi::VarInfo, logp)
Expand Down
10 changes: 4 additions & 6 deletions src/varnamevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct VarNameVector{
TIdcs<:OrderedDict{<:VarName,Int},
TVN<:AbstractVector{<:VarName},
TVal<:AbstractVector,
TTrans<:AbstractVector
TTrans<:AbstractVector,
}
"mapping from the `VarName` to its integer index in `vns`, `ranges` and `dists`"
idcs::TIdcs # Dict{<:VarName,Int}
Expand Down Expand Up @@ -44,9 +44,7 @@ Bijectors.inverse(f::FromVec{Tuple{}}) = tovec
VarNameVector(x::AbstractDict) = VarNameVector(keys(x), values(x))
VarNameVector(vns, vals) = VarNameVector(collect(vns), collect(vals))
function VarNameVector(

Check warning on line 46 in src/varnamevector.jl

View check run for this annotation

Codecov / codecov/patch

src/varnamevector.jl#L44-L46

Added lines #L44 - L46 were not covered by tests
vns::AbstractVector,
vals::AbstractVector,
transforms = map(FromVec, vals)
vns::AbstractVector, vals::AbstractVector, transforms=map(FromVec, vals)
)
# TODO: Check uniqueness of `vns`?

Expand Down Expand Up @@ -107,7 +105,7 @@ Base.getindex(vnv::VarNameVector, spl::AbstractSampler) = vnv[:]
Base.setindex!(vnv::VarNameVector, val, i::Int) = vnv.vals[i] = val
function Base.setindex!(vnv::VarNameVector, val, vn::VarName)
f = inverse(gettransform(vnv, vn))
vnv.vals[getrange(vnv, vn)] = f(val)
return vnv.vals[getrange(vnv, vn)] = f(val)

Check warning on line 108 in src/varnamevector.jl

View check run for this annotation

Codecov / codecov/patch

src/varnamevector.jl#L105-L108

Added lines #L105 - L108 were not covered by tests
end

function Base.empty!(vnv::VarNameVector)

Check warning on line 111 in src/varnamevector.jl

View check run for this annotation

Codecov / codecov/patch

src/varnamevector.jl#L111

Added line #L111 was not covered by tests
Expand Down Expand Up @@ -146,7 +144,7 @@ function group_by_symbol(vnv::VarNameVector)
VarNameVector(

Check warning on line 144 in src/varnamevector.jl

View check run for this annotation

Codecov / codecov/patch

src/varnamevector.jl#L144

Added line #L144 was not covered by tests
map(identity, vns),
map(Base.Fix1(getindex, vnv), vns),
map(Base.Fix1(gettransform, vnv), vns)
map(Base.Fix1(gettransform, vnv), vns),
)
end

Expand Down
12 changes: 2 additions & 10 deletions test/varnamevector.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
@testset "VarNameVector" begin
vns = [
@varname(x[1]),
@varname(x[2]),
@varname(x[3]),
]
vals = [
1,
2:3,
reshape(4:9, 2, 3),
]
vns = [@varname(x[1]), @varname(x[2]), @varname(x[3])]
vals = [1, 2:3, reshape(4:9, 2, 3)]
vnv = VarNameVector(vns, vals)

# `getindex`
Expand Down

0 comments on commit fc6a051

Please sign in to comment.