Skip to content

allow vcat on single ChainedVector #96

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 2 additions & 0 deletions src/chainedvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ Base.@propagate_inbounds function Base.insert!(A::ChainedVector{T, AT}, i::Integ
return A
end

Base.vcat(A::ChainedVector{T, AT}) where {T, AT <: AbstractVector{T}} = A

function Base.vcat(A::ChainedVector{T, AT}, arrays::ChainedVector{T, AT}...) where {T, AT <: AbstractVector{T}}
Comment on lines +632 to 634
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest folding this into the same method, either with a fast path like

Suggested change
Base.vcat(A::ChainedVector{T, AT}) where {T, AT <: AbstractVector{T}} = A
function Base.vcat(A::ChainedVector{T, AT}, arrays::ChainedVector{T, AT}...) where {T, AT <: AbstractVector{T}}
function Base.vcat(A::ChainedVector{T, AT}, arrays::ChainedVector{T, AT}...) where {T, AT <: AbstractVector{T}}
isempty(arrays) && return Base.unaliascopy(A)

or by fixing the source of the error directly by passing init=0 to sum a few lines down. (The latter would require bumping the minimum Julia compat to at least 1.6, but IMO that's fine.)

newarrays = vcat(A.arrays, map(x->x.arrays, arrays)...)
n = length(A.inds)
Expand Down