From 8ff79f52fea39d957cef0b3934bdca4a020b3f80 Mon Sep 17 00:00:00 2001 From: ErikQQY <2283984853@qq.com> Date: Thu, 12 Sep 2024 01:14:10 +0800 Subject: [PATCH] Avoid undef error Signed-off-by: ErikQQY <2283984853@qq.com> --- src/vector_of_array.jl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index b77d30bb..68c4fe2f 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -736,7 +736,21 @@ end end @inline function Base.similar(VA::VectorOfArray, dims::N) where {N} - VectorOfArray(similar(VA.u, dims)) + l = length(VA) + if dims <= l + VectorOfArray([similar(VA[:, i]) for i in 1:l]) + else + VectorOfArray([[similar(VA[:, i]) for i in 1:l]; [similar(VA.u[end]) for _ in (l+1):dims]]) + end +end + +@inline function Base.similar(VA::VectorOfArray, ::Type{T}, dims::N) where {N, T} + l = length(VA) + if dims <= l + VectorOfArray([similar(VA[:, i], T) for i in 1:l]) + else + VectorOfArray([[similar(VA[:, i], T) for i in 1:l]; [similar(VA.u[end], T) for _ in (l+1):dims]]) + end end @inline function Base.similar(VA::VectorOfArray{T, N, AT},