7
7
8
8
const DOKStorage{T,N} = Dictionary{CartesianIndex{N},T}
9
9
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
+ """
10
16
struct SparseArrayDOK{T,N,F} <: AbstractSparseArray{T,N}
11
17
storage:: DOKStorage{T,N}
12
18
size:: NTuple{N,Int}
@@ -28,8 +34,20 @@ struct SparseArrayDOK{T,N,F} <: AbstractSparseArray{T,N}
28
34
end
29
35
end
30
36
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
+
33
51
function SparseArrayDOK {T,N} (
34
52
:: UndefInitializer , dims:: Dims , getunstoredindex= default_getunstoredindex
35
53
) where {T,N}
@@ -38,33 +56,45 @@ function SparseArrayDOK{T,N}(
38
56
F = typeof (getunstoredindex)
39
57
return SparseArrayDOK {T,N,F} (undef, dims, getunstoredindex)
40
58
end
41
-
42
- # # constructors with T
43
59
function SparseArrayDOK {T} (:: UndefInitializer , dims:: Dims{N} , unstored... ) where {T,N}
44
60
return SparseArrayDOK {T,N} (undef, dims, unstored... )
45
61
end
46
-
47
62
function SparseArrayDOK {T} (:: UndefInitializer , dims:: Vararg{Int,N} ) where {T,N}
48
63
return SparseArrayDOK {T,N} (undef, dims)
49
64
end
50
65
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}
51
81
# 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... )
56
86
for (i, v) in pairs (storage)
57
87
A[i] = v
58
88
end
59
89
return A
60
90
end
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... )
68
98
end
69
99
70
100
function set_getunstoredindex (a:: SparseArrayDOK , f)
0 commit comments