We can reshape a regular matrix to the third dimension using:
julia> data = rand(4,2)
4×2 Array{Float64,2}:
0.89585 0.328315
0.77878 0.619666
0.232389 0.132091
0.48543 0.829476
julia> reshape(data, 4, 1, 2)
4×1×2 Array{Float64,3}:
[:, :, 1] =
0.895850499952602
0.7787804133322247
0.23238945917674037
0.4854297310447009
[:, :, 2] =
0.3283154491436233
0.6196660556881552
0.13209084702809903
0.8294762758800456
But if using CircularBuffer we get an error:
using DataStructures
julia> data = CircularBuffer{Vector{Float64}}(4)
0-element CircularBuffer{Array{Float64,1}}
julia> push!(data, rand(2))
1-element CircularBuffer{Array{Float64,1}}:
[0.0271144, 0.131345]
julia> push!(data, rand(2))
2-element CircularBuffer{Array{Float64,1}}:
[0.0271144, 0.131345]
[0.0483998, 0.384114]
julia> push!(data, rand(2))
3-element CircularBuffer{Array{Float64,1}}:
[0.0271144, 0.131345]
[0.0483998, 0.384114]
[0.856657, 0.239313]
julia> push!(data, rand(2))
4-element CircularBuffer{Array{Float64,1}}:
[0.0271144, 0.131345]
[0.0483998, 0.384114]
[0.856657, 0.239313]
[0.573953, 0.0423042]
julia> reshape(data, 4, 1, 2)
ERROR: DimensionMismatch("parent has 4 elements, which is incompatible with size (4, 1, 2)")
Stacktrace:
[1] _throw_dmrs(::Int64, ::String, ::Tuple{Int64,Int64,Int64}) at ./reshapedarray.jl:180
[2] _reshape at ./reshapedarray.jl:175 [inlined]
[3] reshape(::CircularBuffer{Array{Float64,1}}, ::Tuple{Int64,Int64,Int64}) at ./reshapedarray.jl:112
[4] reshape(::CircularBuffer{Array{Float64,1}}, ::Int64, ::Int64, ::Vararg{Int64,N} where N) at ./reshapedarray.jl:115
[5] top-level scope at none:0