Skip to content

Commit 492fa27

Browse files
committed
scalar padded copyto!
1 parent 27f7e5c commit 492fa27

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LazyArrays"
22
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
3-
version = "0.12"
3+
version = "0.12.1"
44

55
[deps]
66
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"

src/lazyconcat.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,14 @@ function ==(A::CachedVector{<:Any,<:Any,<:Zeros}, B::CachedVector{<:Any,<:Any,<:
486486
end
487487

488488
# special copyto! since `similar` of a padded returns a cached
489-
function copyto!(dest::CachedVector{T,Vector{T},<:Zeros{T,1}}, src::Vcat{<:Any,1,<:Tuple{<:AbstractVector,<:Zeros}}) where T
490-
length(src) length(dest) || throw(BoundsError())
491-
a,_ = src.args
492-
resizedata!(dest, length(a)) # make sure we are padded enough
493-
copyto!(dest.data, a)
494-
dest
489+
for Typ in (:Number, :AbstractVector)
490+
@eval function copyto!(dest::CachedVector{T,Vector{T},<:Zeros{T,1}}, src::Vcat{<:Any,1,<:Tuple{<:$Typ,<:Zeros}}) where T
491+
length(src) length(dest) || throw(BoundsError())
492+
a,_ = src.args
493+
resizedata!(dest, length(a)) # make sure we are padded enough
494+
copyto!(dest.data, a)
495+
dest
496+
end
495497
end
496498

497499
struct Dot{StyleA,StyleB,ATyp,BTyp}

test/concattests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ import LazyArrays: MemoryLayout, DenseColumnMajor, PaddedLayout, materialize!, M
311311
end
312312

313313
@testset "copyto!" begin
314+
a = Vcat(1, Zeros(10))
315+
c = cache(Zeros(11));
316+
@test MemoryLayout(typeof(a)) isa PaddedLayout
317+
@test MemoryLayout(typeof(c)) isa PaddedLayout{DenseColumnMajor}
318+
@test copyto!(c, a) c;
319+
@test length(c.data) == 1
320+
@test c == a
321+
314322
a = Vcat(1:3, Zeros(10))
315323
c = cache(Zeros(13));
316324
@test MemoryLayout(typeof(a)) isa PaddedLayout

0 commit comments

Comments
 (0)