Skip to content
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

allow vcat on single ChainedVector #96

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stuartthomas25
Copy link

Formerly, vcat(a::ChainedVector) would fail with an error. This PR adds a method to match the typical Julia behavior that vcat(a)=a.

Formerly, `vcat(a::ChainedVector)` would fail with an error.
Copy link

codecov bot commented Mar 19, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 94.73%. Comparing base (fa840f9) to head (132495d).

Files Patch % Lines
src/chainedvector.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #96      +/-   ##
==========================================
- Coverage   94.82%   94.73%   -0.10%     
==========================================
  Files           5        5              
  Lines        1043     1044       +1     
==========================================
  Hits          989      989              
- Misses         54       55       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JoaoAparicio
Copy link
Contributor

One observation: The typical Julia behavior is that vcat copies its inputs:

x = [1,2,3]
vcat(x) === x  # false

whereas here

x = ChainedVector([[1,2,3],[4,5]])
vcat(x) === x  # true

Comment on lines +632 to 634
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}}
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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants