Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ function _disk_copyto!(dest, Rdest, src, Rsrc)
return dest
end
view(dest, Rdest) .= view(src, Rsrc)
return dest
end
function _disk_copyto_5arg!(dest, dstart, src, sstart, n)
if iszero(n)
return dest
end
if n < 0
throw(ArgumentError(LazyString("tried to copy n=",
n," elements, but n should be non-negative")))
end
destv = view(dest, range(dstart, length=n))
DiskArrays.readblock!(src, destv, range(sstart, length=n))
return dest
end

# Use a view for lazy reverse
Expand Down Expand Up @@ -76,6 +89,12 @@ macro implement_array_methods(t)
function Base.copyto!(dest::PermutedDimsArray{T,N}, src::$t{T,N}) where {T,N}
return $_disk_copyto!(dest, src)
end
function Base.copyto!(dest::Vector, dstart::Integer, src::$t{<:Any, 1}, sstart::Integer, n::Integer)
return $_disk_copyto_5arg!(dest, dstart, src, sstart, n)
end
function Base.copyto!(dest::SubArray{T, 1, Vector{T}, <:Tuple{AbstractUnitRange}, true} where {T}, dstart::Integer, src::$t{<:Any, 1}, sstart::Integer, n::Integer)
return $_disk_copyto_5arg!(dest, dstart, src, sstart, n)
end

Base.reverse(a::$t; dims=:) = $_disk_reverse(a, dims)
Base.reverse(a::$t{<:Any,1}) = $_disk_reverse1(a)
Expand Down
24 changes: 20 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -770,15 +770,31 @@ end
@test Array(a_disk) == a
@testset "copyto" begin
x = zero(a)
copyto!(x, a_disk)
@test copyto!(x, a_disk) === x
@test x == a
copyto!(x, CartesianIndices((1:3, 1:2)), a_disk, CartesianIndices((8:10, 8:9)))
@test copyto!(x, CartesianIndices((1:3, 1:2)), a_disk, CartesianIndices((8:10, 8:9))) === x
# Test copyto! with zero length index
x_empty = Matrix{Int64}(undef, 0, 2)
copyto!(x_empty, CartesianIndices((1:0, 1:2)), a_disk, CartesianIndices((8:7, 8:9)))
# copyto! with different length should throw an error
@test_throws ArgumentError copyto!(x, CartesianIndices((1:1, 1:2)), a_disk, CartesianIndices((4:6, 8:9)))

# 5 arg copyto!
a_vec = collect(0x00:0x90)
test_dests = [
zero(a_vec),
view(zero(a_vec), 1:10),
zeros(length(a_vec)), # This tests type conversion
]
for x in test_dests
local a_disk = AccessCountDiskArray(a_vec; chunksize=(15,))
x = zero(a_vec)
@test_throws ArgumentError copyto!(x, 1, a_disk, 1, -1)
@test copyto!(x, 1, a_disk, 1, 0) === x
@test copyto!(x, 6, a_disk, 3, 2) === x
@test x[6] == a_vec[3]
@test x[7] == a_vec[4]
@test getindex_count(a_disk) == 1
end
end

@test collect(reverse(a_disk)) == reverse(a)
Expand All @@ -804,7 +820,7 @@ end
@test vcat(a_disk, a_disk) == vcat(a, a)
@test hcat(a_disk, a_disk) == hcat(a, a)
@test cat(a_disk, a_disk; dims=3) == cat(a, a; dims=3)
@test_broken circshift(a_disk, 2) == circshift(a, 2) # This one is super weird. The size changes.
@test circshift(a_disk, 2) == circshift(a, 2)
end

@testset "Reshape" begin
Expand Down
Loading