1
- using BlockArrays: BlockArrays, Block, BlockedUnitRange, blockedrange, blocklength
1
+ using BlockArrays:
2
+ BlockArrays,
3
+ Block,
4
+ BlockedUnitRange,
5
+ UndefBlocksInitializer,
6
+ blockedrange,
7
+ blocklength,
8
+ undef_blocks
2
9
using DerivableInterfaces: @interface
3
10
using Dictionaries: Dictionary
4
11
using SparseArraysBase: SparseArrayDOK
5
12
13
+ """
14
+ SparseArrayDOK{T}(::UndefBlocksInitializer, axes)
15
+ SparseArrayDOK{T,N}(::UndefBlocksInitializer, axes)
16
+
17
+ Construct the block structure of an undefined BlockSparseArray that will have
18
+ blocked axes `axes`.
19
+ """
20
+ function SparseArraysBase. SparseArrayDOK {T,N} (
21
+ :: UndefBlocksInitializer , ax:: Tuple{Vararg{AbstractUnitRange{<:Integer},N}}
22
+ ) where {T,N}
23
+ return SparseArrayDOK {T,N} (undef, blocklength .(ax), GetUnstoredBlock (ax))
24
+ end
25
+ function SparseArraysBase. SparseArrayDOK {T,N} (
26
+ :: UndefBlocksInitializer , ax:: Vararg{AbstractUnitRange{<:Integer},N}
27
+ ) where {T,N}
28
+ return SparseArrayDOK {T,N} (undef_blocks, ax)
29
+ end
30
+ function SparseArraysBase. SparseArrayDOK {T,N} (
31
+ :: UndefBlocksInitializer , dims:: Tuple{Vararg{AbstractVector{<:Integer},N}}
32
+ ) where {T,N}
33
+ return SparseArrayDOK {T,N} (undef_blocks, blockedrange .(dims))
34
+ end
35
+ function SparseArraysBase. SparseArrayDOK {T,N} (
36
+ :: UndefBlocksInitializer , dims:: Vararg{AbstractVector{<:Integer},N}
37
+ ) where {T,N}
38
+ return SparseArrayDOK {T,N} (undef_blocks, blockedrange .(dims))
39
+ end
40
+
41
+ function SparseArraysBase. SparseArrayDOK {T} (
42
+ :: UndefBlocksInitializer , ax:: Tuple{Vararg{AbstractUnitRange{<:Integer},N}}
43
+ ) where {T,N}
44
+ return SparseArrayDOK {T,N} (undef_blocks, ax)
45
+ end
46
+ function SparseArraysBase. SparseArrayDOK {T} (
47
+ :: UndefBlocksInitializer , ax:: Vararg{AbstractUnitRange{<:Integer},N}
48
+ ) where {T,N}
49
+ return SparseArrayDOK {T,N} (undef_blocks, ax)
50
+ end
51
+ function SparseArraysBase. SparseArrayDOK {T} (
52
+ :: UndefBlocksInitializer , dims:: Tuple{Vararg{AbstractVector{<:Integer},N}}
53
+ ) where {T,N}
54
+ return SparseArrayDOK {T,N} (undef_blocks, blockedrange .(dims))
55
+ end
56
+ function SparseArraysBase. SparseArrayDOK {T} (
57
+ :: UndefBlocksInitializer , dims:: Vararg{AbstractVector{<:Integer},N}
58
+ ) where {T,N}
59
+ return SparseArrayDOK {T,N} (undef_blocks, blockedrange .(dims))
60
+ end
61
+
6
62
function _BlockSparseArray end
7
63
8
64
struct BlockSparseArray{
@@ -46,12 +102,22 @@ function sparsemortar(
46
102
) where {T,N}
47
103
return _BlockSparseArray (blocks, axes)
48
104
end
49
-
50
- function BlockArrays. mortar (
51
- blocks:: SparseArrayDOK{<:AbstractArray{T,N},N} ,
52
- axes:: Tuple{Vararg{AbstractUnitRange{<:Integer},N}} ,
105
+ function sparsemortar (
106
+ blocks:: AbstractArray{<:AbstractArray{T,N},N} ,
107
+ axes:: Vararg{AbstractUnitRange{<:Integer},N} ,
53
108
) where {T,N}
54
- return _BlockSparseArray (blocks, axes)
109
+ return sparsemortar (blocks, axes)
110
+ end
111
+ function sparsemortar (
112
+ blocks:: AbstractArray{<:AbstractArray{T,N},N} ,
113
+ dims:: Tuple{Vararg{AbstractVector{<:Integer},N}} ,
114
+ ) where {T,N}
115
+ return sparsemortar (blocks, blockedrange .(dims))
116
+ end
117
+ function sparsemortar (
118
+ blocks:: AbstractArray{<:AbstractArray{T,N},N} , dims:: Vararg{AbstractVector{<:Integer},N}
119
+ ) where {T,N}
120
+ return sparsemortar (blocks, dims)
55
121
end
56
122
57
123
@doc """
@@ -64,20 +130,19 @@ of block lengths in each dimension or a list of blocked ranges representing the
64
130
""" BlockSparseArray
65
131
66
132
function BlockSparseArray {T,N,A} (
67
- :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange,N}}
133
+ :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange{<:Integer} ,N}}
68
134
) where {T,N,A<: AbstractArray{T,N} }
69
- blocks = default_blocks (A, axes)
70
- return _BlockSparseArray (blocks, axes)
135
+ return _BlockSparseArray (SparseArrayDOK {A} (undef_blocks, axes), axes)
71
136
end
72
137
73
138
function BlockSparseArray {T,N,A} (
74
- :: UndefInitializer , axes:: Vararg{AbstractUnitRange,N}
139
+ :: UndefInitializer , axes:: Vararg{AbstractUnitRange{<:Integer} ,N}
75
140
) where {T,N,A<: AbstractArray{T,N} }
76
141
return BlockSparseArray {T,N,A} (undef, axes)
77
142
end
78
143
79
144
function BlockSparseArray {T,N,A} (
80
- :: UndefInitializer , dims:: Tuple{Vararg{Vector{Int },N}}
145
+ :: UndefInitializer , dims:: Tuple{Vararg{AbstractVector{<:Integer },N}}
81
146
) where {T,N,A<: AbstractArray{T,N} }
82
147
return BlockSparseArray {T,N,A} (undef, blockedrange .(dims))
83
148
end
86
151
function BlockSparseArray {T,0,A} (
87
152
:: UndefInitializer , axes:: Tuple{}
88
153
) where {T,A<: AbstractArray{T,0} }
89
- blocks = default_blocks (A, axes)
90
- return _BlockSparseArray (blocks, axes)
154
+ return _BlockSparseArray (SparseArrayDOK {A} (undef_blocks, axes), axes)
91
155
end
92
156
93
157
function BlockSparseArray {T,N,A} (
94
- :: UndefInitializer , dims:: Vararg{Vector{Int },N}
158
+ :: UndefInitializer , dims:: Vararg{AbstractVector{<:Integer },N}
95
159
) where {T,N,A<: AbstractArray{T,N} }
96
160
return BlockSparseArray {T,N,A} (undef, dims)
97
161
end
98
162
99
163
function BlockSparseArray {T,N} (
100
- :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange,N}}
164
+ :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange{<:Integer} ,N}}
101
165
) where {T,N}
102
- return BlockSparseArray {T,N,default_arraytype(T, axes) } (undef, axes)
166
+ return BlockSparseArray {T,N,Array{T,N} } (undef, axes)
103
167
end
104
168
105
169
function BlockSparseArray {T,N} (
106
- :: UndefInitializer , axes:: Vararg{AbstractUnitRange,N}
170
+ :: UndefInitializer , axes:: Vararg{AbstractUnitRange{<:Integer} ,N}
107
171
) where {T,N}
108
172
return BlockSparseArray {T,N} (undef, axes)
109
173
end
110
174
111
175
function BlockSparseArray {T,0} (:: UndefInitializer , axes:: Tuple{} ) where {T}
112
- return BlockSparseArray {T,0,default_arraytype(T, axes) } (undef, axes)
176
+ return BlockSparseArray {T,0,Array{T,0} } (undef, axes)
113
177
end
114
178
115
179
function BlockSparseArray {T,N} (
116
- :: UndefInitializer , dims:: Tuple{Vararg{Vector{Int },N}}
180
+ :: UndefInitializer , dims:: Tuple{Vararg{AbstractVector{<:Integer },N}}
117
181
) where {T,N}
118
182
return BlockSparseArray {T,N} (undef, blockedrange .(dims))
119
183
end
120
184
121
- function BlockSparseArray {T,N} (:: UndefInitializer , dims:: Vararg{Vector{Int},N} ) where {T,N}
185
+ function BlockSparseArray {T,N} (
186
+ :: UndefInitializer , dims:: Vararg{AbstractVector{<:Integer},N}
187
+ ) where {T,N}
122
188
return BlockSparseArray {T,N} (undef, dims)
123
189
end
124
190
125
- function BlockSparseArray {T} (:: UndefInitializer , dims:: Tuple{Vararg{Vector{Int}}} ) where {T}
191
+ function BlockSparseArray {T} (
192
+ :: UndefInitializer , dims:: Tuple{Vararg{AbstractVector{<:Integer}}}
193
+ ) where {T}
126
194
return BlockSparseArray {T,length(dims)} (undef, dims)
127
195
end
128
196
129
197
function BlockSparseArray {T} (
130
- :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange}}
198
+ :: UndefInitializer , axes:: Tuple{Vararg{AbstractUnitRange{<:Integer} }}
131
199
) where {T}
132
200
return BlockSparseArray {T,length(axes)} (undef, axes)
133
201
end
@@ -136,11 +204,15 @@ function BlockSparseArray{T}(::UndefInitializer, axes::Tuple{}) where {T}
136
204
return BlockSparseArray {T,length(axes)} (undef, axes)
137
205
end
138
206
139
- function BlockSparseArray {T} (:: UndefInitializer , dims:: Vararg{Vector{Int}} ) where {T}
207
+ function BlockSparseArray {T} (
208
+ :: UndefInitializer , dims:: Vararg{AbstractVector{<:Integer}}
209
+ ) where {T}
140
210
return BlockSparseArray {T} (undef, dims)
141
211
end
142
212
143
- function BlockSparseArray {T} (:: UndefInitializer , axes:: Vararg{AbstractUnitRange} ) where {T}
213
+ function BlockSparseArray {T} (
214
+ :: UndefInitializer , axes:: Vararg{AbstractUnitRange{<:Integer}}
215
+ ) where {T}
144
216
return BlockSparseArray {T} (undef, axes)
145
217
end
146
218
0 commit comments