Skip to content

Commit

Permalink
Version-limit pointer based vcat_copyto
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Dec 7, 2023
1 parent fe038e4 commit 327ddb0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/lazyconcat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,21 @@ function vcat_copyto!(dest::AbstractMatrix, arrays...)
end

function vcat_copyto!(arr::AbstractVector, arrays...)
n = 0
for a in arrays
n += length(a)
end
n = sum(length, arrays)

Check warning on line 258 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L258

Added line #L258 was not covered by tests
n == length(arr) || throw(DimensionMismatch("destination must have length equal to sums of concatenated vectors"))

i = 0
@inbounds for a in arrays
i = firstindex(arr)
for a in arrays

Check warning on line 262 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L261-L262

Added lines #L261 - L262 were not covered by tests
m = length(a)
copyto!(view(arr,i+1:i+m), a)
copyto!(view(arr, range(i, length=m)), a)

Check warning on line 264 in src/lazyconcat.jl

View check run for this annotation

Codecov / codecov/patch

src/lazyconcat.jl#L264

Added line #L264 was not covered by tests
i += m
end
arr
end

# The following provides no performance benefit on Julia v1.10.0-rc2
@static if VERSION < v"1.10-"

function vcat_copyto!(arr::Vector{T}, arrays::Vector{T}...) where T
n = 0
for a in arrays
Expand Down Expand Up @@ -310,6 +310,8 @@ function vcat_copyto!(arr::Vector{T}, arrays::Vector{T}...) where T
return arr
end

end

# special case for adjoints of hcat. This is useful for catching fast paths
# for vector case, e.g., _fast_blockbradcast_copyto! in BlockArrays.jl
function vcat_copyto!(dest::AbstractMatrix, arrays::Adjoint{<:Any,<:AbstractVector}...)
Expand Down

0 comments on commit 327ddb0

Please sign in to comment.