@@ -47,6 +47,25 @@ Base.size(cb::CircularArrayBuffer{T,N}, i::Integer) where {T,N} = i == N ? cb.nf
47
47
Base. size (cb:: CircularArrayBuffer{T,N} ) where {T,N} = ntuple (i -> size (cb, i), N)
48
48
Base. getindex (cb:: CircularArrayBuffer{T,N} , i:: Int ) where {T,N} = getindex (cb. buffer, _buffer_index (cb, i))
49
49
Base. getindex (cb:: CircularArrayBuffer{T,N} , I... ) where {T,N} = getindex (cb. buffer, Base. front (I)... , _buffer_frame (cb, Base. last (I)))
50
+
51
+ # !!!
52
+ # strange, but we need this function to show `CircularVectorBuffer` correctly
53
+ # `Base.print_array` will try to use `isassigned(cb, i, j)` to print elements
54
+ # And, `X::AbstractVector[2, 1]` is valid !!!
55
+ # without this line
56
+ # ```julia
57
+ # julia> cb = CircularArrayBuffer([1., 2.])
58
+ # CircularVectorBuffer(::Vector{Float64}) with eltype Float64:
59
+ # 1.0
60
+ # 2.0
61
+
62
+ # julia> push!(cb, 3)
63
+ # CircularVectorBuffer(::Vector{Float64}) with eltype Float64:
64
+ # #undef
65
+ # #undef
66
+ # ```
67
+ Base. getindex (cb:: CircularVectorBuffer , i, j) = getindex (cb. buffer, _buffer_frame (cb, i), j)
68
+
50
69
Base. setindex! (cb:: CircularArrayBuffer{T,N} , v, i:: Int ) where {T,N} = setindex! (cb. buffer, v, _buffer_index (cb, i))
51
70
Base. setindex! (cb:: CircularArrayBuffer{T,N} , v, I... ) where {T,N} = setindex! (cb. buffer, v, Base. front (I)... , _buffer_frame (cb, Base. last (I)))
52
71
@@ -92,11 +111,7 @@ function Base.push!(cb::CircularArrayBuffer{T,N}, data) where {T,N}
92
111
end
93
112
if N == 1
94
113
i = _buffer_frame (cb, cb. nframes)
95
- if ndims (data) == 0
96
- cb. buffer[i: i] .= data[]
97
- else
98
- cb. buffer[i: i] .= data
99
- end
114
+ cb. buffer[i: i] .= Ref (data)
100
115
else
101
116
cb. buffer[ntuple (_ -> (:), N - 1 )... , _buffer_frame (cb, cb. nframes)] .= data
102
117
end
0 commit comments