-
Notifications
You must be signed in to change notification settings - Fork 21
Add 5 arg copyto!
into Vector
with matching type
#264
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,30 @@ function _disk_copyto!(dest, Rdest, src, Rsrc) | |
return dest | ||
end | ||
view(dest, Rdest) .= view(src, Rsrc) | ||
return dest | ||
end | ||
function _disk_copyto_same_type_vector!(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 | ||
function _disk_copyto_vector!(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 | ||
view(dest, range(dstart, length=n)) .= view(src, range(dstart, length=n)) | ||
return dest | ||
end | ||
|
||
# Use a view for lazy reverse | ||
|
@@ -76,6 +100,18 @@ 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{T}, dstart::Integer, src::$t{T, 1}, sstart::Integer, n::Integer) where {T} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming here that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe. Looking at the docs, it just says "The results shall be written into |
||
return $_disk_copyto_same_type_vector!(dest, dstart, src, sstart, n) | ||
end | ||
function Base.copyto!(dest::SubArray{T, 1, Vector{T}, <:Tuple{AbstractUnitRange}, true}, dstart::Integer, src::$t{T, 1}, sstart::Integer, n::Integer) where {T} | ||
return $_disk_copyto_same_type_vector!(dest, dstart, src, sstart, n) | ||
end | ||
function Base.copyto!(dest::Vector, dstart::Integer, src::$t{T, 1}, sstart::Integer, n::Integer) where {T} | ||
return $_disk_copyto_vector!(dest, dstart, src, sstart, n) | ||
end | ||
function Base.copyto!(dest::SubArray{TD, 1, Vector{TD}}, dstart::Integer, src::$t{TS, 1}, sstart::Integer, n::Integer) where {TD, TS} | ||
return $_disk_copyto_vector!(dest, dstart, src, sstart, n) | ||
end | ||
|
||
Base.reverse(a::$t; dims=:) = $_disk_reverse(a, dims) | ||
Base.reverse(a::$t{<:Any,1}) = $_disk_reverse1(a) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on the use case it might be better for performance to avoid the DiskArray broadcast machinery, broadcast on views should work but might be a bit slow if chunk sizes are too small. Instead we might instantiate the result and copy with
coptyo!(dest,dstart,src[range(dstart, length=n)])
Can we assume that the amount of data we copy fits in memory, or is
dest
mmapped in your case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not doing any mmapping in
InputBuffers.jl
, though there is nothing stopping someone from passing a mmappedout
to Base.readbytes!(b::InputBuffer, out::AbstractArray{UInt8}, nb=length(out))Also, the
copyto!
inInputBuffers.jl
should end up calling_disk_copyto_same_type_vector
with the directreadblock!
call sincesrc
anddest
both have eltypeUInt8
.