Skip to content

Commit 95c8076

Browse files
committed
Add tests with Aqua
1 parent cfc7dfb commit 95c8076

File tree

7 files changed

+75
-14
lines changed

7 files changed

+75
-14
lines changed

Project.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1212
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1313

1414
[compat]
15+
Aqua = "0.8.12"
16+
Distributed = "<0.0.1, 1"
17+
LinearAlgebra = "<0.0.1, 1"
1518
Primes = "0.4, 0.5"
19+
Random = "<0.0.1, 1"
20+
Serialization = "<0.0.1, 1"
21+
SparseArrays = "<0.0.1, 1"
22+
SpecialFunctions = "0.8, 1, 2"
1623
Statistics = "<0.0.1, 1"
24+
Test = "<0.0.1, 1"
1725
julia = "1"
1826

1927
[extras]
28+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2029
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2130
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2231

2332
[targets]
24-
test = ["Test", "SpecialFunctions"]
33+
test = ["Aqua", "Test", "SpecialFunctions"]

src/DistributedArrays.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import LinearAlgebra: axpy!, dot, norm, mul!
1414
import Primes
1515
import Primes: factor
1616

17+
import SparseArrays
18+
1719
# DArray exports
1820
export DArray, SubDArray, SubOrDArray, @DArray
1921
export dzeros, dones, dfill, drand, drandn, distribute, localpart, localindices, ppeval

src/broadcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ end
6363
# - Q: How do decide on the cuts
6464
# - then localise arguments on each node
6565
##
66-
@inline function Base.copyto!(dest::DDestArray, bc::Broadcasted)
66+
@inline function Base.copyto!(dest::DDestArray, bc::Broadcasted{Nothing})
6767
axes(dest) == axes(bc) || Broadcast.throwdm(axes(dest), axes(bc))
6868

6969
# Distribute Broadcasted

src/darray.jl

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ function makelocal(A::DArray{<:Any, <:Any, AT}, I::Vararg{Any, N}) where {N, AT}
384384
end
385385

386386
# shortcut to set/get localparts of a distributed object
387-
function Base.getindex(d::DArray, s::Symbol)
387+
Base.getindex(d::DArray, s::Symbol) = _getindex(d, s)
388+
Base.getindex(d::DistributedArrays.DArray{<:Any, 1}, s::Symbol) = _getindex(d, s)
389+
function _getindex(d::DArray, s::Symbol)
388390
@assert s in [:L, :l, :LP, :lp]
389391
return localpart(d)
390392
end
@@ -454,6 +456,14 @@ function Base.:(==)(d1::SubDArray, d2::SubDArray)
454456
return t
455457
end
456458

459+
# Fix method ambiguities
460+
for T in (:DArray, :SubDArray)
461+
@eval begin
462+
Base.:(==)(d1::$T{<:Any,1}, d2::SparseArrays.ReadOnly) = d1 == parent(d2)
463+
Base.:(==)(d1::SparseArrays.ReadOnly, d2::$T{<:Any,1}) = parent(d1) == d2
464+
end
465+
end
466+
457467
"""
458468
locate(d::DArray, I::Int...)
459469
@@ -513,10 +523,28 @@ dfill(v, d1::Integer, drest::Integer...) = dfill(v, convert(Dims, tuple(d1, dres
513523
Construct a distributed uniform random array.
514524
Trailing arguments are the same as those accepted by `DArray`.
515525
"""
516-
drand(r, dims::Dims, args...) = DArray(I -> rand(r, map(length,I)), dims, args...)
517-
drand(r, d1::Integer, drest::Integer...) = drand(r, convert(Dims, tuple(d1, drest...)))
518-
drand(d1::Integer, drest::Integer...) = drand(Float64, convert(Dims, tuple(d1, drest...)))
519-
drand(d::Dims, args...) = drand(Float64, d, args...)
526+
drand(::Type{T}, dims::Dims) where {T} = DArray(I -> rand(T, map(length, I)), dims)
527+
drand(X, dims::Dims) = DArray(I -> rand(X, map(length, I)), dims)
528+
drand(dims::Dims) = drand(Float64, dims)
529+
530+
drand(::Type{T}, d1::Integer, drest::Integer...) where {T} = drand(T, Dims((d1, drest...)))
531+
drand(X, d1::Integer, drest::Integer...) = drand(X, Dims((d1, drest...)))
532+
drand(d1::Integer, drest::Integer...) = drand(Float64, Dims((d1, drest...)))
533+
534+
# With optional process IDs and number of chunks
535+
for N in (1, 2)
536+
@eval begin
537+
drand(::Type{T}, dims::Dims, args::Vararg{Any,$N}) where {T} = DArray(I -> rand(T, map(length, I)), dims, args...)
538+
drand(X, dims::Dims, args::Vararg{Any,$N}) = DArray(I -> rand(X, map(length, I)), dims, args...)
539+
drand(dims::Dims, args::Vararg{Any,$N}) = drand(Float64, dims, args...)
540+
end
541+
end
542+
543+
# Fix method ambiguities
544+
drand(dims::Dims, procs::Tuple{Vararg{Int}}) = drand(Float64, dims, procs)
545+
drand(dims::Dims, procs::Tuple{Vararg{Int}}, dist) = drand(Float64, dims, procs, dist)
546+
drand(X::Tuple{Vararg{Int}}, dim::Integer) = drand(X, Dims((dim,)))
547+
drand(X::Tuple{Vararg{Int}}, d1::Integer, d2::Integer) = drand(X, Dims((d1, d2)))
520548

521549
"""
522550
drandn(dims, ...)
@@ -643,7 +671,7 @@ allowscalar(flag = true) = (_allowscalar[] = flag)
643671
_scalarindexingallowed() = _allowscalar[] || throw(ErrorException("scalar indexing disabled"))
644672

645673
getlocalindex(d::DArray, idx...) = localpart(d)[idx...]
646-
function getindex_tuple(d::DArray{T}, I::Tuple{Vararg{Int}}) where T
674+
function getindex_tuple(d::DArray{T,N}, I::NTuple{N,Int}) where {T,N}
647675
chidx = locate(d, I...)
648676
idxs = d.indices[chidx...]
649677
localidx = ntuple(i -> (I[i] - first(idxs[i]) + 1), ndims(d))
@@ -655,16 +683,16 @@ function Base.getindex(d::DArray, i::Int)
655683
_scalarindexingallowed()
656684
return getindex_tuple(d, Tuple(CartesianIndices(d)[i]))
657685
end
658-
function Base.getindex(d::DArray, i::Int...)
686+
function Base.getindex(d::DArray{<:Any,N}, i::Vararg{Int,N}) where {N}
659687
_scalarindexingallowed()
660688
return getindex_tuple(d, i)
661689
end
662690

663-
Base.getindex(d::DArray) = d[1]
664-
if VERSION > v"1.1-"
665-
Base.getindex(d::SubDArray, I::Int...) = invoke(getindex, Tuple{SubArray{<:Any,N},Vararg{Int,N}} where N, d, I...)
691+
function Base.getindex(d::DArray{<:Any,N}, I::Vararg{Any,N}) where {N}
692+
return view(d, I...)
666693
end
667-
Base.getindex(d::SubOrDArray, I::Union{Int,UnitRange{Int},Colon,Vector{Int},StepRange{Int,Int}}...) = view(d, I...)
694+
695+
Base.getindex(d::DArray) = d[1]
668696

669697
function Base.isassigned(D::DArray, i::Integer...)
670698
try
@@ -692,6 +720,15 @@ function Base.copyto!(dest::SubOrDArray, src::AbstractArray)
692720
return dest
693721
end
694722

723+
# Fix method ambiguities
724+
# TODO: Improve efficiency?
725+
Base.copyto!(dest::SubOrDArray{<:Any,2}, src::SparseArrays.AbstractSparseMatrixCSC) = copyto!(dest, Matrix(src))
726+
@static if isdefined(SparseArrays, :CHOLMOD)
727+
Base.copyto!(dest::SubOrDArray, src::SparseArrays.CHOLMOD.Dense) = copyto!(dest, Array(src))
728+
Base.copyto!(dest::SubOrDArray{T}, src::SparseArrays.CHOLMOD.Dense{T}) where {T<:Union{Float32,Float64,ComplexF32,ComplexF64}} = copyto!(dest, Array(src))
729+
Base.copyto!(dest::SubOrDArray{T,2}, src::SparseArrays.CHOLMOD.Dense{T}) where {T<:Union{Float32,Float64,ComplexF32,ComplexF64}} = copyto!(dest, Array(src))
730+
end
731+
695732
function Base.deepcopy(src::DArray)
696733
dest = similar(src)
697734
asyncmap(procs(src)) do p

src/mapreduce.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ function Base.map!(f::F, dest::DArray, src::DArray{<:Any,<:Any,A}) where {F,A}
1515
return dest
1616
end
1717

18-
function Base.reduce(f, d::DArray)
18+
# Only defining `reduce(f, ::DArray)` causes method ambiguity issues with
19+
# - `reduce(hcat, ::AbstractVector{<:AbstractVecOrMat})`
20+
# - `reduce(vcat, ::AbstractVector{<:AbstractVecOrMat})`
21+
Base.reduce(f, d::DArray) = _reduce(f, d)
22+
Base.reduce(::typeof(hcat), d::DArray{<:AbstractVecOrMat, 1}) = _reduce(hcat, d)
23+
Base.reduce(::typeof(vcat), d::DArray{<:AbstractVecOrMat, 1}) = _reduce(vcat, d)
24+
function _reduce(f, d::DArray)
1925
results = asyncmap(procs(d)) do p
2026
remotecall_fetch(p) do
2127
return reduce(f, localpart(d))

test/aqua.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using DistributedArrays, Test
2+
import Aqua
3+
4+
@testset "Aqua" begin
5+
Aqua.test_all(DistributedArrays)
6+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function check_leaks()
3232
end
3333
end
3434

35+
include("aqua.jl")
3536
include("darray.jl")
3637
include("spmd.jl")
3738

0 commit comments

Comments
 (0)