Skip to content

Support zero dimension data insert #5

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
merged 1 commit into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CircularArrayBuffers"
uuid = "9de3a189-e0c0-4e15-ba3b-b14b9fb0aec1"
authors = ["Jun Tian <[email protected]> and contributors"]
version = "0.1.3"
version = "0.1.4"

[compat]
julia = "1"
Expand Down
6 changes: 5 additions & 1 deletion src/CircularArrayBuffers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ function Base.push!(cb::CircularArrayBuffer{T, N}, data) where {T,N}
cb.nframes += 1
end
if N == 1
cb[cb.nframes] = data
if ndims(data) == 0
cb[cb.nframes] = data[]
else
cb[cb.nframes] = data
end
else
cb[ntuple(_ -> (:), N - 1)..., cb.nframes] .= data
end
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ using Test
@testset "CircularArrayBuffers.jl" begin
A = ones(2, 2)
C = ones(Float32, 2, 2)

# https://github.com/JuliaReinforcementLearning/ReinforcementLearning.jl/issues/551
@testset "1D with 0d data" begin
b = CircularArrayBuffer{Int}(3)
push!(b, zeros(Int, ()))
@test length(b) == 1
@test b[1] == 0
end

@testset "1D Int" begin
b = CircularArrayBuffer{Int}(3)

Expand Down