From dc0e237b347fc9d25197bbae6768760cc57c801e Mon Sep 17 00:00:00 2001 From: Jun Tian Date: Tue, 1 Sep 2020 18:03:16 +0800 Subject: [PATCH] bump version (#79) --- Project.toml | 2 +- src/implementations/spaces/discrete_space.jl | 1 + src/implementations/spaces/vect_space.jl | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 5d93df6..ca384b6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ReinforcementLearningBase" uuid = "e575027e-6cd6-5018-9292-cdc6200d2b44" authors = ["Johanni Brea ", "Jun Tian "] -version = "0.8.1" +version = "0.8.2" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" diff --git a/src/implementations/spaces/discrete_space.jl b/src/implementations/spaces/discrete_space.jl index ebb31d4..a77a167 100644 --- a/src/implementations/spaces/discrete_space.jl +++ b/src/implementations/spaces/discrete_space.jl @@ -62,6 +62,7 @@ Base.convert( ) = DiscreteSpace(s) Base.iterate(s::DiscreteSpace, args...) = iterate(s.span, args...) +Base.getindex(s::DiscreteSpace, args...) = getindex(s.span, args...) ##### # ActionWithProb diff --git a/src/implementations/spaces/vect_space.jl b/src/implementations/spaces/vect_space.jl index e0b54a0..678c0e2 100644 --- a/src/implementations/spaces/vect_space.jl +++ b/src/implementations/spaces/vect_space.jl @@ -8,3 +8,16 @@ Base.eltype(s::VectSpace) = Vector{eltype(s.data[1])} Base.in(xs, s::VectSpace) = length(xs) == length(s.data) && all(x in d for (x, d) in zip(xs, s.data)) Random.rand(rng::AbstractRNG, s::VectSpace) = [rand(rng, d) for d in s.data] + +Base.iterate(s::VectSpace, args...) = iterate(s.data, args...) +Base.getindex(s::VectSpace, i::Int) = getindex(s.data, i) + +""" + getindex(s::VectSpace, I::Vector{Int}) + +Here `I` represents the index of action in each inner space inside `s`. +""" +function Base.getindex(s::VectSpace, I::Vector{Int}) + @assert length(s.data) == length(I) + [getindex(d, i) for (d, i) in zip(s.data, I)] +end