@@ -384,7 +384,9 @@ function makelocal(A::DArray{<:Any, <:Any, AT}, I::Vararg{Any, N}) where {N, AT}
384384end
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)
390392end
@@ -454,6 +456,14 @@ function Base.:(==)(d1::SubDArray, d2::SubDArray)
454456 return t
455457end
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
513523Construct a distributed uniform random array.
514524Trailing 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
645673getlocalindex (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]))
657685end
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)
661689end
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... )
666693end
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
669697function Base. isassigned (D:: DArray , i:: Integer... )
670698 try
@@ -692,6 +720,15 @@ function Base.copyto!(dest::SubOrDArray, src::AbstractArray)
692720 return dest
693721end
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+
695732function Base. deepcopy (src:: DArray )
696733 dest = similar (src)
697734 asyncmap (procs (src)) do p
0 commit comments