Skip to content

Commit 235825f

Browse files
authored
refactor, rename and document (#229)
* refactor, rename and document * fix doc ref * format everything * fix field names * fix array chunksize fields
1 parent d330591 commit 235825f

22 files changed

+1479
-1090
lines changed

src/DiskArrays.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ end DiskArrays
1212
export AbstractDiskArray, eachchunk, ChunkIndex, ChunkIndices
1313

1414
include("scalar.jl")
15+
include("chunks.jl")
1516
include("diskarray.jl")
17+
include("batchgetindex.jl")
18+
include("diskindex.jl")
19+
include("indexing.jl")
1620
include("array.jl")
1721
include("broadcast.jl")
1822
include("iterator.jl")
@@ -72,7 +76,7 @@ end
7276
# We need to skip the `implement_zip` macro for dispatch
7377
@implement_diskarray_skip_zip AbstractDiskArray
7478

75-
#And we define the test types
79+
# And we define the test types
7680
include("util/testtypes.jl")
7781

7882

src/array.jl

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,17 @@
1-
macro implement_array_methods(t)
2-
t = esc(t)
3-
quote
4-
Base.Array(a::$t) = $_Array(a)
5-
Base.collect(a::$t) = $_Array(a)
6-
Base.copyto!(dest::$t, source::AbstractArray) = $_copyto!(dest, source)
7-
Base.copyto!(dest::AbstractArray, source::$t) = $_copyto!(dest, source)
8-
Base.copyto!(dest::$t, source::$t) = $_copyto!(dest, source)
9-
function Base.copyto!(
10-
dest::$t, Rdest::CartesianIndices, src::AbstractArray, Rsrc::CartesianIndices
11-
)
12-
return $_copyto!(dest, Rdest, src, Rsrc)
13-
end
14-
function Base.copyto!(
15-
dest::AbstractArray, Rdest::CartesianIndices, src::$t, Rsrc::CartesianIndices
16-
)
17-
return $_copyto!(dest, Rdest, src, Rsrc)
18-
end
19-
function Base.copyto!(
20-
dest::$t, Rdest::CartesianIndices, src::$t, Rsrc::CartesianIndices
21-
)
22-
return $_copyto!(dest, Rdest, src, Rsrc)
23-
end
24-
# For ambiguity
25-
Base.copyto!(dest::PermutedDimsArray, src::$t) = DiskArrays._copyto!(dest, src)
26-
function Base.copyto!(dest::PermutedDimsArray{T,N}, src::$t{T,N}) where {T,N}
27-
return $_copyto!(dest, src)
28-
end
29-
30-
Base.reverse(a::$t; dims=:) = $_reverse(a, dims)
31-
Base.reverse(a::$t{<:Any,1}) = $_reverse1(a)
32-
Base.reverse(a::$t{<:Any,1}, start::Integer, stop::Integer=lastindex(a)) = $_reverse1(a, start, stop)
33-
34-
# Here we extend the unexported `_replace` method, but we replicate
35-
# much less Base functionality by extending it rather than `replace`.
36-
function Base._replace!(new::Base.Callable, res::AbstractArray, A::$t, count::Int)
37-
return $_replace!(new, res, A, count)
38-
end
39-
function Base._replace!(new::Base.Callable, res::$t, A::AbstractArray, count::Int)
40-
return $_replace!(new, res, A, count)
41-
end
42-
function Base._replace!(new::Base.Callable, res::$t, A::$t, count::Int)
43-
return $_replace!(new, res, A, count)
44-
end
45-
end
46-
end
47-
481
# Use broadcast to copy to a new Array
49-
_Array(a::AbstractArray{T,N}) where {T,N} = a[ntuple(_ -> :, Val{N}())...]
50-
_Array(a::AbstractArray{T,0}) where {T} = fill(a[])
2+
_disk_collect(a::AbstractArray{T,N}) where {T,N} = a[ntuple(_ -> :, Val{N}())...]
3+
_disk_collect(a::AbstractArray{T,0}) where {T} = fill(a[])
514

525
# Use broadcast to copy
53-
function _copyto!(dest::AbstractArray{<:Any,N}, source::AbstractArray{<:Any,N}) where {N}
6+
function _disk_copyto!(dest::AbstractArray{<:Any,N}, source::AbstractArray{<:Any,N}) where {N}
547
return dest .= source
558
end
56-
function _copyto!(dest::AbstractArray, source::AbstractArray)
9+
function _disk_copyto!(dest::AbstractArray, source::AbstractArray)
5710
# TODO make this more specific so we are reshaping the Non-DiskArray more often.
5811
reshape(dest, size(source)) .= source
5912
return dest
6013
end
61-
62-
function _copyto!(dest, Rdest, src, Rsrc)
14+
function _disk_copyto!(dest, Rdest, src, Rsrc)
6315
if size(Rdest) != size(Rsrc)
6416
throw(ArgumentError("source and destination must have same size (got $(size(Rsrc)) and $(size(Rdest)))"))
6517
end
@@ -70,26 +22,77 @@ function _copyto!(dest, Rdest, src, Rsrc)
7022
end
7123
view(dest, Rdest) .= view(src, Rsrc)
7224
end
25+
7326
# Use a view for lazy reverse
74-
_reverse(a, ::Colon) = _reverse(a, ntuple(identity, ndims(a)))
75-
_reverse(a, dims::Int) = _reverse(a, (dims,))
76-
function _reverse(A, dims::Tuple)
27+
_disk_reverse(a, ::Colon) = _disk_reverse(a, ntuple(identity, ndims(a)))
28+
_disk_reverse(a, dims::Int) = _disk_reverse(a, (dims,))
29+
function _disk_reverse(A, dims::Tuple)
7730
rev_axes = map(ntuple(identity, ndims(A)), axes(A)) do d, a
7831
ax = StepRange(a)
7932
d in dims ? reverse(ax) : ax
8033
end
8134
return view(A, rev_axes...)
8235
end
83-
_reverse1(a) = _reverse(a, 1)
84-
function _reverse1(a, start::Int, stop::Int)
36+
37+
_disk_reverse1(a) = _disk_reverse(a, 1)
38+
function _disk_reverse1(a, start::Int, stop::Int)
8539
inds = [firstindex(a):start-1; stop:-1:start; stop+1:lastindex(a)]
8640
return view(a, inds)
8741
end
8842

8943
# Use broadcast instead of a loop.
9044
# The `count` argument is disallowed as broadcast is not sequential.
91-
function _replace!(new, res::AbstractArray, A::AbstractArray, count::Int)
45+
function _disk_replace!(new, res::AbstractArray, A::AbstractArray, count::Int)
9246
count < length(res) &&
9347
throw(ArgumentError("`replace` on DiskArrays objects cannot use a count value"))
9448
return broadcast!(new, res, A)
9549
end
50+
51+
macro implement_array_methods(t)
52+
t = esc(t)
53+
quote
54+
Base.Array(a::$t) = $_disk_collect(a)
55+
Base.collect(a::$t) = $_disk_collect(a)
56+
Base.copyto!(dest::$t, source::AbstractArray) = $_disk_copyto!(dest, source)
57+
Base.copyto!(dest::AbstractArray, source::$t) = $_disk_copyto!(dest, source)
58+
Base.copyto!(dest::$t, source::$t) = $_disk_copyto!(dest, source)
59+
function Base.copyto!(
60+
dest::$t, Rdest::CartesianIndices, src::AbstractArray, Rsrc::CartesianIndices
61+
)
62+
return $_disk_copyto!(dest, Rdest, src, Rsrc)
63+
end
64+
function Base.copyto!(
65+
dest::AbstractArray, Rdest::CartesianIndices, src::$t, Rsrc::CartesianIndices
66+
)
67+
return $_disk_copyto!(dest, Rdest, src, Rsrc)
68+
end
69+
function Base.copyto!(
70+
dest::$t, Rdest::CartesianIndices, src::$t, Rsrc::CartesianIndices
71+
)
72+
return $_disk_copyto!(dest, Rdest, src, Rsrc)
73+
end
74+
# For ambiguity
75+
Base.copyto!(dest::PermutedDimsArray, src::$t) = DiskArrays._copyto!(dest, src)
76+
function Base.copyto!(dest::PermutedDimsArray{T,N}, src::$t{T,N}) where {T,N}
77+
return $_disk_copyto!(dest, src)
78+
end
79+
80+
Base.reverse(a::$t; dims=:) = $_disk_reverse(a, dims)
81+
Base.reverse(a::$t{<:Any,1}) = $_disk_reverse1(a)
82+
Base.reverse(a::$t{<:Any,1}, start::Integer, stop::Integer=lastindex(a)) =
83+
$_disk_reverse1(a, start, stop)
84+
85+
# Here we extend the unexported `_replace` method, but we replicate
86+
# much less Base functionality by extending it rather than `replace`.
87+
function Base._replace!(new::Base.Callable, res::AbstractArray, A::$t, count::Int)
88+
return $_disk_replace!(new, res, A, count)
89+
end
90+
function Base._replace!(new::Base.Callable, res::$t, A::AbstractArray, count::Int)
91+
return $_disk_replace!(new, res, A, count)
92+
end
93+
function Base._replace!(new::Base.Callable, res::$t, A::$t, count::Int)
94+
return $_disk_replace!(new, res, A, count)
95+
end
96+
end
97+
end
98+

0 commit comments

Comments
 (0)