77
88const DOKStorage{T,N} = Dictionary{CartesianIndex{N},T}
99
10+ """
11+ SparseArrayDOK{T,N,F} <: AbstractSparseArray{T,N}
12+
13+ `N`-dimensional sparse Dictionary-of-keys (DOK) array with elements of type `T`,
14+ optionally with a function of type `F` to instantiate non-stored elements.
15+ """
1016struct SparseArrayDOK{T,N,F} <: AbstractSparseArray{T,N}
1117 storage:: DOKStorage{T,N}
1218 size:: NTuple{N,Int}
@@ -28,8 +34,20 @@ struct SparseArrayDOK{T,N,F} <: AbstractSparseArray{T,N}
2834 end
2935end
3036
31- # # constructors with T and N
32- # -> make SparseMatrix{T}(undef, ...) work
37+ # Constructors
38+ # ------------
39+ """
40+ SparseArrayDOK{T}(undef, dims, unstored...)
41+ SparseArrayDOK{T}(undef, dims...)
42+ SparseArrayDOK{T,N}(undef, dims, unstored...)
43+ SparseArrayDOK{T,N}(undef, dims...)
44+
45+ Construct an uninitialized `N`-dimensional [`SparseArrayDOK`](@ref) containing
46+ elements of type `T`. `N` can either be supplied explicitly, or be determined by
47+ the length or number of `dims`.
48+ """
49+ SparseArrayDOK {T,N} (:: UndefInitializer , dims, unstored... )
50+
3351function SparseArrayDOK {T,N} (
3452 :: UndefInitializer , dims:: Dims , getunstoredindex= default_getunstoredindex
3553) where {T,N}
@@ -38,33 +56,45 @@ function SparseArrayDOK{T,N}(
3856 F = typeof (getunstoredindex)
3957 return SparseArrayDOK {T,N,F} (undef, dims, getunstoredindex)
4058end
41-
42- # # constructors with T
4359function SparseArrayDOK {T} (:: UndefInitializer , dims:: Dims{N} , unstored... ) where {T,N}
4460 return SparseArrayDOK {T,N} (undef, dims, unstored... )
4561end
46-
4762function SparseArrayDOK {T} (:: UndefInitializer , dims:: Vararg{Int,N} ) where {T,N}
4863 return SparseArrayDOK {T,N} (undef, dims)
4964end
5065
66+ """
67+ SparseArrayDOK(storage::Union{AbstractDict,AbstractDictionary}, dims, unstored...)
68+ SparseArrayDOK{T}(storage::Union{AbstractDict,AbstractDictionary}, dims, unstored...)
69+ SparseArrayDOK{T,N}(storage::Union{AbstractDict,AbstractDictionary}, dims, unstored...)
70+
71+ Construct an `N`-dimensional [`SparseArrayDOK`](@ref) containing elements of type `T`. Both
72+ `T` and `N` can either be supplied explicitly or be determined by the `storage` and the
73+ length or number of `dims`.
74+
75+ This constructor does not take ownership of the supplied storage, and will result in an
76+ independent container.
77+ """
78+ SparseArrayDOK {T,N} (:: Union{AbstractDict,AbstractDictionary} , dims, unstored... )
79+
80+ const AbstractDictOrDictionary = Union{AbstractDict,AbstractDictionary}
5181# checked constructor from data: use `setindex!` to validate/convert input
52- function SparseArrayDOK {T} (
53- storage:: Union{AbstractDictionary,AbstractDict} , dims:: Dims , unstored...
54- ) where {T}
55- A = SparseArrayDOK {T} (undef, dims, unstored... )
82+ function SparseArrayDOK {T,N } (
83+ storage:: AbstractDictOrDictionary , dims:: Dims , unstored...
84+ ) where {T,N }
85+ A = SparseArrayDOK {T,N } (undef, dims, unstored... )
5686 for (i, v) in pairs (storage)
5787 A[i] = v
5888 end
5989 return A
6090end
61-
62- # # constructors without type parameters
63- function SparseArrayDOK (
64- storage :: Union{AbstractDictionary,AbstractDict} , dims:: Dims , unstored...
65- )
66- T = valtype (storage)
67- return SparseArrayDOK {T } (storage, dims, unstored... )
91+ function SparseArrayDOK {T} (
92+ storage :: AbstractDictOrDictionary , dims :: Dims , unstored ...
93+ ) where {T}
94+ return SparseArrayDOK {T,length(dims)} (storage , dims, unstored... )
95+ end
96+ function SparseArrayDOK (storage:: AbstractDictOrDictionary , dims :: Dims , unstored ... )
97+ return SparseArrayDOK {valtype(storage) } (storage, dims, unstored... )
6898end
6999
70100function set_getunstoredindex (a:: SparseArrayDOK , f)
0 commit comments